summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2019-04-30 21:32:30 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2019-04-30 22:35:40 +0200
commit4fed39d9271ceb68be4157ab3f96a45b94f77dc0 (patch)
treee63c4a6e8a99f9c219565e5895c0fef3bf999daa /kconfiglib.py
parent9fe13c03de16c341cd7ed40167216207b821ea50 (diff)
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.
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py37
1 files 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 <filename> already exists, a copy of it will be saved to
- .<filename>.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.
+ <filename>.old in the same directory before the new configuration is
+ written.
- Errors are silently ignored if .<filename>.old cannot be written
- (e.g. due to being a directory).
+ Errors are silently ignored if <filename>.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 .<filename>.old if it already exists on POSIX
+ # Will remove <filename>.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 .<filename>.old happens to be a directory.
+ # <filename>.old file is usually more of a nice-to-have, and not worth
+ # erroring out over e.g. if <filename>.old happens to be a directory.
pass