From 7bc4c63eb413488ce3d565ea9cb8decfa7e104a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Nov 2023 11:28:08 +0800 Subject: [PATCH] Migration: don't overwrite existing files --- README.md | 3 ++- src/fastfetch.c | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2f387b60e..a5e243cd9 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,8 @@ See Wiki: https://github.com/fastfetch-cli/fastfetch/wiki/Building * Run it with default configuration: `fastfetch` * Run it with [all supported modules](https://github.com/fastfetch-cli/fastfetch/wiki/Support+Status#available-modules) and find what you interest: `fastfetch -c all.jsonc` * Find all data that fastfetch detects: `fastfetch -s --format json` -* Get help messages: `fastfetch --help` +* Display help messages: `fastfetch --help` +* Generate config file based on command line arguments: `fastfetch --arg1 --arg2 --mirgrate-config` ## Customization diff --git a/src/fastfetch.c b/src/fastfetch.c index c815b5569..61237ff60 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -481,7 +481,7 @@ static void parseOption(FFdata* data, const char* key, const char* value) { if (instance.state.configDoc) { - fputs("Error: existing jsonc config file detected. Aborting\n", stderr); + fputs("Error: existing jsonc config detected. Aborting\n", stderr); exit(477); } @@ -492,6 +492,12 @@ static void parseOption(FFdata* data, const char* key, const char* value) } else ffStrbufSetS(&instance.state.migrateConfigPath, value); + + if (ffPathExists(instance.state.migrateConfigPath.chars, FF_PATHTYPE_ANY)) + { + fprintf(stderr, "Error: file `%s` exists. Aborting\n", instance.state.migrateConfigPath.chars); + exit(477); + } } else if(ffStrEqualsIgnCase(key, "--load-user-config")) data->loadUserConfig = ffOptionParseBoolean(value);