Make io_check_dir() create parent directories
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
a0129d6751
commit
250a233ff7
32
src/io.c
32
src/io.c
@ -1053,19 +1053,41 @@ int io_check_dir(const char *dir)
|
||||
if (read_only)
|
||||
return -1;
|
||||
|
||||
char *path = mem_strdup(dir);
|
||||
char *index;
|
||||
|
||||
int existed = 1;
|
||||
errno = 0;
|
||||
if (mkdir(dir, 0700) != 0) {
|
||||
for (index = path + 1; *index; index++) {
|
||||
if (*index == '/') {
|
||||
*index = '\0';
|
||||
if (mkdir(path, 0700) != 0) {
|
||||
if (errno != EEXIST) {
|
||||
fprintf(stderr,
|
||||
_("FATAL ERROR: could not create %s: %s\n"),
|
||||
dir, strerror(errno));
|
||||
path, strerror(errno));
|
||||
exit_calcurse(EXIT_FAILURE);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
existed = 0;
|
||||
}
|
||||
*index = '/';
|
||||
}
|
||||
}
|
||||
|
||||
if (mkdir(path, 0700) != 0) {
|
||||
if (errno != EEXIST) {
|
||||
fprintf(stderr,
|
||||
_("FATAL ERROR: could not create %s: %s\n"),
|
||||
path, strerror(errno));
|
||||
exit_calcurse(EXIT_FAILURE);
|
||||
}
|
||||
} else {
|
||||
existed = 0;
|
||||
}
|
||||
|
||||
mem_free(path);
|
||||
return existed;
|
||||
}
|
||||
|
||||
unsigned io_dir_exists(const char *path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user