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 <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <libgen.h>
|
|
||||||
|
|
||||||
#define DIRECTORY_DIR "directory: "
|
#define DIRECTORY_DIR "directory: "
|
||||||
#define DIRECTORY_MTIME "mtime: "
|
#define DIRECTORY_MTIME "mtime: "
|
||||||
@ -988,32 +987,26 @@ static void sortDirectory(Directory * directory)
|
|||||||
int checkDirectoryDB(void)
|
int checkDirectoryDB(void)
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *dbFile;
|
char *dbFile = getDbFile();
|
||||||
char *dirPath;
|
|
||||||
char *dbPath;
|
|
||||||
|
|
||||||
dbFile = getDbFile();
|
|
||||||
|
|
||||||
/* Check if the file exists */
|
/* Check if the file exists */
|
||||||
if (access(dbFile, F_OK)) {
|
if (access(dbFile, F_OK)) {
|
||||||
/* If the file doesn't exist, we can't check if we can write
|
/* 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
|
* it, 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 */
|
||||||
dbPath = xstrdup(dbFile);
|
char dirPath[MPD_PATH_MAX];
|
||||||
dirPath = dirname(dbPath);
|
parent_path(dirPath, dbFile);
|
||||||
|
|
||||||
/* Check that the parent part of the path is a directory */
|
/* Check that the parent part of the path is a directory */
|
||||||
if (stat(dirPath, &st) < 0) {
|
if (stat(dirPath, &st) < 0) {
|
||||||
ERROR("Couldn't stat parent directory of db file "
|
ERROR("Couldn't stat parent directory of db file "
|
||||||
"\"%s\": %s\n", dbFile, strerror(errno));
|
"\"%s\": %s\n", dbFile, strerror(errno));
|
||||||
free(dbPath);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!S_ISDIR(st.st_mode)) {
|
if (!S_ISDIR(st.st_mode)) {
|
||||||
ERROR("Couldn't create db file \"%s\" because the "
|
ERROR("Couldn't create db file \"%s\" because the "
|
||||||
"parent path is not a directory\n", dbFile);
|
"parent path is not a directory\n", dbFile);
|
||||||
free(dbPath);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1021,12 +1014,9 @@ int checkDirectoryDB(void)
|
|||||||
if (access(dirPath, R_OK | W_OK)) {
|
if (access(dirPath, R_OK | W_OK)) {
|
||||||
ERROR("Can't create db file in \"%s\": %s\n", dirPath,
|
ERROR("Can't create db file in \"%s\": %s\n", dirPath,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
free(dbPath);
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(dbPath);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user