Fix config_create_directory bug

This commit is contained in:
Ron Pedde 2005-01-11 03:37:28 +00:00
parent c8a4fdd19d
commit 9dbd40bde8

View File

@ -158,24 +158,27 @@ int config_session=0; /**< session counter */
*/ */
int config_makedir(char *path) { int config_makedir(char *path) {
char *token; char *token, *next_token;
char *pathdup; char *pathdup;
char path_buffer[PATH_MAX]; char path_buffer[PATH_MAX];
int err; int err;
DPRINTF(E_DBG,L_CONF,"Creating %s\n",path);
pathdup=strdup(path); pathdup=strdup(path);
if(!pathdup) { if(!pathdup) {
return -1; return -1;
} }
token=strtok(pathdup+1,"/"); next_token=pathdup+1;
strcpy(path_buffer,"/"); memset(path_buffer,0,sizeof(path_buffer));
while(token) { while((token=strsep(&next_token,"/"))) {
token=strtok(NULL,"/");
if((strlen(path_buffer) + strlen(token)) < PATH_MAX) { if((strlen(path_buffer) + strlen(token)) < PATH_MAX) {
strcat(path_buffer,"/");
strcat(path_buffer,token); strcat(path_buffer,token);
if(mkdir(path_buffer,0700)) { DPRINTF(E_DBG,L_CONF,"Making %s\n",path_buffer);
if((mkdir(path_buffer,0700)) && (errno != EEXIST)) {
err=errno; err=errno;
free(pathdup); free(pathdup);
errno=err; errno=err;
@ -199,6 +202,8 @@ int config_makedir(char *path) {
int config_existdir(char *path) { int config_existdir(char *path) {
struct stat sb; struct stat sb;
DPRINTF(E_DBG,L_CONF,"Checking existence of %s\n",path);
if(stat(path,&sb)) { if(stat(path,&sb)) {
return 0; return 0;
} }
@ -385,6 +390,7 @@ int config_read(char *file) {
if(config_makedir(config.dbdir)) { if(config_makedir(config.dbdir)) {
DPRINTF(E_LOG,L_CONF,"Database dir %s does not exist, cannot create: %s\n", DPRINTF(E_LOG,L_CONF,"Database dir %s does not exist, cannot create: %s\n",
config.dbdir,strerror(errno)); config.dbdir,strerror(errno));
return -1;
} }
} }