Control: tags -1 + patch

On 18-Oct-2015, Ben Finney wrote:
> I have experienced the same error. A deliberately-created symlink
> causes ‘dh_python3’ to crash when it attempts to ‘os.rmdir’ the
> symlink

Here is a patch series to use a helper function that removes the entry
whatever its type.

-- 
 \      “I don't know half of you half as well as I should like, and I |
  `\   like less than half of you half as well as you deserve.” —Bilbo |
_o__)                                                          Baggins |
Ben Finney <b...@benfinney.id.au>
From 5ac8dabbedc305553151b97bc5b7d60a43b02a64 Mon Sep 17 00:00:00 2001
From: Ben Finney <b...@benfinney.id.au>
Date: Sun, 25 Oct 2015 15:10:14 +1100
Subject: [PATCH 1/2] Add helper function to remove a filesystem entry of any
 type.

---
 dhpython/fs.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/dhpython/fs.py b/dhpython/fs.py
index e0be654..05b8e8b 100644
--- a/dhpython/fs.py
+++ b/dhpython/fs.py
@@ -25,6 +25,8 @@ from filecmp import cmp as cmpfile
 from os.path import exists, dirname, isdir, islink, join, split, splitext
 from shutil import rmtree
 from stat import ST_MODE, S_IXUSR, S_IXGRP, S_IXOTH
+import errno
+
 from dhpython import MULTIARCH_DIR_TPL
 from dhpython.tools import fix_shebang, clean_egg_name
 from dhpython.interpreter import Interpreter
@@ -32,6 +34,17 @@ from dhpython.interpreter import Interpreter
 log = logging.getLogger('dhpython')
 
 
+def remove_entry(path):
+    """ Remove specified filesystem entry, whatever its type. """
+    try:
+        os.remove(path)
+    except OSError as exc:
+        if exc.errno == errno.EISDIR:
+            os.rmdir(path)
+        else:
+            raise
+
+
 def fix_locations(package, interpreter, versions, options):
     """Move files to the right location."""
     # make a copy since we change version later
-- 
2.6.1

From 8052e56dcd776409254fd525d15a63525dab4434 Mon Sep 17 00:00:00 2001
From: Ben Finney <b...@benfinney.id.au>
Date: Sun, 25 Oct 2015 15:10:43 +1100
Subject: [PATCH 2/2] Remove filesystem entries allowing for different types.

---
 dhpython/fs.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/dhpython/fs.py b/dhpython/fs.py
index 05b8e8b..1d73d23 100644
--- a/dhpython/fs.py
+++ b/dhpython/fs.py
@@ -64,7 +64,7 @@ def fix_locations(package, interpreter, versions, options):
                     if exists(parent_dir):
                         if os.listdir(parent_dir):
                             break
-                        os.rmdir(parent_dir)
+                        remove_entry(parent_dir)
                     parent_dir = dirname(parent_dir)
 
         # do the same with debug locations
@@ -78,7 +78,7 @@ def fix_locations(package, interpreter, versions, options):
                     if exists(parent_dir):
                         if os.listdir(parent_dir):
                             break
-                        os.rmdir(parent_dir)
+                        remove_entry(parent_dir)
                     parent_dir = dirname(parent_dir)
 
 
@@ -115,7 +115,7 @@ def share_files(srcdir, dstdir, interpreter, options):
         # XXX: check symlinks
 
     if exists(srcdir) and not os.listdir(srcdir):
-        os.rmdir(srcdir)
+        remove_entry(srcdir)
 
 
 class Scan:
@@ -239,7 +239,7 @@ class Scan:
                 # try to remove directory if it's empty (and its parent if it's empty afterwards)
                 while root:
                     try:
-                        os.rmdir(root)
+                        remove_entry(root)
                         log.debug('removing empty directory: %s', root)
                     except Exception:
                         break
@@ -414,6 +414,6 @@ class Scan:
             for root, dirs, file_names in os.walk(proot, topdown=False):
                 if '-packages/' in root and not file_names:
                     try:
-                        os.rmdir(root)
+                        remove_entry(root)
                     except Exception:
                         pass
-- 
2.6.1

Attachment: signature.asc
Description: PGP signature

Reply via email to