From 4fed39d9271ceb68be4157ab3f96a45b94f77dc0 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Tue, 30 Apr 2019 21:32:30 +0200 Subject: Never prepend '.' to $KCONFIG_CONFIG.old In retrospect, trying to be "helpful" by saving the old version of a $KCONFIG_CONFIG that does not start with a '.' as e.g. '.config.old' instead of 'config.old' is a bad idea, because it means that scripts can't rely on the backup file simply being called $KCONFIG_CONFIG.old. I spotted this causing compatibility issues in https://github.com/automate-lfs/jhalfs/commit/a645174fd43ba4eee84089965df85785878e7aa6. I had Vim backup files and the like in mind originally, but .config.old is much more likely to be processed by scripts. This is a small backwards compatibility break, so the major version will be increased to 11. --- kconfiglib.py | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index e490c87..09efe4f 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -529,8 +529,7 @@ import sys # Get rid of some attribute lookups. These are obvious in context. from glob import iglob -from os.path import dirname, exists, expandvars, isabs, islink, join, \ - relpath, split +from os.path import dirname, exists, expandvars, isabs, islink, join, relpath # File layout: @@ -1358,12 +1357,11 @@ class Kconfig(object): save_old (default: True): If True and already exists, a copy of it will be saved to - ..old in the same directory before the new configuration is - written. The leading dot is added only if the filename doesn't - already start with a dot. + .old in the same directory before the new configuration is + written. - Errors are silently ignored if ..old cannot be written - (e.g. due to being a directory). + Errors are silently ignored if .old cannot be written (e.g. + due to being a directory). verbose (default: True): If True and filename is None (automatically infer configuration @@ -5886,29 +5884,24 @@ def _touch_dep_file(path, sym_name): def _save_old(path): - # See write_config() + # See write_config(). os.replace() would be nice here, but it's Python 3 + # (3.3+) only. - dirname, basename = split(path) - backup = join(dirname, - basename + ".old" if basename.startswith(".") - else "." + basename + ".old") - - # os.replace() would be nice here, but it's Python 3 (3.3+) only try: - # Use copyfile() if 'path' is a symlink. The intention is probably to - # overwrite the target in that case. if os.name == "posix" and not islink(path): - # Will remove ..old if it already exists on POSIX + # Will remove .old if it already exists on POSIX # systems - os.rename(path, backup) + os.rename(path, path + ".old") else: - # Only import as needed, to save some startup time + # Use copyfile() if 'path' is a symlink. The intention is probably + # to overwrite the target in that case. Only import shutil as + # needed, to save some startup time. import shutil - shutil.copyfile(path, backup) + shutil.copyfile(path, path + ".old") except: # Ignore errors from 'filename' missing as well as other errors. The - # backup file is more of a nice-to-have, and not worth erroring out - # over e.g. if ..old happens to be a directory. + # .old file is usually more of a nice-to-have, and not worth + # erroring out over e.g. if .old happens to be a directory. pass -- cgit v1.2.3