From 66e4379d698172fe7c3f17799eb24628df79bffa Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Mon, 8 May 2006 21:03:47 +0000 Subject: Jat/Q patch for checking permission on database before creating it git-svn-id: https://svn.musicpd.org/mpd/trunk@4140 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/directory.c | 12 ++++++++++++ src/directory.h | 2 ++ src/main.c | 1 + 3 files changed, 15 insertions(+) diff --git a/src/directory.c b/src/directory.c index 891e7c351..8e1904794 100644 --- a/src/directory.c +++ b/src/directory.c @@ -988,6 +988,18 @@ void sortDirectory(Directory * directory) { } } +int checkDirectoryDB() { + char * dbFile = getDbFile(); + + if(access(dbFile, R_OK|W_OK)) { + ERROR("db file \"%s\" cannot be opened for reading/writing: %s", + dbFile, strerror(errno)); + return -1; + } + + return 0; +} + int writeDirectoryDB() { FILE * fp; char * dbFile = getDbFile(); diff --git a/src/directory.h b/src/directory.h index 48807ea87..0a640aaef 100644 --- a/src/directory.h +++ b/src/directory.h @@ -58,6 +58,8 @@ void closeMp3Directory(); int printDirectoryInfo(FILE * fp, char * dirname); +int checkDirectoryDB(); + int writeDirectoryDB(); int readDirectoryDB(); diff --git a/src/main.c b/src/main.c index f7eb8a45a..944eb037a 100644 --- a/src/main.c +++ b/src/main.c @@ -320,6 +320,7 @@ void openDB(Options * options, char * argv0) { exit(EXIT_FAILURE); } flushWarningLog(); + if(checkDirectoryDB()<0) exit(EXIT_FAILURE); initMp3Directory(); if(writeDirectoryDB()<0) exit(EXIT_FAILURE); if(options->createDB) exit(EXIT_SUCCESS); -- cgit v1.2.3