aboutsummaryrefslogtreecommitdiffstats
path: root/src/update.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-09 15:47:22 +0200
committerMax Kellermann <max@duempel.org>2008-10-09 15:47:22 +0200
commit0daba6bd4342f1f080a35ca0da3d8ec63edef51f (patch)
tree49976167b671eacd612898a4f1b3ae1cc9d841f2 /src/update.c
parent2ae94fec6dccb9790b17a3472b69f70455a24247 (diff)
downloadmpd-0daba6bd4342f1f080a35ca0da3d8ec63edef51f.tar.gz
mpd-0daba6bd4342f1f080a35ca0da3d8ec63edef51f.tar.xz
mpd-0daba6bd4342f1f080a35ca0da3d8ec63edef51f.zip
update: moved code to directory_make_child_checked()
The branching looks a bit complicated in addDirectoryPathToDB() - improve its readability by moving code to a simplified separate function.
Diffstat (limited to 'src/update.c')
-rw-r--r--src/update.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/update.c b/src/update.c
index ddd3e27d1..b93aadc5d 100644
--- a/src/update.c
+++ b/src/update.c
@@ -321,13 +321,35 @@ updateDirectory(struct directory *directory)
}
static struct directory *
+directory_make_child_checked(struct directory *parent, const char *path)
+{
+ struct directory *directory;
+ struct stat st;
+ struct song *conflicting;
+
+ directory = directory_get_child(parent, path);
+ if (directory != NULL)
+ return directory;
+
+ if (myStat(path, &st) < 0 ||
+ inodeFoundInParent(parent, st.st_ino, st.st_dev))
+ return NULL;
+
+ /* if we're adding directory paths, make sure to delete filenames
+ with potentially the same name */
+ conflicting = songvec_find(&parent->songs, mpd_basename(path));
+ if (conflicting)
+ delete_song(parent, conflicting);
+
+ return directory_new_child(parent, path);
+}
+
+static struct directory *
addDirectoryPathToDB(const char *utf8path)
{
char path_max_tmp[MPD_PATH_MAX];
char *parent;
struct directory *parentDirectory;
- struct directory *directory;
- struct song *conflicting;
parent = parent_path(path_max_tmp, utf8path);
@@ -339,26 +361,7 @@ addDirectoryPathToDB(const char *utf8path)
if (!parentDirectory)
return NULL;
- if ((directory = directory_get_child(parentDirectory, utf8path))) {
- assert(parentDirectory == directory->parent);
- } else {
- struct stat st;
- if (myStat(utf8path, &st) < 0 ||
- inodeFoundInParent(parentDirectory, st.st_ino, st.st_dev))
- return NULL;
-
- directory = directory_new_child(parentDirectory,
- utf8path);
- }
-
- /* if we're adding directory paths, make sure to delete filenames
- with potentially the same name */
- conflicting = songvec_find(&parentDirectory->songs,
- mpd_basename(directory->path));
- if (conflicting)
- delete_song(parentDirectory, conflicting);
-
- return directory;
+ return directory_make_child_checked(parentDirectory, utf8path);
}
static struct directory *