Commit af153d34 authored by J. Alexander Treuman's avatar J. Alexander Treuman

Tidying up code in checkDirectoryDB

git-svn-id: https://svn.musicpd.org/mpd/trunk@4434 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 14eea124
...@@ -1021,39 +1021,37 @@ static void sortDirectory(Directory * directory) ...@@ -1021,39 +1021,37 @@ static void sortDirectory(Directory * directory)
int checkDirectoryDB() int checkDirectoryDB()
{ {
char *dbFile = getDbFile(); char *dbFile;
/** char *dirPath;
* Check if the file exists char *dbPath;
*/
dbFile = getDbFile();
/* Check if the file exists */
if (access(dbFile, F_OK)) { if (access(dbFile, F_OK)) {
char *dirPath = NULL; dbPath = strdup(dbFile);
char *dbPath = strdup(dbFile);
/** /* If the file doesn't exist, we can't check if we can write
* If the file doesn't exits, we can't check if we can write it, * it, so we are going to try to get the directory path, and
* so we are going to try to get the directory path, and see if we can write a file in that * see if we can write a file in that */
*/
dirPath = dirname(dbPath); dirPath = dirname(dbPath);
/** /* Check if we can write to the directory */
* Check if we can write to the directory
*/
if (access(dirPath, R_OK | W_OK)) { if (access(dirPath, R_OK | W_OK)) {
ERROR("Can't create db file in \"%s\": %s", dirPath, ERROR("Can't create db file in \"%s\": %s\n", dirPath,
strerror(errno)); strerror(errno));
free(dbPath); free(dbPath);
return -1; return -1;
} }
free(dbPath); free(dbPath);
return 0; return 0;
} }
/**
* File exists, now check if we can write it /* File exists, now check if we can write it */
*/
if (access(dbFile, R_OK | W_OK)) { if (access(dbFile, R_OK | W_OK)) {
ERROR("db file \"%s\" cannot be opened for reading/writing: %s", ERROR("Can't open db file \"%s\" for reading/writing: %s\n",
dbFile, strerror(errno)); dbFile, strerror(errno));
return -1; return -1;
} }
......
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