Commit 0ff9b24a authored by Łukasz Magiera's avatar Łukasz Magiera

config-patch: backup config

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 2514c747
......@@ -372,6 +372,11 @@ func transformConfig(configRoot string, transformer config.Transformer) error {
return err
}
_, err = r.BackupConfig("profile-")
if err != nil {
return err
}
return r.SetConfig(cfg)
}
......
......@@ -480,6 +480,32 @@ func (r *FSRepo) FileManager() *filestore.FileManager {
return r.filemgr
}
func (r *FSRepo) BackupConfig(prefix string) (string, error) {
temp, err := ioutil.TempFile(r.path, "config-"+prefix)
if err != nil {
return "", err
}
defer temp.Close()
configFilename, err := config.Filename(r.path)
if err != nil {
return "", err
}
orig, err := os.OpenFile(configFilename, os.O_RDONLY, 0600)
if err != nil {
return "", err
}
defer orig.Close()
_, err = io.Copy(temp, orig)
if err != nil {
return "", err
}
return orig.Name(), nil
}
// setConfigUnsynced is for private use.
func (r *FSRepo) setConfigUnsynced(updated *config.Config) error {
configFilename, err := config.Filename(r.path)
......
......@@ -28,6 +28,10 @@ func (m *Mock) SetConfig(updated *config.Config) error {
return nil
}
func (m *Mock) BackupConfig(prefix string) (string, error) {
return "", errTODO
}
func (m *Mock) SetConfigKey(key string, value interface{}) error {
return errTODO
}
......
......@@ -18,6 +18,7 @@ var (
type Repo interface {
Config() (*config.Config, error)
BackupConfig(prefix string) (string, error)
SetConfig(*config.Config) error
SetConfigKey(key string, value interface{}) error
......
......@@ -183,10 +183,18 @@ test_config_cmd() {
test $(cat actual_config | wc -l) = 1
'
test_expect_success "copy ipfs config" '
cp "$IPFS_PATH/config" before_patch
'
test_expect_success "'ipfs config profile apply server' works" '
ipfs config profile apply server
'
test_expect_success "backup was created and looks good" '
test_cmp "$(find "$IPFS_PATH" -name "config-profile*")" before_patch
'
test_expect_success "'ipfs config Swarm.AddrFilters' looks good with server profile" '
ipfs config Swarm.AddrFilters > actual_config &&
test $(cat actual_config | wc -l) = 17
......@@ -209,6 +217,10 @@ test_config_cmd() {
# won't work as it changes datastore definition, which makes ipfs not launch
# without converting first
# test_profile_apply_revert badgerds
test_expect_success "cleanup config backups" '
find "$IPFS_PATH" -name "config-profile*" -exec rm {} \;
'
}
test_init_ipfs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment