From 78073d6674ce3250334d0f5177c9f8010e8d381c Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 8 Dec 2018 04:47:52 +0100 Subject: Preserve symlinks when writing .config.old files if .config is a symlink, then the intention is probably to overwrite the target, but rename()ing the symlink to .config.old interferes with that. Use the shutil.copyfile() fallback instead if .config is a symlink. --- kconfiglib.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index a376d62..551bca9 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -5870,9 +5870,11 @@ def _save_old(path): basename = "." + basename + ".old" backup = os.path.join(dirname, basename) + # os.replace() would be nice here, but it's Python 3 (3.3+) only try: - # os.replace() would be nice here, but it's Python 3 (3.3+) only - if os.name == "posix": + # Use copyfile() if 'path' is a symlink. The intention is probably to + # overwrite the target in that case. + if os.name == "posix" and not os.path.islink(path): # Will remove ..old if it already exists on POSIX # systems os.rename(path, backup) -- cgit v1.2.3