From 29ab2aed192cae114a01931579554f75273fb485 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 24 Aug 2023 14:23:09 -0900 Subject: [PATCH] ctdldump/ctdlload: -h now works identical to citserver --- citadel/utils/ctdldump.c | 17 +++++++---------- citadel/utils/ctdlload.c | 23 +++++++++-------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/citadel/utils/ctdldump.c b/citadel/utils/ctdldump.c index a7a83b448..97ff71291 100644 --- a/citadel/utils/ctdldump.c +++ b/citadel/utils/ctdldump.c @@ -355,8 +355,8 @@ void export_table(int which_cdb) { int main(int argc, char **argv) { int i = 0; - char src_dir[PATH_MAX]; int confirmed = 0; + char *ctdldir = CTDLDIR; // display the greeting fprintf(stderr, "\033[44m\033[33m\033[1m \033[K\033[0m\n" @@ -366,15 +366,12 @@ int main(int argc, char **argv) { "\033[44m\033[33m\033[1m is subject to the terms of the GNU General Public license v3. \033[K\033[0m\n" "\033[44m\033[33m\033[1m \033[K\033[0m\n"); - // Default source directory unless overridden - snprintf(src_dir, sizeof(src_dir), "%s/data", CTDLDIR); - // Parse command line int a; while ((a = getopt(argc, argv, "h:y")) != EOF) { switch (a) { case 'h': - snprintf(src_dir, sizeof(src_dir), "%s/data", optarg); + ctdldir = optarg; break; case 'y': confirmed = 1; @@ -385,11 +382,6 @@ int main(int argc, char **argv) { } } - if (src_dir == NULL) { - fprintf(stderr, "ctdldump: no source directory was specified.\n"); - exit(1); - } - if (confirmed == 1) { fprintf(stderr, "ctdldump: You have specified the [-y] flag, so processing will continue.\n"); } @@ -400,6 +392,11 @@ int main(int argc, char **argv) { exit(1); } + if (chdir(ctdldir) != 0) { + fprintf(stderr, "ctdlload: unable to change directory to [%s]: %m", ctdldir); + exit(2); + } + // backend modules use syslog -- redirect to stderr openlog("ctdldump", LOG_PERROR , LOG_DAEMON); diff --git a/citadel/utils/ctdlload.c b/citadel/utils/ctdlload.c index 45e68536e..258c47f9c 100644 --- a/citadel/utils/ctdlload.c +++ b/citadel/utils/ctdlload.c @@ -722,8 +722,8 @@ void ingest(void) { // Main entry point int main(int argc, char **argv) { - char dst_dir[PATH_MAX]; int confirmed = 0; + char *ctdldir = CTDLDIR; // display the greeting fprintf(stderr, "\033[44m\033[33m\033[1m \033[K\033[0m\n" @@ -733,30 +733,22 @@ int main(int argc, char **argv) { "\033[44m\033[33m\033[1m is subject to the terms of the GNU General Public license v3. \033[K\033[0m\n" "\033[44m\033[33m\033[1m \033[K\033[0m\n"); - // Default destination directory unless overridden - snprintf(dst_dir, sizeof(dst_dir), "%s/data", CTDLDIR); - // Parse command line int a; while ((a = getopt(argc, argv, "h:y")) != EOF) { switch (a) { case 'h': - snprintf(dst_dir, sizeof(dst_dir), "%s/data", optarg); + ctdldir = optarg; break; case 'y': confirmed = 1; break; default: - fprintf(stderr, "%s: usage: %s -h dest_dir [