aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-29 03:35:54 -0700
committerEric Wong <normalperson@yhbt.net>2008-10-03 17:13:18 -0700
commitddc39977bc530954a2497c96cb78e7def0747908 (patch)
tree74eaccde1a4067a4ba08e1b267be317825ca0930 /src
parentdde461fe6e012a62ee47cf5f3bfc022b650b6bf5 (diff)
downloadmpd-ddc39977bc530954a2497c96cb78e7def0747908.tar.gz
mpd-ddc39977bc530954a2497c96cb78e7def0747908.tar.xz
mpd-ddc39977bc530954a2497c96cb78e7def0747908.zip
directory: streamline deletes
Instead of relying on the shortname, just pass the song pointer to prevent redundant lookups during deletes.
Diffstat (limited to 'src')
-rw-r--r--src/directory.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/directory.c b/src/directory.c
index fc9c6b41d..0c34e2ea9 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -70,8 +70,7 @@ static enum update_return updateDirectory(Directory * directory);
static void deleteEmptyDirectoriesInDirectory(Directory * directory);
-static void removeSongFromDirectory(Directory * directory,
- const char *shortname);
+static void delete_song(Directory *dir, Song *del);
static enum update_return addSubDirectoryToDirectory(Directory * directory,
const char *name, struct stat *st);
@@ -212,16 +211,12 @@ static void freeDirectory(Directory * directory)
/*getDirectoryPath(NULL); */
}
-static void removeSongFromDirectory(Directory * directory, const char *shortname)
+static void delete_song(Directory *dir, Song *del)
{
- Song *song = songvec_find(&directory->songs, shortname);
-
- if (song) {
- char path_max_tmp[MPD_PATH_MAX]; /* wasteful */
- LOG("removing: %s\n", get_song_url(path_max_tmp, song));
- songvec_delete(&directory->songs, song);
- freeSong(song); /* FIXME racy */
- }
+ char path_max_tmp[MPD_PATH_MAX]; /* wasteful */
+ LOG("removing: %s\n", get_song_url(path_max_tmp, del));
+ songvec_delete(&dir->songs, del);
+ freeSong(del); /* FIXME racy */
}
static void deleteEmptyDirectoriesInDirectory(Directory * directory)
@@ -256,7 +251,7 @@ updateInDirectory(Directory * directory, const char *name)
} else if (st.st_mtime != song->mtime) {
LOG("updating %s\n", name);
if (updateSongInfo(song) < 0)
- removeSongFromDirectory(directory, shortname);
+ delete_song(directory, song);
return UPDATE_RETURN_UPDATED;
}
} else if (S_ISDIR(st.st_mode)) {
@@ -308,7 +303,7 @@ removeDeletedFromDirectory(char *path_max_tmp, Directory * directory)
strcpy(path_max_tmp, song->url);
if (!isFile(path_max_tmp, NULL)) {
- removeSongFromDirectory(directory, song->url);
+ delete_song(directory, song);
ret = UPDATE_RETURN_UPDATED;
}
}
@@ -322,6 +317,7 @@ static Directory *addDirectoryPathToDB(const char *utf8path)
char *parent;
Directory *parentDirectory;
Directory *directory;
+ Song *conflicting;
parent = parent_path(path_max_tmp, utf8path);
@@ -348,7 +344,10 @@ static Directory *addDirectoryPathToDB(const char *utf8path)
/* if we're adding directory paths, make sure to delete filenames
with potentially the same name */
- removeSongFromDirectory(parentDirectory, mpd_basename(directory->path));
+ conflicting = songvec_find(&parentDirectory->songs,
+ mpd_basename(directory->path));
+ if (conflicting)
+ delete_song(parentDirectory, conflicting);
return directory;
}
@@ -419,14 +418,13 @@ static enum update_return updatePath(const char *utf8path)
else if (updateSongInfo(song) == 0)
return UPDATE_RETURN_UPDATED;
else {
- removeSongFromDirectory(parentDirectory,
- song->url);
+ delete_song(parentDirectory, song);
return UPDATE_RETURN_UPDATED;
}
}
/* if updateDirectory fails, means we should delete it */
else {
- removeSongFromDirectory(parentDirectory, song->url);
+ delete_song(parentDirectory, song);
ret = UPDATE_RETURN_UPDATED;
/* don't return, path maybe a directory now */
}