[PATCH v2] emirrordist: Clean dangling symlinks up

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH v2] emirrordist: Clean dangling symlinks up

Michał Górny-5
Bug: https://bugs.gentoo.org/697906
Signed-off-by: Michał Górny <[hidden email]>
---
 lib/portage/_emirrordist/DeletionIterator.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/portage/_emirrordist/DeletionIterator.py b/lib/portage/_emirrordist/DeletionIterator.py
index dab6eaea2..5c193911a 100644
--- a/lib/portage/_emirrordist/DeletionIterator.py
+++ b/lib/portage/_emirrordist/DeletionIterator.py
@@ -27,11 +27,16 @@ class DeletionIterator(object):
  # require at least one successful stat()
  exceptions = []
  for layout in reversed(self._config.layouts):
+ path = os.path.join(distdir, layout.get_path(filename))
  try:
- st = os.stat(
- os.path.join(distdir, layout.get_path(filename)))
+ st = os.stat(path)
  except OSError as e:
- exceptions.append(e)
+ # is it a dangling symlink?
+ try:
+ if os.path.islink(path):
+ os.unlink(path)
+ except OSError as e:
+ exceptions.append(e)
  else:
  if stat.S_ISREG(st.st_mode):
  break
--
2.23.0


Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v2] emirrordist: Clean dangling symlinks up

Zac Medico-2
On 10/21/19 1:02 AM, Michał Górny wrote:

> Bug: https://bugs.gentoo.org/697906
> Signed-off-by: Michał Górny <[hidden email]>
> ---
>  lib/portage/_emirrordist/DeletionIterator.py | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/lib/portage/_emirrordist/DeletionIterator.py b/lib/portage/_emirrordist/DeletionIterator.py
> index dab6eaea2..5c193911a 100644
> --- a/lib/portage/_emirrordist/DeletionIterator.py
> +++ b/lib/portage/_emirrordist/DeletionIterator.py
> @@ -27,11 +27,16 @@ class DeletionIterator(object):
>   # require at least one successful stat()
>   exceptions = []
>   for layout in reversed(self._config.layouts):
> + path = os.path.join(distdir, layout.get_path(filename))
>   try:
> - st = os.stat(
> - os.path.join(distdir, layout.get_path(filename)))
> + st = os.stat(path)
>   except OSError as e:
> - exceptions.append(e)
> + # is it a dangling symlink?
> + try:
> + if os.path.islink(path):
> + os.unlink(path)
> + except OSError as e:
> + exceptions.append(e)
>   else:
>   if stat.S_ISREG(st.st_mode):
>   break
>
Looks good. Please merge.
--
Thanks,
Zac


signature.asc (1000 bytes) Download Attachment