aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/database.c4
-rw-r--r--src/directory.c14
-rw-r--r--src/directory.h2
3 files changed, 10 insertions, 10 deletions
diff --git a/src/database.c b/src/database.c
index 98e50ad87..bd278a635 100644
--- a/src/database.c
+++ b/src/database.c
@@ -37,7 +37,7 @@ static time_t directory_dbModTime;
void db_init(void)
{
- music_root = directory_new(NULL, NULL);
+ music_root = directory_new("", NULL);
updateDirectory(music_root);
stats.numberOfSongs = countSongsIn(NULL);
stats.dbPlayTime = sumSongTimesIn(NULL);
@@ -233,7 +233,7 @@ int db_load(void)
struct stat st;
if (!music_root)
- music_root = directory_new(NULL, NULL);
+ music_root = directory_new("", NULL);
while (!(fp = fopen(dbFile, "r")) && errno == EINTR) ;
if (fp == NULL) {
ERROR("unable to open db file \"%s\": %s\n",
diff --git a/src/directory.c b/src/directory.c
index f79cc2dbc..295fdd09a 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -30,10 +30,11 @@ struct directory * directory_new(const char *dirname, struct directory * parent)
{
struct directory *directory;
- directory = xcalloc(1, sizeof(*directory));
+ assert(dirname != NULL);
+ assert((*dirname == 0) == (parent == NULL));
- if (dirname && strlen(dirname))
- directory->path = xstrdup(dirname);
+ directory = xcalloc(1, sizeof(*directory));
+ directory->path = xstrdup(dirname);
directory->parent = parent;
return directory;
@@ -43,8 +44,7 @@ void directory_free(struct directory * directory)
{
dirvec_destroy(&directory->children);
songvec_destroy(&directory->songs);
- if (directory->path)
- free(directory->path);
+ free(directory->path);
free(directory);
/* this resets last dir returned */
/*directory_get_path(NULL); */
@@ -140,7 +140,7 @@ int directory_save(int fd, struct directory * directory)
struct dirvec *children = &directory->children;
size_t i;
- if (directory->path &&
+ if (!isRootDirectory(directory->path) &&
fdprintf(fd, DIRECTORY_BEGIN "%s\n",
directory_get_path(directory)) < 0)
return -1;
@@ -165,7 +165,7 @@ int directory_save(int fd, struct directory * directory)
if (fdprintf(fd, SONG_END "\n") < 0)
return -1;
- if (directory->path &&
+ if (!isRootDirectory(directory->path) &&
fdprintf(fd, DIRECTORY_END "%s\n",
directory_get_path(directory)) < 0)
return -1;
diff --git a/src/directory.h b/src/directory.h
index 5609e4ea4..17c218bfb 100644
--- a/src/directory.h
+++ b/src/directory.h
@@ -63,7 +63,7 @@ static inline int directory_is_empty(struct directory *directory)
static inline const char * directory_get_path(struct directory *dir)
{
- return dir->path ? dir->path : "";
+ return dir->path;
}
void directory_prune_empty(struct directory *directory);