Open file for reading, and then for writing to prevent dangling data at the end if updated data is shorter than existing data.

pull/3554/head
derekpierre 2024-08-12 16:33:41 -04:00
parent 321ffd4a98
commit c5b2204e84
No known key found for this signature in database
1 changed files with 6 additions and 4 deletions

View File

@ -404,14 +404,16 @@ def recover(config_file):
)
click.Abort()
with open(ursula_config_file, "r+") as f:
with open(ursula_config_file, "r") as f:
ursula_config = json.load(f)
ursula_config["keystore_path"] = str(new_keystore_path.absolute())
f.seek(0)
ursula_config["keystore_path"] = str(new_keystore_path.absolute())
with open(ursula_config_file, "w") as f:
json.dump(ursula_config, f, indent=2)
emitter.echo(
f"Updated ursula.json to use keystore filepath: {new_keystore_path.absolute()}"
f"Updated Ursula configuration, {ursula_config_file.absolute()}, to use keystore filepath: {new_keystore_path.absolute()}"
)