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
printDirectoryInDirectory(struct directory *directory, void *data)
{
struct client *client = data;
if (!isRootDirectory(directory->path)) {
if (!directory_is_root(directory))
client_printf(client, "directory: %s\n", directory_get_path(directory));
}
return 0;
}
......@@ -374,7 +375,7 @@ sumSavedFilenameMemoryInDirectory(struct directory *dir, void *data)
{
int *sum = data;
if (isRootDirectory(dir->path))
if (directory_is_root(dir))
return 0;
*sum += (strlen(directory_get_path(dir)) + 1
......
......@@ -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.
*/
const char *
......
......@@ -36,7 +36,7 @@ directory_save(FILE *fp, struct directory *directory)
size_t i;
int retv;
if (!isRootDirectory(directory->path)) {
if (!directory_is_root(directory)) {
retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN,
directory_get_path(directory));
if (retv < 0)
......@@ -57,7 +57,7 @@ directory_save(FILE *fp, struct directory *directory)
songvec_save(fp, &directory->songs);
if (!isRootDirectory(directory->path) &&
if (!directory_is_root(directory) &&
fprintf(fp, DIRECTORY_END "%s\n",
directory_get_path(directory)) < 0)
return -1;
......
......@@ -181,7 +181,7 @@ song_get_url(const struct song *song, char *path_max_tmp)
assert(song != NULL);
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);
else
pfx_dir(path_max_tmp, song->url, strlen(song->url),
......
......@@ -26,7 +26,7 @@
void
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,
directory_get_path(song->parent), song->url);
} else {
......
......@@ -290,7 +290,7 @@ make_subdir(struct directory *parent, const char *name)
if (directory == NULL) {
char path[MPD_PATH_MAX];
if (isRootDirectory(directory_get_path(parent)))
if (directory_is_root(parent))
strcpy(path, name);
else
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