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 v2] emirrordist: Clean dangling symlinks up
Date: Mon, 21 Oct 2019 08:03:00
Message-Id: 20191021080232.167049-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 | 11 ++++++++---
5 1 file changed, 8 insertions(+), 3 deletions(-)
6
7 diff --git a/lib/portage/_emirrordist/DeletionIterator.py b/lib/portage/_emirrordist/DeletionIterator.py
8 index dab6eaea2..5c193911a 100644
9 --- a/lib/portage/_emirrordist/DeletionIterator.py
10 +++ b/lib/portage/_emirrordist/DeletionIterator.py
11 @@ -27,11 +27,16 @@ 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 --
32 2.23.0

Replies