aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory.c
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2006-06-07 21:00:36 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2006-06-07 21:00:36 +0000
commit7716a6c23419d434581aaa913cc8d901d3c84af2 (patch)
tree6ac645d57d965112440bacf4dc9f0dfdeda6ad4f /src/directory.c
parent96a3939ed094684770a42f26482a7f6191036b2a (diff)
downloadmpd-7716a6c23419d434581aaa913cc8d901d3c84af2.tar.gz
mpd-7716a6c23419d434581aaa913cc8d901d3c84af2.tar.xz
mpd-7716a6c23419d434581aaa913cc8d901d3c84af2.zip
Check that db_file exists before checking if we can write to it. Committed on behalf of qball.
git-svn-id: https://svn.musicpd.org/mpd/trunk@4255 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/directory.c')
-rw-r--r--src/directory.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/directory.c b/src/directory.c
index 2464271f4..9c8e3ba98 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -48,6 +48,7 @@
#include <errno.h>
#include <signal.h>
#include <assert.h>
+#include <libgen.h>
#define DIRECTORY_DIR "directory: "
#define DIRECTORY_MTIME "mtime: "
@@ -989,7 +990,36 @@ void sortDirectory(Directory * directory) {
int checkDirectoryDB() {
char * dbFile = getDbFile();
+ /**
+ * Check if the file exists
+ */
+ if(access(dbFile, F_OK)) {
+ char *dirPath = NULL;
+ char *dbPath = strdup(dbFile);
+
+ /**
+ * If the file doesn't exits, we can't check if we can write it,
+ * so we are going to try to get the directory path, and see if we can write a file in that
+ */
+ dirPath = dirname(dbPath);
+
+ /**
+ * Check if we can write to the directory
+ */
+ if(access(dirPath, R_OK|W_OK))
+ {
+ ERROR("Can't create db file in \"%s\": %s", dirPath, strerror(errno));
+ free(dbPath);
+ return -1;
+ }
+ free(dbPath);
+ return 0;
+
+ }
+ /**
+ * File exists, now check if we can write it
+ */
if(access(dbFile, R_OK|W_OK)) {
ERROR("db file \"%s\" cannot be opened for reading/writing: %s",
dbFile, strerror(errno));