1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-27 15:06:15 +01:00

conf: Preserve oscrc symlink

When a user creates a symlink pointing from ~/.config/osc/oscrc
to a different location, don't overwrite the symlink but follow
it when writing configuration on disk.
This commit is contained in:
Daniel Mach 2021-12-06 14:23:51 +01:00
parent 2e80671523
commit 5ba6bbe0c2

View File

@ -695,8 +695,20 @@ def write_config(fname, cp):
if os.path.exists(fname) and not os.path.isfile(fname):
# only write to a regular file
return
# config file is behind a symlink
# resolve the symlink and continue writing the config as usual
if os.path.islink(fname):
fname = os.readlink(fname)
# create directories to the config file (if they don't exist already)
if not os.path.exists(os.path.dirname(fname)):
os.makedirs(os.path.dirname(fname), mode=0o700)
try:
os.makedirs(os.path.dirname(fname), mode=0o700)
except OSError as e:
if e.errno != errno.EEXIST:
raise
with open(fname + '.new', 'w') as f:
cp.write(f, comments=True)
try: