From c69b615f2b17a927f2c49ab9cd381eb1e5a8e2a4 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Wed, 10 Mar 2004 02:58:27 +0000 Subject: [PATCH] fix it so that mpd will work if mtime is 0 (for those strange folk) git-svn-id: https://svn.musicpd.org/mpd/trunk@237 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/directory.c | 16 ++++++++-------- src/ls.c | 51 ++++++++++++++++++++++++++++--------------------- src/ls.h | 14 +++++++------- src/player.c | 18 +++++++++-------- src/song.c | 18 ++++++++--------- 5 files changed, 63 insertions(+), 54 deletions(-) diff --git a/src/directory.c b/src/directory.c index 457a5d585..f8bd00969 100644 --- a/src/directory.c +++ b/src/directory.c @@ -90,7 +90,7 @@ Directory * newDirectory(Directory * parentDirectory, char * dirname, time_t mti directory->parentDirectory = parentDirectory; directory->subDirectories = newDirectoryList(); directory->songs = newSongList(); - if(mtime<0) directory->mtime = isDir(dirname); + if(mtime<0) isDir(dirname,&(directory->mtime)); else directory->mtime = mtime; return directory; @@ -147,7 +147,7 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) { void * song; void * subDir; - if((mtime = isMusic(name))) { + if(isMusic(name,&mtime)) { if(0==findInList(directory->songs,shortname,&song)) { addToDirectory(directory,shortname,name); } @@ -156,7 +156,7 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) { updateSongInfo((Song *)song); } } - else if((mtime = isDir(name))) { + else if(isDir(name,&mtime)) { if(findInList(directory->subDirectories,shortname,(void **)&subDir)) { updateDirectory((Directory *)subDir); } @@ -204,7 +204,7 @@ int removeDeletedFromDirectory(Directory * directory) { while(node) { tmpNode = node->nextNode; if(findInList(entList,node->key,&name)) { - if(!isDir((char *)name)) { + if(!isDir((char *)name,NULL)) { LOG("removing directory: %s\n",(char*)name); deleteFromList(directory->subDirectories,node->key); } @@ -220,7 +220,7 @@ int removeDeletedFromDirectory(Directory * directory) { while(node) { tmpNode = node->nextNode; if(findInList(entList,node->key,(void **)&name)) { - if(!isMusic(name)) { + if(!isMusic(name,NULL)) { removeSongFromDirectory(directory,node->key); } } @@ -268,7 +268,7 @@ int updateDirectory(Directory * directory) { closedir(dir); - if(directory->utf8name) directory->mtime = isDir(directory->utf8name); + if(directory->utf8name) isDir(directory->utf8name,&(directory->mtime)); return 0; } @@ -323,10 +323,10 @@ int addSubDirectoryToDirectory(Directory * directory, char * shortname, } int addToDirectory(Directory * directory, char * shortname, char * name) { - if(isDir(name)) { + if(isDir(name,NULL)) { return addSubDirectoryToDirectory(directory,shortname,name); } - else if(isMusic(name)) { + else if(isMusic(name,NULL)) { Song * song; song = addSongToList(directory->songs,shortname,name); if(!song) return -1; diff --git a/src/ls.c b/src/ls.c index 85c7b6a01..56930e75c 100644 --- a/src/ls.c +++ b/src/ls.c @@ -110,26 +110,26 @@ int lsPlaylists(FILE * fp, char * utf8path) { return 0; } -time_t isMusic(char * utf8file) { - time_t ret = 0; +int isMusic(char * utf8file, time_t * mtime) { + int ret = 0; #ifdef HAVE_OGG - if((ret = isOgg(utf8file))) return ret; + if((ret = isOgg(utf8file,mtime))) return ret; #endif #ifdef HAVE_FLAC - if((ret = isFlac(utf8file))) return ret; + if((ret = isFlac(utf8file,mtime))) return ret; #endif #ifdef HAVE_MAD - if((ret = isMp3(utf8file))) return ret; + if((ret = isMp3(utf8file,mtime))) return ret; #endif #ifdef HAVE_AUDIOFILE - if((ret = isWave(utf8file))) return ret; + if((ret = isWave(utf8file,mtime))) return ret; #endif return ret; } -time_t isPlaylist(char * utf8file) { +int isPlaylist(char * utf8file) { struct stat st; char * file = utf8ToFsCharset(utf8file); char * actualFile = file; @@ -147,7 +147,7 @@ time_t isPlaylist(char * utf8file) { cNext = cLast = strtok(dup,"."); while((cNext = strtok(NULL,"."))) cLast = cNext; if(cLast && 0==strcmp(cLast,PLAYLIST_FILE_SUFFIX)) { - ret = st.st_mtime; + ret = 1; } free(dup); if(temp) free(temp); @@ -159,7 +159,7 @@ time_t isPlaylist(char * utf8file) { return 0; } -time_t isWave(char * utf8file) { +int isWave(char * utf8file, time_t * mtime) { struct stat st; char * file = utf8ToFsCharset(utf8file); char * actualFile = file; @@ -171,12 +171,13 @@ time_t isWave(char * utf8file) { char * dup; char * cLast; char * cNext; - time_t ret = 0; + int ret = 0; dup = strdup(file); cNext = cLast = strtok(dup,"."); while((cNext = strtok(NULL,"."))) cLast = cNext; if(cLast && 0==strcasecmp(cLast,"wav")) { - ret = st.st_mtime; + if(mtime) *mtime = st.st_mtime; + ret = 1; } free(dup); return ret; @@ -187,7 +188,7 @@ time_t isWave(char * utf8file) { return 0; } -time_t isFlac(char * utf8file) { +int isFlac(char * utf8file, time_t * mtime) { struct stat st; char * file = utf8ToFsCharset(utf8file); char * actualFile = file; @@ -199,12 +200,13 @@ time_t isFlac(char * utf8file) { char * dup; char * cLast; char * cNext; - time_t ret = 0; + int ret = 0; dup = strdup(file); cNext = cLast = strtok(dup,"."); while((cNext = strtok(NULL,"."))) cLast = cNext; if(cLast && 0==strcasecmp(cLast,"flac")) { - ret = st.st_mtime; + if(mtime) *mtime = st.st_mtime; + ret = 1; } free(dup); return ret; @@ -215,7 +217,7 @@ time_t isFlac(char * utf8file) { return 0; } -time_t isOgg(char * utf8file) { +int isOgg(char * utf8file, time_t * mtime) { struct stat st; char * file = utf8ToFsCharset(utf8file); char * actualFile = file; @@ -227,12 +229,13 @@ time_t isOgg(char * utf8file) { char * dup; char * cLast; char * cNext; - time_t ret = 0; + int ret = 0; dup = strdup(file); cNext = cLast = strtok(dup,"."); while((cNext = strtok(NULL,"."))) cLast = cNext; if(cLast && 0==strcasecmp(cLast,"ogg")) { - ret = st.st_mtime; + if(mtime) *mtime = st.st_mtime; + ret = 1; } free(dup); return ret; @@ -243,7 +246,7 @@ time_t isOgg(char * utf8file) { return 0; } -time_t isMp3(char * utf8file) { +int isMp3(char * utf8file, time_t * mtime) { struct stat st; char * file = utf8ToFsCharset(utf8file); char * actualFile = file; @@ -255,12 +258,13 @@ time_t isMp3(char * utf8file) { char * dup; char * cLast; char * cNext; - time_t ret = 0; + int ret = 0; dup = strdup(file); cNext = cLast = strtok(dup,"."); while((cNext = strtok(NULL,"."))) cLast = cNext; if(cLast && 0==strcasecmp(cLast,"mp3")) { - ret = st.st_mtime; + if(mtime) *mtime = st.st_mtime; + ret = 1; } free(dup); return ret; @@ -271,11 +275,14 @@ time_t isMp3(char * utf8file) { return 0; } -time_t isDir(char * utf8name) { +int isDir(char * utf8name, time_t * mtime) { struct stat st; if(stat(rmp2amp(utf8ToFsCharset(utf8name)),&st)==0) { - if(S_ISDIR(st.st_mode)) return st.st_mtime; + if(S_ISDIR(st.st_mode)) { + if(mtime) *mtime = st.st_mtime; + return 1; + } } else { DEBUG("isDir: unable to stat: %s (%s)\n",utf8name, diff --git a/src/ls.h b/src/ls.h index c31f37a32..6884549de 100644 --- a/src/ls.h +++ b/src/ls.h @@ -24,19 +24,19 @@ int lsPlaylists(FILE * fp, char * utf8path); -time_t isMp3(char * utf8file); +int isMp3(char * utf8file, time_t * mtime); -time_t isOgg(char * utf8file); +int isOgg(char * utf8file, time_t * mtime); -time_t isFlac(char * utf8file); +int isFlac(char * utf8file, time_t * mtime); -time_t isWave(char * utf8file); +int isWave(char * utf8file, time_t * mtime); -time_t isMusic(char * utf8file); +int isMusic(char * utf8file, time_t * mtime); -time_t isDir(char * utf8name); +int isDir(char * utf8name, time_t * mtime); -time_t isPlaylist(char * utf8file); +int isPlaylist(char * utf8file); char * dupAndStripPlaylistSuffix(char * file); diff --git a/src/player.c b/src/player.c index 3a9f455d0..2b45e6ab4 100644 --- a/src/player.c +++ b/src/player.c @@ -166,16 +166,16 @@ int playerPlay(FILE * fp, char * utf8file) { if(0); #ifdef HAVE_MAD - else if(isMp3(utf8file)) pc->decodeType = DECODE_TYPE_MP3; + else if(isMp3(utf8file,NULL)) pc->decodeType = DECODE_TYPE_MP3; #endif #ifdef HAVE_OGG - else if(isOgg(utf8file)) pc->decodeType = DECODE_TYPE_OGG; + else if(isOgg(utf8file,NULL)) pc->decodeType = DECODE_TYPE_OGG; #endif #ifdef HAVE_FLAC - else if(isFlac(utf8file)) pc->decodeType = DECODE_TYPE_FLAC; + else if(isFlac(utf8file,NULL)) pc->decodeType = DECODE_TYPE_FLAC; #endif #ifdef HAVE_AUDIOFILE - else if(isWave(utf8file)) pc->decodeType = DECODE_TYPE_AUDIOFILE; + else if(isWave(utf8file,NULL)) pc->decodeType = DECODE_TYPE_AUDIOFILE; #endif else { strncpy(pc->erroredFile,pc->file,MAXPATHLEN); @@ -317,16 +317,18 @@ int queueSong(char * utf8file) { if(0); #ifdef HAVE_MAD - else if(isMp3(utf8file)) pc->decodeType = DECODE_TYPE_MP3; + else if(isMp3(utf8file,NULL)) pc->decodeType = DECODE_TYPE_MP3; #endif #ifdef HAVE_OGG - else if(isOgg(utf8file)) pc->decodeType = DECODE_TYPE_OGG; + else if(isOgg(utf8file,NULL)) pc->decodeType = DECODE_TYPE_OGG; #endif #ifdef HAVE_FLAC - else if(isFlac(utf8file)) pc->decodeType = DECODE_TYPE_FLAC; + else if(isFlac(utf8file,NULL)) { + pc->decodeType = DECODE_TYPE_FLAC; + } #endif #ifdef HAVE_AUDIOFILE - else if(isWave(utf8file)) { + else if(isWave(utf8file,NULL)) { pc->decodeType = DECODE_TYPE_AUDIOFILE; } #endif diff --git a/src/song.c b/src/song.c index 56032c79f..c269c2e52 100644 --- a/src/song.c +++ b/src/song.c @@ -49,28 +49,28 @@ Song * newSong(char * utf8file) { if(0); #ifdef HAVE_OGG - else if((song->mtime = isOgg(utf8file))) { + else if(isOgg(utf8file,&(song->mtime))) { song->time = getOggTotalTime( rmp2amp(utf8ToFsCharset(utf8file))); if(song->time>=0) song->tag = oggTagDup(utf8file); } #endif #ifdef HAVE_FLAC - else if((song->mtime = isFlac(utf8file))) { + else if((isFlac(utf8file,&(song->mtime)))) { song->time = getFlacTotalTime( rmp2amp(utf8ToFsCharset(utf8file))); if(song->time>=0) song->tag = flacTagDup(utf8file); } #endif #ifdef HAVE_MAD - else if((song->mtime = isMp3(utf8file))) { + else if(isMp3(utf8file,&(song->mtime))) { song->time = getMp3TotalTime( rmp2amp(utf8ToFsCharset(utf8file))); if(song->time>=0) song->tag = mp3TagDup(utf8file); } #endif #ifdef HAVE_AUDIOFILE - else if((song->mtime = isWave(utf8file))) { + else if(isWave(utf8file,&(song->mtime))) { song->time = getAudiofileTotalTime( rmp2amp(utf8ToFsCharset(utf8file))); if(song->time>=0) song->tag = audiofileTagDup(utf8file); @@ -98,7 +98,7 @@ SongList * newSongList() { Song * addSongToList(SongList * list, char * key, char * utf8file) { Song * song = NULL; - if(isMusic(utf8file)) { + if(isMusic(utf8file,NULL)) { song = newSong(utf8file); } @@ -212,25 +212,25 @@ void readSongInfoIntoList(FILE * fp, SongList * list) { int updateSongInfo(Song * song) { if(song->tag) freeMpdTag(song->tag); #ifdef HAVE_MAD - if((song->mtime = isMp3(song->utf8file))) { + if(isMp3(song->utf8file,&(song->mtime))) { song->tag = mp3TagDup(song->utf8file); return 0; } #endif #ifdef HAVE_OGG - if((song->mtime = isOgg(song->utf8file))) { + if(isOgg(song->utf8file,&(song->mtime))) { song->tag = oggTagDup(song->utf8file); return 0; } #endif #ifdef HAVE_FLAC - if((song->mtime = isFlac(song->utf8file))) { + if(isFlac(song->utf8file,&(song->mtime))) { song->tag = flacTagDup(song->utf8file); return 0; } #endif #ifdef HAVE_AUDIOFILE - if((song->mtime = isWave(song->utf8file))) { + if(isWave(song->utf8file,&(song->mtime))) { song->tag = audiofileTagDup(song->utf8file); return 0; }