1
0
mirror of https://github.com/gilbertchen/duplicacy synced 2025-12-06 00:03:38 +00:00

Remove existing config and save a local copy when changing password

This commit is contained in:
Gilbert Chen
2017-12-09 17:34:43 -05:00
parent 8bd463288f
commit c5e2032715

View File

@@ -592,11 +592,45 @@ func changePassword(context *cli.Context) {
iterations = duplicacy.CONFIG_DEFAULT_ITERATIONS
}
description, err := json.MarshalIndent(config, "", " ")
if err != nil {
duplicacy.LOG_ERROR("CONFIG_MARSHAL", "Failed to marshal the config: %v", err)
return
}
configPath := path.Join(duplicacy.GetDuplicacyPreferencePath(), "config")
err = ioutil.WriteFile(configPath, description, 0600)
if err != nil {
duplicacy.LOG_ERROR("CONFIG_SAVE", "Failed to save the old config to %s: %v", configPath, err)
return
}
duplicacy.LOG_INFO("CONFIG_SAVE", "The old config has been temporarily saved to %s", configPath)
removeLocalCopy := false
defer func() {
if removeLocalCopy {
err = os.Remove(configPath)
if err != nil {
duplicacy.LOG_WARN("CONFIG_CLEAN", "Failed to delete %s: %v", configPath, err)
} else {
duplicacy.LOG_INFO("CONFIG_CLEAN", "The local copy of the old config has been removed")
}
}
} ()
err = storage.DeleteFile(0, "config")
if err != nil {
duplicacy.LOG_ERROR("CONFIG_DELETE", "Failed to delete the old config from the storage: %v", err)
return
}
duplicacy.UploadConfig(storage, config, newPassword, iterations)
duplicacy.SavePassword(*preference, "password", newPassword)
duplicacy.LOG_INFO("STORAGE_SET", "The password for storage %s has been changed", preference.StorageURL)
removeLocalCopy = true
}
func backupRepository(context *cli.Context) {