Avoiding writing ninjalog.cfg unnecessarily

Writing to ninjalog.cfg comes with the risk of failure (Ctrl+C at the
wrong time) which can lead to an empty or corrupted file. This will
cause errors on subsequent builds when loading the config file, and
will lose the users opt-in/out settings.

This change ensures that the config file is only written when something
has changed, thus essentially avoiding the risk.

Bug: 941810
Change-Id: If266f07536569c9ac91ee37c28797c8b2ccc6fdc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1522291
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
Reviewed-by: Fumitoshi Ukai <ukai@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
changes/91/1522291/2
Bruce Dawson 6 years ago committed by Commit Bot
parent 8e85c22df6
commit cf9613f166

@ -86,8 +86,6 @@ def main():
print('ninjalog upload is opted out.')
return 0
SaveConfig(config)
if 'opt-in' in config and not config['opt-in']:
# Upload is opted out.
return 0
@ -99,6 +97,8 @@ def main():
if config.get("countdown", 0) > 0:
# Need to show message.
ShowMessage(config["countdown"])
# Only save config if something has meaningfully changed.
SaveConfig(config)
return 0
if len(sys.argv) == 1:

Loading…
Cancel
Save