1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-09 22:36:14 +01:00

Merge branch 'oscrc-symlink' of https://github.com/dmach/osc

If the oscrc is a symlink, follow the symlink when writing the
configuration file. The old code replaced the symlink with a
regular file (see #390 ("symlinked $HOME/.oscrc gets replaced
with a ordinary file")).

Implementation note: if the directory, which contains the resolved
config file, has a <config file>.new file, the file is overwritten.
This commit is contained in:
Marcus Huewe 2021-12-08 10:20:59 +01:00
commit c45373faaa

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: