Skip to content

Commit 4fed39d

Browse files
committed
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 automate-lfs/jhalfs@a645174. 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.
1 parent 9fe13c0 commit 4fed39d

1 file changed

Lines changed: 15 additions & 22 deletions

File tree

kconfiglib.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,7 @@ def my_other_fn(kconf, name, arg_1, arg_2, ...):
529529

530530
# Get rid of some attribute lookups. These are obvious in context.
531531
from glob import iglob
532-
from os.path import dirname, exists, expandvars, isabs, islink, join, \
533-
relpath, split
532+
from os.path import dirname, exists, expandvars, isabs, islink, join, relpath
534533

535534

536535
# File layout:
@@ -1358,12 +1357,11 @@ def write_config(self, filename=None,
13581357
13591358
save_old (default: True):
13601359
If True and <filename> already exists, a copy of it will be saved to
1361-
.<filename>.old in the same directory before the new configuration is
1362-
written. The leading dot is added only if the filename doesn't
1363-
already start with a dot.
1360+
<filename>.old in the same directory before the new configuration is
1361+
written.
13641362
1365-
Errors are silently ignored if .<filename>.old cannot be written
1366-
(e.g. due to being a directory).
1363+
Errors are silently ignored if <filename>.old cannot be written (e.g.
1364+
due to being a directory).
13671365
13681366
verbose (default: True):
13691367
If True and filename is None (automatically infer configuration
@@ -5886,29 +5884,24 @@ def _touch_dep_file(path, sym_name):
58865884

58875885

58885886
def _save_old(path):
5889-
# See write_config()
5887+
# See write_config(). os.replace() would be nice here, but it's Python 3
5888+
# (3.3+) only.
58905889

5891-
dirname, basename = split(path)
5892-
backup = join(dirname,
5893-
basename + ".old" if basename.startswith(".")
5894-
else "." + basename + ".old")
5895-
5896-
# os.replace() would be nice here, but it's Python 3 (3.3+) only
58975890
try:
5898-
# Use copyfile() if 'path' is a symlink. The intention is probably to
5899-
# overwrite the target in that case.
59005891
if os.name == "posix" and not islink(path):
5901-
# Will remove .<filename>.old if it already exists on POSIX
5892+
# Will remove <filename>.old if it already exists on POSIX
59025893
# systems
5903-
os.rename(path, backup)
5894+
os.rename(path, path + ".old")
59045895
else:
5905-
# Only import as needed, to save some startup time
5896+
# Use copyfile() if 'path' is a symlink. The intention is probably
5897+
# to overwrite the target in that case. Only import shutil as
5898+
# needed, to save some startup time.
59065899
import shutil
5907-
shutil.copyfile(path, backup)
5900+
shutil.copyfile(path, path + ".old")
59085901
except:
59095902
# Ignore errors from 'filename' missing as well as other errors. The
5910-
# backup file is more of a nice-to-have, and not worth erroring out
5911-
# over e.g. if .<filename>.old happens to be a directory.
5903+
# <filename>.old file is usually more of a nice-to-have, and not worth
5904+
# erroring out over e.g. if <filename>.old happens to be a directory.
59125905
pass
59135906

59145907

0 commit comments

Comments
 (0)