Skip to content

Commit

Permalink
Config: do not overwrite when loaded and not migrated (#4605)
Browse files Browse the repository at this point in the history
The `Config.from_file` classmethod used to load the `config.json` file
into memory was always writing the contents from memory to disk if it
was read, even if the content was not migrated. This is unnecessary and
so the write is now only performed if the config was migrated.
  • Loading branch information
sphuber authored Dec 2, 2020
1 parent f945dca commit 6d8ec0b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion aiida/manage/configuration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ def from_file(cls, filepath):
config = Config(filepath, check_and_migrate_config({}))
config.store()
else:
migrated = False

# If the configuration file needs to be migrated first create a specific backup so it can easily be reverted
if config_needs_migrating(config):
migrated = True
echo.echo_warning(f'current configuration file `{filepath}` is outdated and will be migrated')
filepath_backup = cls._backup(filepath)
echo.echo_warning(f'original backed up to `{filepath_backup}`')

config = Config(filepath, check_and_migrate_config(config))
config.store()

if migrated:
config.store()

return config

Expand Down

0 comments on commit 6d8ec0b

Please sign in to comment.