Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/libduc/duc.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ void duc_set_log_callback(duc *duc, duc_log_callback cb)
duc->log_callback = cb;
}

int mkdir_p(const char *pathname, mode_t mode)
{
int r = mkdir(pathname, mode);
if((-1) == r && errno == EEXIST) {
// if it's a directory, this is fine.
struct stat statbuf;
if((-1) != stat(pathname, &statbuf) && (statbuf.st_mode & S_IFMT) == S_IFDIR)
return 0;
}
return r;
}

// Return 0 ok, -1 for errors.
int duc_open(duc *duc, const char *path_db, duc_open_flags flags)
{
Expand Down Expand Up @@ -96,7 +108,7 @@ int duc_open(duc *duc, const char *path_db, duc_open_flags flags)
/* Append parent folder */
snprintf(tmp, sizeof tmp, "%s/duc", home);
/* Create if needed */
res = mkdir(tmp, 0700);
res = mkdir_p(tmp, 0700);
if (res != 0) {
duc_log(duc, DUC_LOG_FTL, "Error! Cannot create mkdir \"%s\", %s", tmp, strerror(errno));
exit(1);
Expand All @@ -113,7 +125,7 @@ int duc_open(duc *duc, const char *path_db, duc_open_flags flags)
/* Append parent folder */
snprintf(tmp, sizeof tmp, "%s/.cache/duc", home);
/* Create if needed */
res = mkdir(tmp, 0700);
res = mkdir_p(tmp, 0700);
if (res != 0) {
duc_log(duc, DUC_LOG_FTL, "Error! Cannot create mkdir \"%s\", %s", tmp, strerror(errno));
exit(1);
Expand Down