Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH] emirrordist: Clean dangling symlinks up
Date: Sun, 20 Oct 2019 10:23:31
Message-Id: 20191020102304.393166-1-mgorny@gentoo.org
1 Bug: https://bugs.gentoo.org/697906
2 Signed-off-by: Michał Górny <mgorny@g.o>
3 ---
4 lib/portage/_emirrordist/DeletionIterator.py | 21 +++++++++++++++++---
5 1 file changed, 18 insertions(+), 3 deletions(-)
6
7 diff --git a/lib/portage/_emirrordist/DeletionIterator.py b/lib/portage/_emirrordist/DeletionIterator.py
8 index dab6eaea2..6bc0fd09f 100644
9 --- a/lib/portage/_emirrordist/DeletionIterator.py
10 +++ b/lib/portage/_emirrordist/DeletionIterator.py
11 @@ -27,16 +27,31 @@ class DeletionIterator(object):
12 # require at least one successful stat()
13 exceptions = []
14 for layout in reversed(self._config.layouts):
15 + path = os.path.join(distdir, layout.get_path(filename))
16 try:
17 - st = os.stat(
18 - os.path.join(distdir, layout.get_path(filename)))
19 + st = os.stat(path)
20 except OSError as e:
21 - exceptions.append(e)
22 + # is it a dangling symlink?
23 + try:
24 + if os.path.islink(path):
25 + os.unlink(path)
26 + except OSError as e:
27 + exceptions.append(e)
28 else:
29 if stat.S_ISREG(st.st_mode):
30 break
31 else:
32 if exceptions:
33 + # check for dangling symlinks
34 + for layout in self._config.layouts:
35 + path = os.path.join(distdir, layout.get_path(filename))
36 + try:
37 + st = os.lstat(path)
38 + if stat.S_ISLNK(st.st_mode):
39 + os.unlink(path)
40 + except OSError as e:
41 + pass
42 +
43 logging.error("stat failed on '%s' in distfiles: %s\n" %
44 (filename, '; '.join(str(x) for x in exceptions)))
45 continue
46 --
47 2.23.0

Replies