aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory.c
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2006-07-23 23:35:35 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2006-07-23 23:35:35 +0000
commitc3bc1e5b3cba69ab994dd4d316be56bcf4e399a2 (patch)
tree5ab49f937301b11631cb069061d48efa0c2d3bb9 /src/directory.c
parentbb9a5aaf2b9468869c4a8f9c8ed1ae662c7f16bd (diff)
downloadmpd-c3bc1e5b3cba69ab994dd4d316be56bcf4e399a2.tar.gz
mpd-c3bc1e5b3cba69ab994dd4d316be56bcf4e399a2.tar.xz
mpd-c3bc1e5b3cba69ab994dd4d316be56bcf4e399a2.zip
Make checkDirectoryDB check that the db file is a regular file
git-svn-id: https://svn.musicpd.org/mpd/trunk@4436 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/directory.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/directory.c b/src/directory.c
index b05428ac2..6a46051ba 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -1021,6 +1021,7 @@ static void sortDirectory(Directory * directory)
int checkDirectoryDB()
{
+ struct stat st;
char *dbFile;
char *dirPath;
char *dbPath;
@@ -1029,11 +1030,10 @@ int checkDirectoryDB()
/* Check if the file exists */
if (access(dbFile, F_OK)) {
- dbPath = strdup(dbFile);
-
/* If the file doesn't exist, 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 */
+ dbPath = strdup(dbFile);
dirPath = dirname(dbPath);
/* Check if we can write to the directory */
@@ -1049,7 +1049,19 @@ int checkDirectoryDB()
return 0;
}
- /* File exists, now check if we can write it */
+ /* Path exists, now check if it's a regular file */
+ if (stat(dbFile, &st) < 0) {
+ ERROR("Error stat'ing db file \"%s\": %s\n", dbFile,
+ strerror(errno));
+ return -1;
+ }
+
+ if (!S_ISREG(st.st_mode)) {
+ ERROR("db file \"%s\" is not a regular file\n", dbFile);
+ return -1;
+ }
+
+ /* And check that we can write to it */
if (access(dbFile, R_OK | W_OK)) {
ERROR("Can't open db file \"%s\" for reading/writing: %s\n",
dbFile, strerror(errno));
@@ -1172,6 +1184,7 @@ int readDirectoryDB()
ERROR("db info not found in db file\n");
ERROR("you should recreate the db using --create-db\n");
fseek(fp, 0, SEEK_SET);
+ return -1;
}
}