1 |
On 10/20/19 3:23 AM, Michał Górny wrote: |
2 |
> Bug: https://bugs.gentoo.org/697906 |
3 |
> Signed-off-by: Michał Górny <mgorny@g.o> |
4 |
> --- |
5 |
> lib/portage/_emirrordist/DeletionIterator.py | 21 +++++++++++++++++--- |
6 |
> 1 file changed, 18 insertions(+), 3 deletions(-) |
7 |
> |
8 |
> diff --git a/lib/portage/_emirrordist/DeletionIterator.py b/lib/portage/_emirrordist/DeletionIterator.py |
9 |
> index dab6eaea2..6bc0fd09f 100644 |
10 |
> --- a/lib/portage/_emirrordist/DeletionIterator.py |
11 |
> +++ b/lib/portage/_emirrordist/DeletionIterator.py |
12 |
> @@ -27,16 +27,31 @@ class DeletionIterator(object): |
13 |
> # require at least one successful stat() |
14 |
> exceptions = [] |
15 |
> for layout in reversed(self._config.layouts): |
16 |
> + path = os.path.join(distdir, layout.get_path(filename)) |
17 |
> try: |
18 |
> - st = os.stat( |
19 |
> - os.path.join(distdir, layout.get_path(filename))) |
20 |
> + st = os.stat(path) |
21 |
> except OSError as e: |
22 |
> - exceptions.append(e) |
23 |
> + # is it a dangling symlink? |
24 |
> + try: |
25 |
> + if os.path.islink(path): |
26 |
> + os.unlink(path) |
27 |
> + except OSError as e: |
28 |
> + exceptions.append(e) |
29 |
> else: |
30 |
> if stat.S_ISREG(st.st_mode): |
31 |
> break |
32 |
|
33 |
How about if we remove the above break so that we can eliminate the |
34 |
lstat loop below? |
35 |
|
36 |
|
37 |
> else: |
38 |
> if exceptions: |
39 |
> + # check for dangling symlinks |
40 |
> + for layout in self._config.layouts: |
41 |
> + path = os.path.join(distdir, layout.get_path(filename)) |
42 |
> + try: |
43 |
> + st = os.lstat(path) |
44 |
> + if stat.S_ISLNK(st.st_mode): |
45 |
> + os.unlink(path) |
46 |
> + except OSError as e: |
47 |
> + pass |
48 |
> + |
49 |
> logging.error("stat failed on '%s' in distfiles: %s\n" % |
50 |
> (filename, '; '.join(str(x) for x in exceptions))) |
51 |
> continue |
52 |
> |
53 |
|
54 |
Looks good except that it would be nice to eliminate the second loop. |
55 |
-- |
56 |
Thanks, |
57 |
Zac |