diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-12-08 04:47:52 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-12-08 04:54:47 +0100 |
| commit | 78073d6674ce3250334d0f5177c9f8010e8d381c (patch) | |
| tree | 918f7a9e0db6c5d69eafbb8b07ffff2c3d55bf18 | |
| parent | 3cc2f9f32b61ed27c533b60a8544ac32de0d969d (diff) | |
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.
| -rw-r--r-- | kconfiglib.py | 6 |
1 files 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 .<filename>.old if it already exists on POSIX # systems os.rename(path, backup) |
