Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] dispatch-conf: avoid symlink "File exists" error (535850)
Date: Sun, 11 Jan 2015 08:50:28
Message-Id: 1420966190-7007-1-git-send-email-zmedico@gentoo.org
1 Since commit f17448317166bfac42dc279b8795cd581c189582, an existing
2 symlink in /etc/config-archive could trigger a fatal "File exists"
3 error. Handle this by removing the destination file if it exists. This
4 was not necessary when dispatch-conf only supported regular files,
5 since shutil.copy2 would simply overwrite the regular destination file.
6
7 Fixes: f17448317166 ("dispatch-conf: symlink support for bug #485598")
8 X-Gentoo-Bug: 535850
9 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=535850
10 ---
11 pym/portage/dispatch_conf.py | 24 ++++++++++++++++++++++++
12 1 file changed, 24 insertions(+)
13
14 diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py
15 index b27e68b..7d55182 100644
16 --- a/pym/portage/dispatch_conf.py
17 +++ b/pym/portage/dispatch_conf.py
18 @@ -179,6 +179,12 @@ def rcs_archive(archive, curconf, newconf, mrgconf):
19 if curconf_st is not None and \
20 (stat.S_ISREG(curconf_st.st_mode) or
21 stat.S_ISLNK(curconf_st.st_mode)):
22 + # Remove destination file in order to ensure that the following
23 + # symlink or copy2 call won't fail (see bug #535850).
24 + try:
25 + os.unlink(archive)
26 + except OSError:
27 + pass
28 try:
29 if stat.S_ISLNK(curconf_st.st_mode):
30 os.symlink(os.readlink(curconf), archive)
31 @@ -208,6 +214,12 @@ def rcs_archive(archive, curconf, newconf, mrgconf):
32 if has_branch:
33 os.rename(archive, archive + '.dist')
34
35 + # Remove destination file in order to ensure that the following
36 + # symlink or copy2 call won't fail (see bug #535850).
37 + try:
38 + os.unlink(archive)
39 + except OSError:
40 + pass
41 try:
42 if stat.S_ISLNK(mystat.st_mode):
43 os.symlink(os.readlink(newconf), archive)
44 @@ -264,6 +276,12 @@ def file_archive(archive, curconf, newconf, mrgconf):
45 if curconf_st is not None and \
46 (stat.S_ISREG(curconf_st.st_mode) or
47 stat.S_ISLNK(curconf_st.st_mode)):
48 + # Remove destination file in order to ensure that the following
49 + # symlink or copy2 call won't fail (see bug #535850).
50 + try:
51 + os.unlink(archive)
52 + except OSError:
53 + pass
54 try:
55 if stat.S_ISLNK(curconf_st.st_mode):
56 os.symlink(os.readlink(curconf), archive)
57 @@ -285,6 +303,12 @@ def file_archive(archive, curconf, newconf, mrgconf):
58 stat.S_ISLNK(mystat.st_mode)):
59 # Save off new config file in the archive dir with .dist.new suffix
60 newconf_archive = archive + '.dist.new'
61 + # Remove destination file in order to ensure that the following
62 + # symlink or copy2 call won't fail (see bug #535850).
63 + try:
64 + os.unlink(newconf_archive)
65 + except OSError:
66 + pass
67 try:
68 if stat.S_ISLNK(mystat.st_mode):
69 os.symlink(os.readlink(newconf), newconf_archive)
70 --
71 2.0.5

Replies