/*
* citadel_dirs.c : calculate pathnames for various files used in the Citadel system
*
- * Copyright (c) 1987-2014 by the citadel.org team
+ * Copyright (c) 1987-2016 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3.
#include <limits.h>
#include <time.h>
#include <errno.h>
+#include <syslog.h>
#include <libcitadel.h>
#include "citadel.h"
+#include "citadel_dirs.h"
/* our directories... */
char ctdl_home_directory[PATH_MAX] = "";
ctdl_netdigest_dir,
room->QRnumber);
StripSlashes(buf, 0);
- fprintf(stderr, "----> %s \n", buf);
unlink(buf);
}
-FILE *create_digest_file(struct ctdlroom *room)
+FILE *create_digest_file(struct ctdlroom *room, int forceCreate)
{
- char buf[PATH_MAX];
+ struct stat stbuf;
+ char fn[PATH_MAX];
+ int exists;
FILE *fp;
- snprintf(buf, PATH_MAX, "%s/%ld.eml",
+ snprintf(fn, PATH_MAX, "%s/%ld.eml",
ctdl_netdigest_dir,
room->QRnumber);
- StripSlashes(buf, 0);
- fprintf(stderr, "----> %s \n", buf);
+ StripSlashes(fn, 0);
+
+ exists = stat(fn, &stbuf);
+ if (!forceCreate && (exists == -1))
+ return NULL;
- fp = fopen(buf, "w+");
+ fp = fopen(fn, "w+");
if (fp == NULL) {
-
+ syslog(LOG_EMERG,
+ "failed to create digest file %s: %s",
+ fn,
+ strerror(errno));
}
return fp;
}
{
int rv;
rv = mkdir(which, ACCESS);
- if ((rv == -1) && (errno == EEXIST))
+ if ((rv == -1) && (errno != EEXIST)) {
+ syslog(LOG_EMERG,
+ "failed to create directory %s: %s",
+ which,
+ strerror(errno));
return rv;
+ }
rv = chmod(which, ACCESS);
- if (rv == -1)
+ if (rv == -1) {
+ syslog(LOG_EMERG,
+ "failed to set permissions for directory %s: %s",
+ which,
+ strerror(errno));
return rv;
+ }
rv = chown(which, UID, GID);
+ if (rv == -1) {
+ syslog(LOG_EMERG,
+ "failed to set owner for directory %s: %s",
+ which,
+ strerror(errno));
+ return rv;
+ }
return rv;
}
rv = create_dir(ctdl_bb_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
if (rv != -1)
rv = create_dir(ctdl_file_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
- if (rv != -1)
- rv = create_dir(ctdl_netcfg_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
if (rv != -1)
rv = create_dir(ctdl_spool_dir , S_IRUSR|S_IWUSR|S_IXUSR, UID, -1);
if (rv != -1)