From c4d2b8dc1cc73bd2229e1717b3ef6467bc7928d6 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Fri, 16 Apr 2004 00:48:47 +0000 Subject: only write db in initMp3Directory() when stuff is updated git-svn-id: https://svn.musicpd.org/mpd/trunk@781 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/directory.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/directory.c b/src/directory.c index 726eae241..27652e3db 100644 --- a/src/directory.c +++ b/src/directory.c @@ -63,6 +63,10 @@ #define DIRECTORY_UPDATE_EXIT_UPDATE 1 #define DIRECTORY_UPDATE_EXIT_ERROR 2 +#define DIRECTORY_RETURN_NOUPDATE 0 +#define DIRECTORY_RETURN_UPDATE 1 +#define DIRECTORY_RETURN_ERROR -1 + typedef List DirectoryList; typedef struct _Directory { @@ -309,7 +313,7 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) { if(isMusic(name,&mtime)) { if(0==findInList(directory->songs,shortname,&song)) { addToDirectory(directory,shortname,name); - return 1; + return DIRECTORY_RETURN_UPDATE; } else if(mtime!=((Song *)song)->mtime) { LOG("updating %s\n",name); @@ -960,13 +964,15 @@ int readDirectoryDB() { return 0; } -/* return values: - -1 -> error - 0 -> no error, but nothing updated - 1 -> no error, and stuff updated - */ int updateMp3Directory(FILE * fp) { - if(updateDirectory(mp3rootDirectory)<0) { + switch(updateDirectory(mp3rootDirectory)) { + case 0: + /* nothing updated */ + return 0; + case 1: + /* something was updated and db should be written */ + break; + default: ERROR("problems updating music db\n"); myfprintf(fp,"%s problems updating music db\n",COMMAND_RESPOND_ERROR); return -1; -- cgit v1.2.3