aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-09 15:47:22 +0200
committerEric Wong <normalperson@yhbt.net>2008-10-11 19:21:50 -0700
commit189e7bbfe4ca060bc26bc917bd65b71a38851d13 (patch)
tree5667d3eaa2feef9af7ba00816cb287bdd489e837 /src
parent017e2e4a4e8e8b60446cd90fe3d7ab1b3165572e (diff)
downloadmpd-189e7bbfe4ca060bc26bc917bd65b71a38851d13.tar.gz
mpd-189e7bbfe4ca060bc26bc917bd65b71a38851d13.tar.xz
mpd-189e7bbfe4ca060bc26bc917bd65b71a38851d13.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')
-rw-r--r--src/update.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/update.c b/src/update.c
index 564e691d0..73ab142c1 100644
--- a/src/update.c
+++ b/src/update.c
@@ -308,13 +308,34 @@ enum update_return updateDirectory(struct directory *directory)
return ret;
}
-static struct directory * addDirectoryPathToDB(const char *utf8path)
+static struct directory *
+directory_make_child_checked(struct directory *parent, const char *path)
+{
+ struct directory *directory;
+ struct stat st;
+ struct mpd_song *conflicting;
+
+ if ((directory = directory_get_child(parent, path)))
+ 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 */
+ if ((conflicting = songvec_find(&parent->songs, mpd_basename(path))))
+ 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 mpd_song *conflicting;
parent = parent_path(path_max_tmp, utf8path);
@@ -326,25 +347,7 @@ static struct directory * 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 * addParentPathToDB(const char *utf8path)