aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory.c
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2006-07-23 23:42:16 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2006-07-23 23:42:16 +0000
commit76528555dc4878df61d677534964927385670249 (patch)
tree3aa3729b7289df27135fa1eded8a5b26f932fb35 /src/directory.c
parentc3bc1e5b3cba69ab994dd4d316be56bcf4e399a2 (diff)
downloadmpd-76528555dc4878df61d677534964927385670249.tar.gz
mpd-76528555dc4878df61d677534964927385670249.tar.xz
mpd-76528555dc4878df61d677534964927385670249.zip
If we're going to create the db file, make sure the parent path is a directory
git-svn-id: https://svn.musicpd.org/mpd/trunk@4437 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/directory.c')
-rw-r--r--src/directory.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/directory.c b/src/directory.c
index 6a46051ba..85060670a 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -1036,6 +1036,21 @@ int checkDirectoryDB()
dbPath = strdup(dbFile);
dirPath = dirname(dbPath);
+ /* Check that the parent part of the path is a directory */
+ if (stat(dirPath, &st) < 0) {
+ ERROR("Couldn't stat parent directory of db file "
+ "\"%s\": %s\n", dbFile, strerror(errno));
+ free(dbPath);
+ return -1;
+ }
+
+ if (!S_ISDIR(st.st_mode)) {
+ ERROR("Couldn't create db file \"%s\" because the "
+ "parent path is not a directory\n", dbFile);
+ free(dbPath);
+ return -1;
+ }
+
/* Check if we can write to the directory */
if (access(dirPath, R_OK | W_OK)) {
ERROR("Can't create db file in \"%s\": %s\n", dirPath,
@@ -1051,7 +1066,7 @@ int checkDirectoryDB()
/* 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,
+ ERROR("Couldn't stat db file \"%s\": %s\n", dbFile,
strerror(errno));
return -1;
}