aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-01-24 19:07:11 +0100
committerMax Kellermann <max@duempel.org>2012-01-24 20:03:18 +0100
commit420a4c163d4147b6354244cba69fbdd78e17ced2 (patch)
tree2e247c381ffd087a6a7a981e432f827b147dcac7 /src/directory.c
parent1bab735580f83932407b90c722bd021a49c389e8 (diff)
downloadmpd-420a4c163d4147b6354244cba69fbdd78e17ced2.tar.gz
mpd-420a4c163d4147b6354244cba69fbdd78e17ced2.tar.xz
mpd-420a4c163d4147b6354244cba69fbdd78e17ced2.zip
directory: simplify constructors and clarify API documentation
Pass only the "name" to a directory, instead of the full (relative) path.
Diffstat (limited to 'src/directory.c')
-rw-r--r--src/directory.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/directory.c b/src/directory.c
index 380232761..e77eb69f2 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -66,12 +66,47 @@ directory_free(struct directory *directory)
/*directory_get_path(NULL); */
}
+void
+directory_delete(struct directory *directory)
+{
+ assert(directory != NULL);
+ assert(directory->parent != NULL);
+
+ dirvec_delete(&directory->parent->children, directory);
+ directory_free(directory);
+}
+
const char *
directory_get_name(const struct directory *directory)
{
return g_basename(directory->path);
}
+struct directory *
+directory_new_child(struct directory *parent, const char *name_utf8)
+{
+ assert(parent != NULL);
+ assert(name_utf8 != NULL);
+ assert(*name_utf8 != 0);
+
+ char *allocated;
+ const char *path_utf8;
+ if (directory_is_root(parent)) {
+ allocated = NULL;
+ path_utf8 = name_utf8;
+ } else {
+ allocated = g_strconcat(directory_get_path(parent),
+ "/", name_utf8, NULL);
+ path_utf8 = allocated;
+ }
+
+ struct directory *directory = directory_new(path_utf8, parent);
+ g_free(allocated);
+
+ dirvec_add(&parent->children, directory);
+ return directory;
+}
+
void
directory_prune_empty(struct directory *directory)
{
@@ -83,10 +118,8 @@ directory_prune_empty(struct directory *directory)
directory_prune_empty(child);
- if (directory_is_empty(child)) {
- dirvec_delete(dv, child);
- directory_free(child);
- }
+ if (directory_is_empty(child))
+ directory_delete(child);
}
if (!dv->nr)
dirvec_destroy(dv);