aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-07 13:48:37 +0200
committerEric Wong <normalperson@yhbt.net>2008-09-09 01:11:26 -0700
commit7d7b69e576500522a011627d7937e255aa7c16c7 (patch)
treee94ef26cff7f3272707aca3a8da54bb0ea7723d3 /src
parentdcc575a3a877e342e895df9fc99108028151cc6a (diff)
downloadmpd-7d7b69e576500522a011627d7937e255aa7c16c7.tar.gz
mpd-7d7b69e576500522a011627d7937e255aa7c16c7.tar.xz
mpd-7d7b69e576500522a011627d7937e255aa7c16c7.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 'src')
-rw-r--r--src/command.c47
-rw-r--r--src/dbUtils.c30
-rw-r--r--src/dbUtils.h8
-rw-r--r--src/directory.c12
-rw-r--r--src/directory.h2
-rw-r--r--src/tagTracker.c2
6 files changed, 69 insertions, 32 deletions
diff --git a/src/command.c b/src/command.c
index 59a99141a..7a2981e68 100644
--- a/src/command.c
+++ b/src/command.c
@@ -440,7 +440,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);
}
@@ -656,6 +662,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);
@@ -678,6 +687,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);
@@ -700,6 +712,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);
@@ -838,10 +853,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,
@@ -960,6 +982,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;
}
@@ -1053,10 +1079,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,
@@ -1173,7 +1205,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 efce0f4aa..e447bc5ad 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -106,7 +106,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);
@@ -138,7 +138,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)
@@ -172,7 +172,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);
@@ -181,7 +181,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);
}
@@ -203,18 +203,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);
}
@@ -237,26 +237,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;
}
@@ -331,7 +331,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) {
@@ -369,7 +369,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 48d3249ce..64d9492a8 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -1153,8 +1153,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;
@@ -1218,7 +1218,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)
{
@@ -1229,8 +1229,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;
}
@@ -1255,8 +1253,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 e470f85ea..dd9d56330 100644
--- a/src/tagTracker.c
+++ b/src/tagTracker.c
@@ -61,7 +61,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);