directory.c: get rid of the horrid dirname(3) and libgen.h dependency
Ok, so basename(3) is even more brain-damaged, inconsistent and/or broken than dirname(3) on most systems, but there are broken implementations of it out there. Just use our already existing internal parent_path() function instead and get rid of the only place where we look for libgen.h. git-svn-id: https://svn.musicpd.org/mpd/trunk@7129 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
b1cdf8dadf
commit
790e70cf25
@ -41,7 +41,6 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#define DIRECTORY_DIR "directory: "
|
||||
#define DIRECTORY_MTIME "mtime: "
|
||||
@ -988,32 +987,26 @@ static void sortDirectory(Directory * directory)
|
||||
int checkDirectoryDB(void)
|
||||
{
|
||||
struct stat st;
|
||||
char *dbFile;
|
||||
char *dirPath;
|
||||
char *dbPath;
|
||||
|
||||
dbFile = getDbFile();
|
||||
char *dbFile = getDbFile();
|
||||
|
||||
/* Check if the file exists */
|
||||
if (access(dbFile, F_OK)) {
|
||||
/* 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 = xstrdup(dbFile);
|
||||
dirPath = dirname(dbPath);
|
||||
char dirPath[MPD_PATH_MAX];
|
||||
parent_path(dirPath, dbFile);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@ -1021,12 +1014,9 @@ int checkDirectoryDB(void)
|
||||
if (access(dirPath, R_OK | W_OK)) {
|
||||
ERROR("Can't create db file in \"%s\": %s\n", dirPath,
|
||||
strerror(errno));
|
||||
free(dbPath);
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
free(dbPath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user