diff options
author | Max Kellermann <max@duempel.org> | 2008-09-07 13:48:37 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-07 13:48:37 +0200 |
commit | f320c9fa1dc2268fbd97ba9cb00140276c0a2e23 (patch) | |
tree | bd4102bc4a1d6914777305bf73690f3a8c5c7fa0 /src | |
parent | 528be8a0a9b8f9978b3968ab855e69a7ec2935d4 (diff) | |
download | mpd-f320c9fa1dc2268fbd97ba9cb00140276c0a2e23.tar.gz mpd-f320c9fa1dc2268fbd97ba9cb00140276c0a2e23.tar.xz mpd-f320c9fa1dc2268fbd97ba9cb00140276c0a2e23.zip |
directory: don't pass fd to traverseAllIn()
This patch continues the work of the previous patch: don't pass a file
descriptor at all to traverseAllIn(). Since this fd was only used to
report "directory not found" errors, we can easily move that check to
the caller. This is a great relief, since it removes the dependency
on a client connection from a lot of enumeration functions.
Diffstat (limited to '')
-rw-r--r-- | src/command.c | 47 | ||||
-rw-r--r-- | src/dbUtils.c | 30 | ||||
-rw-r--r-- | src/dbUtils.h | 8 | ||||
-rw-r--r-- | src/directory.c | 12 | ||||
-rw-r--r-- | src/directory.h | 2 | ||||
-rw-r--r-- | src/tagTracker.c | 2 |
6 files changed, 69 insertions, 32 deletions
diff --git a/src/command.c b/src/command.c index a11978a6c..238761f74 100644 --- a/src/command.c +++ b/src/command.c @@ -442,7 +442,13 @@ static int handleAdd(int fd, mpd_unused int *permission, if (isRemoteUrl(path)) return addToPlaylist(path, NULL); - result = addAllIn(fd, path); + result = addAllIn(path); + if (result == (enum playlist_result)-1) { + commandError(fd, ACK_ERROR_NO_EXIST, + "directory or file not found"); + return -1; + } + return print_playlist_result(fd, result); } @@ -658,6 +664,9 @@ static int handleFind(int fd, mpd_unused int *permission, } ret = findSongsIn(fd, NULL, numItems, items); + if (ret == -1) + commandError(fd, ACK_ERROR_NO_EXIST, + "directory or file not found"); freeLocateTagItemArray(numItems, items); @@ -680,6 +689,9 @@ static int handleSearch(int fd, mpd_unused int *permission, } ret = searchForSongsIn(fd, NULL, numItems, items); + if (ret == -1) + commandError(fd, ACK_ERROR_NO_EXIST, + "directory or file not found"); freeLocateTagItemArray(numItems, items); @@ -702,6 +714,9 @@ static int handleCount(int fd, mpd_unused int *permission, } ret = searchStatsForSongsIn(fd, NULL, numItems, items); + if (ret == -1) + commandError(fd, ACK_ERROR_NO_EXIST, + "directory or file not found"); freeLocateTagItemArray(numItems, items); @@ -840,10 +855,17 @@ static int handleListAll(int fd, mpd_unused int *permission, mpd_unused int argc, char *argv[]) { char *directory = NULL; + int ret; if (argc == 2) directory = argv[1]; - return printAllIn(fd, directory); + + ret = printAllIn(fd, directory); + if (ret == -1) + commandError(fd, ACK_ERROR_NO_EXIST, + "directory or file not found"); + + return ret; } static int handleVolume(int fd, mpd_unused int *permission, @@ -962,6 +984,10 @@ static int handleList(int fd, mpd_unused int *permission, if (conditionals) freeLocateTagItemArray(numConditionals, conditionals); + if (ret == -1) + commandError(fd, ACK_ERROR_NO_EXIST, + "directory or file not found"); + return ret; } @@ -1055,10 +1081,16 @@ static int handleListAllInfo(int fd, mpd_unused int *permission, mpd_unused int argc, char *argv[]) { char *directory = NULL; + int ret; if (argc == 2) directory = argv[1]; - return printInfoForAllIn(fd, directory); + ret = printInfoForAllIn(fd, directory); + if (ret == -1) + commandError(fd, ACK_ERROR_NO_EXIST, + "directory or file not found"); + + return ret; } static int handlePing(mpd_unused int fd, mpd_unused int *permission, @@ -1175,7 +1207,14 @@ static int handlePlaylistAdd(int fd, mpd_unused int *permission, if (isRemoteUrl(path)) result = addToStoredPlaylist(path, playlist); else - result = addAllInToStoredPlaylist(fd, path, playlist); + result = addAllInToStoredPlaylist(path, playlist); + + if (result == (enum playlist_result)-1) { + commandError(fd, ACK_ERROR_NO_EXIST, + "directory or file not found"); + return -1; + } + return print_playlist_result(fd, result); } diff --git a/src/dbUtils.c b/src/dbUtils.c index a1d7014ee..4aebaed4b 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -107,7 +107,7 @@ int searchForSongsIn(int fd, const char *name, int numItems, data.array.numItems = numItems; data.array.items = items; - ret = traverseAllIn(fd, name, searchInDirectory, NULL, &data); + ret = traverseAllIn(name, searchInDirectory, NULL, &data); for (i = 0; i < numItems; i++) { free(items[i].needle); @@ -139,7 +139,7 @@ int findSongsIn(int fd, const char *name, int numItems, LocateTagItem * items) data.array.numItems = numItems; data.array.items = items; - return traverseAllIn(fd, name, findInDirectory, NULL, &data); + return traverseAllIn(name, findInDirectory, NULL, &data); } static void printSearchStats(int fd, SearchStats *stats) @@ -173,7 +173,7 @@ int searchStatsForSongsIn(int fd, const char *name, int numItems, stats.numberOfSongs = 0; stats.playTime = 0; - ret = traverseAllIn(fd, name, searchStatsInDirectory, NULL, &stats); + ret = traverseAllIn(name, searchStatsInDirectory, NULL, &stats); if (ret == 0) printSearchStats(fd, &stats); @@ -182,7 +182,7 @@ int searchStatsForSongsIn(int fd, const char *name, int numItems, int printAllIn(int fd, const char *name) { - return traverseAllIn(fd, name, printSongInDirectory, + return traverseAllIn(name, printSongInDirectory, printDirectoryInDirectory, (void*)(size_t)fd); } @@ -204,18 +204,18 @@ static int directoryAddSongToStoredPlaylist(Song *song, void *_data) return 0; } -int addAllIn(int fd, const char *name) +int addAllIn(const char *name) { - return traverseAllIn(fd, name, directoryAddSongToPlaylist, NULL, NULL); + return traverseAllIn(name, directoryAddSongToPlaylist, NULL, NULL); } -int addAllInToStoredPlaylist(int fd, const char *name, const char *utf8file) +int addAllInToStoredPlaylist(const char *name, const char *utf8file) { struct add_data data = { .path = utf8file, }; - return traverseAllIn(fd, name, directoryAddSongToStoredPlaylist, NULL, + return traverseAllIn(name, directoryAddSongToStoredPlaylist, NULL, &data); } @@ -238,26 +238,26 @@ static int sumSongTime(Song * song, void *data) int printInfoForAllIn(int fd, const char *name) { - return traverseAllIn(fd, name, directoryPrintSongInfo, + return traverseAllIn(name, directoryPrintSongInfo, printDirectoryInDirectory, (void*)(size_t)fd); } -int countSongsIn(int fd, const char *name) +int countSongsIn(const char *name) { int count = 0; void *ptr = (void *)&count; - traverseAllIn(fd, name, NULL, countSongsInDirectory, ptr); + traverseAllIn(name, NULL, countSongsInDirectory, ptr); return count; } -unsigned long sumSongTimesIn(int fd, const char *name) +unsigned long sumSongTimesIn(const char *name) { unsigned long dbPlayTime = 0; void *ptr = (void *)&dbPlayTime; - traverseAllIn(fd, name, sumSongTime, NULL, ptr); + traverseAllIn(name, sumSongTime, NULL, ptr); return dbPlayTime; } @@ -332,7 +332,7 @@ int listAllUniqueTags(int fd, int type, int numConditionals, resetVisitedFlagsInTagTracker(type); } - ret = traverseAllIn(fd, NULL, listUniqueTagsInDirectory, NULL, + ret = traverseAllIn(NULL, listUniqueTagsInDirectory, NULL, &data); if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) { @@ -370,7 +370,7 @@ void printSavedMemoryFromFilenames(void) { int sum = 0; - traverseAllIn(STDERR_FILENO, NULL, sumSavedFilenameMemoryInSong, + traverseAllIn(NULL, sumSavedFilenameMemoryInSong, sumSavedFilenameMemoryInDirectory, (void *)&sum); DEBUG("saved memory from filenames: %i\n", sum); diff --git a/src/dbUtils.h b/src/dbUtils.h index 89b69bfc3..592b62e95 100644 --- a/src/dbUtils.h +++ b/src/dbUtils.h @@ -23,9 +23,9 @@ int printAllIn(int fd, const char *name); -int addAllIn(int fd, const char *name); +int addAllIn(const char *name); -int addAllInToStoredPlaylist(int fd, const char *name, const char *utf8file); +int addAllInToStoredPlaylist(const char *name, const char *utf8file); int printInfoForAllIn(int fd, const char *name); @@ -37,9 +37,9 @@ int findSongsIn(int fd, const char *name, int numItems, LocateTagItem * items); int searchStatsForSongsIn(int fd, const char *name, int numItems, LocateTagItem * items); -int countSongsIn(int fd, const char *name); +int countSongsIn(const char *name); -unsigned long sumSongTimesIn(int fd, const char *name); +unsigned long sumSongTimesIn(const char *name); int listAllUniqueTags(int fd, int type, int numConditiionals, LocateTagItem * conditionals); diff --git a/src/directory.c b/src/directory.c index 23c2d274f..d72aca1de 100644 --- a/src/directory.c +++ b/src/directory.c @@ -1155,8 +1155,8 @@ int readDirectoryDB(void) readDirectoryInfo(fp, mp3rootDirectory); while (fclose(fp) && errno == EINTR) ; - stats.numberOfSongs = countSongsIn(STDERR_FILENO, NULL); - stats.dbPlayTime = sumSongTimesIn(STDERR_FILENO, NULL); + stats.numberOfSongs = countSongsIn(NULL); + stats.dbPlayTime = sumSongTimesIn(NULL); if (stat(dbFile, &st) == 0) directory_dbModTime = st.st_mtime; @@ -1220,7 +1220,7 @@ static int traverseAllInSubDirectory(Directory * directory, return errFlag; } -int traverseAllIn(int fd, const char *name, +int traverseAllIn(const char *name, int (*forEachSong) (Song *, void *), int (*forEachDir) (Directory *, void *), void *data) { @@ -1231,8 +1231,6 @@ int traverseAllIn(int fd, const char *name, if ((song = getSongFromDB(name)) && forEachSong) { return forEachSong(song, data); } - commandError(fd, ACK_ERROR_NO_EXIST, - "directory or file not found"); return -1; } @@ -1257,8 +1255,8 @@ void initMp3Directory(void) mp3rootDirectory = newDirectory(NULL, NULL); exploreDirectory(mp3rootDirectory); freeAllDirectoryStats(mp3rootDirectory); - stats.numberOfSongs = countSongsIn(STDERR_FILENO, NULL); - stats.dbPlayTime = sumSongTimesIn(STDERR_FILENO, NULL); + stats.numberOfSongs = countSongsIn(NULL); + stats.dbPlayTime = sumSongTimesIn(NULL); } static Song *getSongDetails(const char *file, const char **shortnameRet, diff --git a/src/directory.h b/src/directory.h index 02a6b22d4..19dada309 100644 --- a/src/directory.h +++ b/src/directory.h @@ -64,7 +64,7 @@ Song *getSongFromDB(const char *file); time_t getDbModTime(void); -int traverseAllIn(int fd, const char *name, +int traverseAllIn(const char *name, int (*forEachSong) (Song *, void *), int (*forEachDir) (Directory *, void *), void *data); diff --git a/src/tagTracker.c b/src/tagTracker.c index d6bef6c77..13fba77c9 100644 --- a/src/tagTracker.c +++ b/src/tagTracker.c @@ -60,7 +60,7 @@ int getNumberOfTagItems(int type) resetVisitedFlagsInTagTracker(type); - traverseAllIn(-1, NULL, visit_tag_items, NULL, (void*)(size_t)type); + traverseAllIn(NULL, visit_tag_items, NULL, (void*)(size_t)type); ret = (int)num_visited[type]; resetVisitedFlagsInTagTracker(type); |