From b01954575694bcdd3dd52872b44eb5ff88e44eed Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Tue, 22 Jun 2004 00:55:23 +0000 Subject: call stat() a few less times on update git-svn-id: https://svn.musicpd.org/mpd/trunk@1607 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/directory.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/directory.c b/src/directory.c index a05553dd6..28d3135f1 100644 --- a/src/directory.c +++ b/src/directory.c @@ -301,16 +301,18 @@ void deleteEmptyDirectoriesInDirectory(Directory * directory) { 1 -> no error, and stuff updated */ int updateInDirectory(Directory * directory, char * shortname, char * name) { - time_t mtime; void * song; void * subDir; + struct stat st; + + if(myStat(name, &st)) return -1; - if(isMusic(name,&mtime)) { + if(S_ISREG(st.st_mode) && hasMusicSuffix(name)) { if(0==findInList(directory->songs,shortname,&song)) { addToDirectory(directory,shortname,name); return DIRECTORY_RETURN_UPDATE; } - else if(mtime!=((Song *)song)->mtime) { + else if(st.st_mtime!=((Song *)song)->mtime) { LOG("updating %s\n",name); if(updateSongInfo((Song *)song)<0) { removeSongFromDirectory(directory,shortname); @@ -318,7 +320,7 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) { return 1; } } - else if(isDir(name)) { + else if(S_ISDIR(st.st_mode)) { if(findInList(directory->subDirectories,shortname,(void **)&subDir)) { if(updateDirectory((Directory *)subDir)>0) return 1; } @@ -648,10 +650,11 @@ int addSubDirectoryToDirectory(Directory * directory, char * shortname, } int addToDirectory(Directory * directory, char * shortname, char * name) { - if(isDir(name)) { - return addSubDirectoryToDirectory(directory,shortname,name); - } - else if(isMusic(name,NULL)) { + struct stat st; + + if(myStat(name, &st)) return -1; + + if(S_ISREG(st.st_mode) && hasMusicSuffix(name)) { Song * song; song = addSongToList(directory->songs,shortname,name, SONG_TYPE_FILE); @@ -659,6 +662,9 @@ int addToDirectory(Directory * directory, char * shortname, char * name) { LOG("added %s\n",name); return 1; } + else if(S_ISDIR(st.st_mode)) { + return addSubDirectoryToDirectory(directory,shortname,name); + } DEBUG("addToDirectory: %s is not a directory or music\n",name); -- cgit v1.2.3