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