From 6f43d71628db3c9acb9e0693216885685566b7d3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 10:48:48 +0200 Subject: directory: moved code to update.c The source directory.c mixes several libraries: directory object management, database management and database update, resulting in a 1000+ line monster. Move the whole database update code to update.c. --- src/command.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/command.c') diff --git a/src/command.c b/src/command.c index 6ce5cbed5..4fe1f7410 100644 --- a/src/command.c +++ b/src/command.c @@ -20,6 +20,7 @@ #include "playlist.h" #include "ls.h" #include "directory.h" +#include "update.h" #include "volume.h" #include "stats.h" #include "myfprintf.h" -- cgit v1.2.3 From 729523ec80f35a683c982054628cd47d2161d3d4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:07:35 +0200 Subject: directory: moved code to database.c Taming the directory.c monster, part II: move the database management stuff to database. directory.c should only contain code which works on directory objects. --- src/command.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/command.c') diff --git a/src/command.c b/src/command.c index 4fe1f7410..4923ee5d5 100644 --- a/src/command.c +++ b/src/command.c @@ -19,6 +19,7 @@ #include "command.h" #include "playlist.h" #include "ls.h" +#include "database.h" #include "directory.h" #include "update.h" #include "volume.h" -- cgit v1.2.3 From 0576b8abf8b2fd25105f6e0190a93ddec298e9fb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:07:39 +0200 Subject: database: removed printDirectoryInfo() The same can be achieved with directory_print(db_get_directory()). --- src/command.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/command.c') diff --git a/src/command.c b/src/command.c index 4923ee5d5..7d1e2f306 100644 --- a/src/command.c +++ b/src/command.c @@ -559,15 +559,18 @@ static int handleLsInfo(int fd, mpd_unused int *permission, int argc, char *argv[]) { const char *path = ""; + const struct directory *directory; if (argc == 2) path = argv[1]; - if (printDirectoryInfo(fd, path) < 0) { + if (!(directory = getDirectory(path))) { commandError(fd, ACK_ERROR_NO_EXIST, "directory not found"); return -1; } + directory_print(fd, directory); + if (isRootDirectory(path)) return lsPlaylists(fd, path); -- cgit v1.2.3 From 4629f646077109f7c6185aab92560da52c237412 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:07:55 +0200 Subject: database: renamed functions, "db_" prefix and no CamelCase Yet another CamelCase removal patch. --- src/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/command.c') diff --git a/src/command.c b/src/command.c index 7d1e2f306..0f9852592 100644 --- a/src/command.c +++ b/src/command.c @@ -564,7 +564,7 @@ static int handleLsInfo(int fd, mpd_unused int *permission, if (argc == 2) path = argv[1]; - if (!(directory = getDirectory(path))) { + if (!(directory = db_get_directory(path))) { commandError(fd, ACK_ERROR_NO_EXIST, "directory not found"); return -1; } -- cgit v1.2.3 From a24d3738e35d509aa180fffa127abac8057101cf Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 9 Oct 2008 15:23:37 +0200 Subject: diretory: moved code to directory_save.c, directory_print.c Remove clutter from directory.c. Everything which saves or loads to/from the hard disk goes to directory_save.c, and code which sends directory information to the client is moved into directory_print.c. --- src/command.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/command.c') diff --git a/src/command.c b/src/command.c index 0f9852592..aafb88418 100644 --- a/src/command.c +++ b/src/command.c @@ -21,6 +21,7 @@ #include "ls.h" #include "database.h" #include "directory.h" +#include "directory_print.h" #include "update.h" #include "volume.h" #include "stats.h" -- cgit v1.2.3 From 1d59716731f3ed8569d60ae84c291bd93eb7d582 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 9 Oct 2008 19:17:44 +0200 Subject: update: job ID must be positive The documentation for directory_update_init() was incorrect: a job ID must be positive, not non-negative. If the update queue is full and no job was created, it makes more sense to return 0 instead of -1, because it is more consistent with the return value of isUpdatingDB(). --- src/command.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/command.c') diff --git a/src/command.c b/src/command.c index aafb88418..541a71a50 100644 --- a/src/command.c +++ b/src/command.c @@ -788,14 +788,12 @@ static int handlePlaylistMove(int fd, mpd_unused int *permission, static int print_update_result(int fd, int ret) { - if (ret >= 0) { + if (ret > 0) { fdprintf(fd, "updating_db: %i\n", ret); return 0; } - if (ret == -2) - commandError(fd, ACK_ERROR_ARG, "invalid path"); - else - commandError(fd, ACK_ERROR_UPDATE_ALREADY, "already updating"); + assert(!ret); + commandError(fd, ACK_ERROR_UPDATE_ALREADY, "already updating"); return -1; } -- cgit v1.2.3 From 6e2b0ca9edaed200f250ef487701ad161aa4a168 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 11 Oct 2008 19:49:14 -0700 Subject: directory: don't use identical struct and variable names Duplicated tokens in close proximity takes too long for my head to parse; and "dir" is an easy and common abbreviation for "directory". --- src/command.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/command.c') diff --git a/src/command.c b/src/command.c index 541a71a50..e542683d8 100644 --- a/src/command.c +++ b/src/command.c @@ -560,17 +560,17 @@ static int handleLsInfo(int fd, mpd_unused int *permission, int argc, char *argv[]) { const char *path = ""; - const struct directory *directory; + const struct directory *dir; if (argc == 2) path = argv[1]; - if (!(directory = db_get_directory(path))) { + if (!(dir = db_get_directory(path))) { commandError(fd, ACK_ERROR_NO_EXIST, "directory not found"); return -1; } - directory_print(fd, directory); + directory_print(fd, dir); if (isRootDirectory(path)) return lsPlaylists(fd, path); -- cgit v1.2.3