Optimize error handling in io_check_dir()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
0cd8c210bd
commit
002cf305a5
25
src/io.c
25
src/io.c
@ -1084,17 +1084,15 @@ int io_check_dir(const char *dir)
|
|||||||
char *path = mem_strdup(dir);
|
char *path = mem_strdup(dir);
|
||||||
char *index;
|
char *index;
|
||||||
|
|
||||||
int existed = 1;
|
int existed = 1, failed = 0;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
for (index = path + 1; *index; index++) {
|
for (index = path + 1; *index; index++) {
|
||||||
if (*index == '/') {
|
if (*index == '/') {
|
||||||
*index = '\0';
|
*index = '\0';
|
||||||
if (mkdir(path, 0700) != 0) {
|
if (mkdir(path, 0700) != 0) {
|
||||||
if (errno != EEXIST) {
|
if (errno != EEXIST) {
|
||||||
fprintf(stderr,
|
failed = 1;
|
||||||
_("FATAL ERROR: could not create %s: %s\n"),
|
break;
|
||||||
path, strerror(errno));
|
|
||||||
exit_calcurse(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
existed = 0;
|
existed = 0;
|
||||||
@ -1103,17 +1101,20 @@ int io_check_dir(const char *dir)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mkdir(path, 0700) != 0) {
|
if (!failed && mkdir(path, 0700) != 0) {
|
||||||
if (errno != EEXIST) {
|
if (errno != EEXIST)
|
||||||
fprintf(stderr,
|
failed = 1;
|
||||||
_("FATAL ERROR: could not create %s: %s\n"),
|
|
||||||
path, strerror(errno));
|
|
||||||
exit_calcurse(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
existed = 0;
|
existed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(failed) {
|
||||||
|
fprintf(stderr,
|
||||||
|
_("FATAL ERROR: could not create %s: %s\n"),
|
||||||
|
path, strerror(errno));
|
||||||
|
exit_calcurse(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
mem_free(path);
|
mem_free(path);
|
||||||
return existed;
|
return existed;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user