From a467cceb90334fde2405f2e6fdfd8d2296567598 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Mon, 25 Nov 2024 14:17:32 +0900 Subject: [PATCH] Add separate flag for generate-static overwrite Previous implementation allowed static files to overwrite existing files on generate if static-dir was specified and generate-enable-overwrite was specified. Now, an additional flag "--generate-static-enable-overwrite" determines if static-dir files overwrite on generate. --- src/arg_parse.c | 3 +++ src/arg_parse.h | 1 + src/main.c | 2 +- src/static.c | 4 ++-- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/arg_parse.c b/src/arg_parse.c index f56b2cc..2aeb9f4 100644 --- a/src/arg_parse.c +++ b/src/arg_parse.c @@ -46,6 +46,7 @@ void print_usage(void) { puts(" --enable-static-dir="); puts(" --generate-dir="); puts(" --generate-enable-overwrite"); + puts(" --generate-static-enable-overwrite"); } Args parse_args(int32_t argc, char **argv) { @@ -189,6 +190,8 @@ Args parse_args(int32_t argc, char **argv) { } } else if (strcmp(argv[0], "--generate-enable-overwrite") == 0) { args.flags |= 4; + } else if (strcmp(argv[0], "--generate-static-enable-overwrite") == 0) { + args.flags |= 8; } else { fprintf(stderr, "ERROR: Invalid args!\n"); print_usage(); diff --git a/src/arg_parse.h b/src/arg_parse.h index 1a4a510..59a03ee 100644 --- a/src/arg_parse.h +++ b/src/arg_parse.h @@ -29,6 +29,7 @@ typedef struct Args { // xxxx xx0x - disable listen on config file for reloading. // xxxx xx1x - enable listen on config file for reloading. // xxxx x1xx - enable overwrite on generate. + // xxxx 1xxx - enable overwrite on generate for static dir. uint16_t flags; uint16_t port; // Does not need to be free'd, this should point to a string in argv. diff --git a/src/main.c b/src/main.c index 601a5a0..b2b6338 100644 --- a/src/main.c +++ b/src/main.c @@ -363,7 +363,7 @@ int main(int argc, char **argv) { puts("Static dir option specified, copying over static dir entries..."); if (c_simple_http_static_copy_over_dir(args.static_dir, args.generate_dir, - (args.flags & 4) != 0 ? 1 : 0) + (args.flags & 8) != 0 ? 1 : 0) != 0) { fprintf(stderr, "ERROR during static-dir-entires copying!\n"); return 1; diff --git a/src/static.c b/src/static.c index c6d76b9..cfa07f3 100644 --- a/src/static.c +++ b/src/static.c @@ -421,8 +421,8 @@ int c_simple_http_static_copy_over_dir(const char *from, if (fd) { fprintf( stderr, - "WARNING \"%s\" already exists and --generate-enable-overwrite not " - "specified, skipping!\n", + "WARNING \"%s\" already exists and " + "--generate-static-enable-overwrite not specified, skipping!\n", combined_to); continue; }