Skip to content

Commit

Permalink
Merge pull request #2055 from pi-hole/tweak/migration_targets
Browse files Browse the repository at this point in the history
Migrate legacy files into /etc/pihole/migration_backup_v6
  • Loading branch information
DL6ER authored Sep 9, 2024
2 parents a2dbfed + 19175b1 commit 0e0f3b5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/config/dnsmasq_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/config/dnsmasq_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 5 additions & 13 deletions src/config/setupVars.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 0e0f3b5

Please sign in to comment.