CID 22581 Time of check time of use

CID 22582 Time of check time of use
CID 30743 Time of check time of use
This commit is contained in:
Enno Rehling 2015-11-05 13:27:38 +01:00
parent 8a057f183f
commit 5f99288af1
1 changed files with 14 additions and 20 deletions

View File

@ -1547,19 +1547,14 @@ int write_reports(faction * f, time_t ltime)
struct report_context ctx; struct report_context ctx;
const char *encoding = "UTF-8"; const char *encoding = "UTF-8";
report_type *rtype; report_type *rtype;
const char *path = reportpath();; const char *path = reportpath();
if (noreports) { if (noreports) {
return false; return false;
} }
prepare_report(&ctx, f); prepare_report(&ctx, f);
get_addresses(&ctx); get_addresses(&ctx);
if (_access(path, 0) < 0) { mkreportdir(path);
if (_mkdir(path) != 0) {
log_error("could not create reports directory %s: %s", path, strerror(errno));
abort();
}
}
if (errno) { if (errno) {
log_warning("errno was %d before writing reports", errno); log_warning("errno was %d before writing reports", errno);
errno = 0; errno = 0;
@ -1631,6 +1626,15 @@ static void check_messages_exist(void) {
ct_checknames(); ct_checknames();
} }
void mkreportdir(const char *rpath) {
if (_access(rpath, 0) < 0) {
if (_mkdir(rpath) != 0) {
log_error("could not create reports directory %s: %s", rpath, strerror(errno));
abort();
}
}
}
int init_reports(void) int init_reports(void)
{ {
check_messages_exist(); check_messages_exist();
@ -1641,12 +1645,7 @@ int init_reports(void)
return 0; return 0;
} }
} }
if (_mkdir(reportpath()) != 0) { mkreportdir(reportpath());
if (errno != EEXIST) {
perror("could not create reportpath");
return -1;
}
}
return 0; return 0;
} }
@ -1663,13 +1662,8 @@ int reports(void)
report_donations(); report_donations();
remove_empty_units(); remove_empty_units();
if (_access(rpath, 0) < 0) { mkreportdir(rpath);
if (_mkdir(rpath) != 0) { sprintf(path, "%s/reports.txt", rpath);
log_error("could not create reports directory %s: %s", rpath, strerror(errno));
abort();
}
}
sprintf(path, "%s/reports.txt", reportpath());
mailit = fopen(path, "w"); mailit = fopen(path, "w");
if (mailit == NULL) { if (mailit == NULL) {
log_error("%s could not be opened!\n", path); log_error("%s could not be opened!\n", path);