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
This commit is contained in:
Qball Cow 2006-05-08 21:03:47 +00:00
parent 1071524ae7
commit 66e4379d69
3 changed files with 15 additions and 0 deletions

View File

@ -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();

View File

@ -58,6 +58,8 @@ void closeMp3Directory();
int printDirectoryInfo(FILE * fp, char * dirname);
int checkDirectoryDB();
int writeDirectoryDB();
int readDirectoryDB();

View File

@ -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);