mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-09 12:35:48 +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:
commit
c45373faaa
12
osc/conf.py
12
osc/conf.py
@ -695,8 +695,20 @@ def write_config(fname, cp):
|
|||||||
if os.path.exists(fname) and not os.path.isfile(fname):
|
if os.path.exists(fname) and not os.path.isfile(fname):
|
||||||
# only write to a regular file
|
# only write to a regular file
|
||||||
return
|
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)):
|
if not os.path.exists(os.path.dirname(fname)):
|
||||||
|
try:
|
||||||
os.makedirs(os.path.dirname(fname), mode=0o700)
|
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:
|
with open(fname + '.new', 'w') as f:
|
||||||
cp.write(f, comments=True)
|
cp.write(f, comments=True)
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user