From 19175b10f73366ba6e4ee2bb567c900e4650886a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 9 Sep 2024 17:44:19 +0200 Subject: [PATCH] Migrate legacy files (setupVars.conf, pihole-FTL.conf and custom.list) into /etc/pihole/migration_backup_v6 instead of leaving them inside /etc/pihole Signed-off-by: DL6ER --- src/config/config.c | 2 +- src/config/dnsmasq_config.c | 2 +- src/config/dnsmasq_config.h | 1 + src/config/setupVars.c | 18 +++++------------- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/config/config.c b/src/config/config.c index 861ac4a98..5fe183d06 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -1627,7 +1627,7 @@ bool readFTLconf(struct config *conf, const bool rewrite) const char *path = ""; if((path = readFTLlegacy(conf)) != NULL) { - const char *target = "/etc/pihole/pihole-FTL.conf.bck"; + const char *target = "/etc/pihole/migration_backup_v6/pihole-FTL.conf"; log_info("Moving %s to %s", path, target); if(rename(path, target) != 0) log_warn("Unable to move %s to %s: %s", path, target, strerror(errno)); diff --git a/src/config/dnsmasq_config.c b/src/config/dnsmasq_config.c index abf076ca2..e4c305ec1 100644 --- a/src/config/dnsmasq_config.c +++ b/src/config/dnsmasq_config.c @@ -917,7 +917,7 @@ bool read_legacy_custom_hosts_config(void) { // Check if file exists, if not, there is nothing to do const char *path = DNSMASQ_CUSTOM_LIST_LEGACY; - const char *target = DNSMASQ_CUSTOM_LIST_LEGACY".bck"; + const char *target = DNSMASQ_CUSTOM_LIST_LEGACY_TARGET; if(!file_exists(path)) return true; diff --git a/src/config/dnsmasq_config.h b/src/config/dnsmasq_config.h index 4a9d9fada..2b40042a3 100644 --- a/src/config/dnsmasq_config.h +++ b/src/config/dnsmasq_config.h @@ -29,6 +29,7 @@ bool write_custom_list(void); #define DNSMASQ_HOSTSDIR "/etc/pihole/hosts" #define DNSMASQ_CUSTOM_LIST DNSMASQ_HOSTSDIR"/custom.list" #define DNSMASQ_CUSTOM_LIST_LEGACY "/etc/pihole/custom.list" +#define DNSMASQ_CUSTOM_LIST_LEGACY_TARGET "/etc/pihole/migration_backup_v6/custom.list" #define DHCPLEASESFILE "/etc/pihole/dhcp.leases" #endif //DNSMASQ_CONFIG_H diff --git a/src/config/setupVars.c b/src/config/setupVars.c index 2d8bd48df..cd5df0ea8 100644 --- a/src/config/setupVars.c +++ b/src/config/setupVars.c @@ -591,20 +591,12 @@ void importsetupVarsConf(void) // Ports may be temporarily stored when importing a legacy Teleporter v5 file get_conf_string_from_setupVars("WEB_PORTS", &config.webserver.port); - // Move the setupVars.conf file to setupVars.conf.old - char *old_setupVars = calloc(strlen(config.files.setupVars.v.s) + 5, sizeof(char)); - if(old_setupVars == NULL) - { - log_warn("Could not allocate memory for old_setupVars"); - return; - } - strcpy(old_setupVars, config.files.setupVars.v.s); - strcat(old_setupVars, ".old"); - if(rename(config.files.setupVars.v.s, old_setupVars) != 0) - log_warn("Could not move %s to %s", config.files.setupVars.v.s, old_setupVars); + // Move the setupVars.conf file to the migration directory + const char *setupVars_target = "/etc/pihole/migration_backup_v6/setupVars.conf"; + if(rename(config.files.setupVars.v.s, setupVars_target) != 0) + log_warn("Could not move %s to %s", config.files.setupVars.v.s, setupVars_target); else - log_info("Moved %s to %s", config.files.setupVars.v.s, old_setupVars); - free(old_setupVars); + log_info("Moved %s to %s", config.files.setupVars.v.s, setupVars_target); log_info("Migration complete"); }