Commit ea8ae68e authored by Max Kellermann's avatar Max Kellermann

directory: added directory_is_root()

directory_is_root() is cheaper than isRootDirectory(directory_get_path()).
parent 923d2c96
...@@ -64,9 +64,10 @@ static int ...@@ -64,9 +64,10 @@ static int
printDirectoryInDirectory(struct directory *directory, void *data) printDirectoryInDirectory(struct directory *directory, void *data)
{ {
struct client *client = data; struct client *client = data;
if (!isRootDirectory(directory->path)) {
if (!directory_is_root(directory))
client_printf(client, "directory: %s\n", directory_get_path(directory)); client_printf(client, "directory: %s\n", directory_get_path(directory));
}
return 0; return 0;
} }
...@@ -374,7 +375,7 @@ sumSavedFilenameMemoryInDirectory(struct directory *dir, void *data) ...@@ -374,7 +375,7 @@ sumSavedFilenameMemoryInDirectory(struct directory *dir, void *data)
{ {
int *sum = data; int *sum = data;
if (isRootDirectory(dir->path)) if (directory_is_root(dir))
return 0; return 0;
*sum += (strlen(directory_get_path(dir)) + 1 *sum += (strlen(directory_get_path(dir)) + 1
......
...@@ -71,6 +71,15 @@ directory_get_path(const struct directory *directory) ...@@ -71,6 +71,15 @@ directory_get_path(const struct directory *directory)
} }
/** /**
* Is this the root directory of the music database?
*/
static inline bool
directory_is_root(const struct directory *directory)
{
return directory->parent == NULL;
}
/**
* Returns the base name of the directory. * Returns the base name of the directory.
*/ */
const char * const char *
......
...@@ -36,7 +36,7 @@ directory_save(FILE *fp, struct directory *directory) ...@@ -36,7 +36,7 @@ directory_save(FILE *fp, struct directory *directory)
size_t i; size_t i;
int retv; int retv;
if (!isRootDirectory(directory->path)) { if (!directory_is_root(directory)) {
retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN, retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN,
directory_get_path(directory)); directory_get_path(directory));
if (retv < 0) if (retv < 0)
...@@ -57,7 +57,7 @@ directory_save(FILE *fp, struct directory *directory) ...@@ -57,7 +57,7 @@ directory_save(FILE *fp, struct directory *directory)
songvec_save(fp, &directory->songs); songvec_save(fp, &directory->songs);
if (!isRootDirectory(directory->path) && if (!directory_is_root(directory) &&
fprintf(fp, DIRECTORY_END "%s\n", fprintf(fp, DIRECTORY_END "%s\n",
directory_get_path(directory)) < 0) directory_get_path(directory)) < 0)
return -1; return -1;
......
...@@ -181,7 +181,7 @@ song_get_url(const struct song *song, char *path_max_tmp) ...@@ -181,7 +181,7 @@ song_get_url(const struct song *song, char *path_max_tmp)
assert(song != NULL); assert(song != NULL);
assert(*song->url); assert(*song->url);
if (!song->parent || isRootDirectory(song->parent->path)) if (!song_in_database(song) || directory_is_root(song->parent))
strcpy(path_max_tmp, song->url); strcpy(path_max_tmp, song->url);
else else
pfx_dir(path_max_tmp, song->url, strlen(song->url), pfx_dir(path_max_tmp, song->url, strlen(song->url),
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
void void
song_print_url(struct client *client, struct song *song) song_print_url(struct client *client, struct song *song)
{ {
if (song->parent && !isRootDirectory(song->parent->path)) { if (song_in_database(song) && !directory_is_root(song->parent)) {
client_printf(client, "%s%s/%s\n", SONG_FILE, client_printf(client, "%s%s/%s\n", SONG_FILE,
directory_get_path(song->parent), song->url); directory_get_path(song->parent), song->url);
} else { } else {
......
...@@ -290,7 +290,7 @@ make_subdir(struct directory *parent, const char *name) ...@@ -290,7 +290,7 @@ make_subdir(struct directory *parent, const char *name)
if (directory == NULL) { if (directory == NULL) {
char path[MPD_PATH_MAX]; char path[MPD_PATH_MAX];
if (isRootDirectory(directory_get_path(parent))) if (directory_is_root(parent))
strcpy(path, name); strcpy(path, name);
else else
pfx_dir(path, name, strlen(name), pfx_dir(path, name, strlen(name),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment