Update mtime of config file before upgrading (fixes #2509)
This updates the modified time of the config file before archiving it during an update so that the clean up routine doesn't delete it if it's too old, preventing the user from being able to rollback after an upgrade.
This commit is contained in:
@@ -922,16 +922,33 @@ func loadOrCreateConfig() *config.Wrapper {
|
||||
}
|
||||
|
||||
if cfg.Raw().OriginalVersion != config.CurrentVersion {
|
||||
// Archive previous version and save new one
|
||||
archivePath := cfg.ConfigPath() + fmt.Sprintf(".v%d", cfg.Raw().OriginalVersion)
|
||||
l.Infoln("Archiving a copy of old config file format at:", archivePath)
|
||||
osutil.Rename(cfg.ConfigPath(), archivePath)
|
||||
cfg.Save()
|
||||
err = archiveAndSaveConfig(cfg)
|
||||
if err != nil {
|
||||
l.Fatalln("Config archive:", err)
|
||||
}
|
||||
}
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func archiveAndSaveConfig(cfg *config.Wrapper) error {
|
||||
// To prevent previous config from being cleaned up, quickly touch it too
|
||||
now := time.Now()
|
||||
err := os.Chtimes(cfg.ConfigPath(), now, now)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
archivePath := cfg.ConfigPath() + fmt.Sprintf(".v%d", cfg.Raw().OriginalVersion)
|
||||
l.Infoln("Archiving a copy of old config file format at:", archivePath)
|
||||
err = osutil.Rename(cfg.ConfigPath(), archivePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cfg.Save()
|
||||
}
|
||||
|
||||
func startAuditing(mainService *suture.Supervisor) {
|
||||
auditFile := timestampedLoc(locAuditLog)
|
||||
fd, err := os.OpenFile(auditFile, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
|
||||
|
||||
Reference in New Issue
Block a user