[diffoscope] 02/02: comparators: utils: container: fixes OSError on container files

Juliana Oliveira R jwnx-guest at moszumanska.debian.org
Sun Sep 10 06:29:29 CEST 2017


This is an automated email from the git hooks/post-receive script.

jwnx-guest pushed a commit to branch jwnx_fix_different_container_type_comparison
in repository diffoscope.

commit 01b34fb3a2efe2c41ed05fd3bb98d1899c756bd0
Author: Juliana Oliveira Rodrigues <juliana.orod at gmail.com>
Date:   Sun Sep 10 00:42:29 2017 -0300

    comparators: utils: container: fixes OSError on container files
    
    The destination path for container extraction was generated by joining
    directory's name and filenames recursively. When those names are too long
    or recursion depth is too high, destination path may exceed OS's max
    filename length.
    
    This patch adds a new method for Container class called get_dest_path,
    which returns a joint between destination directory and an uuid hash.
    It sets filename length to 36 characters.
---
 diffoscope/comparators/gzip.py            | 3 +--
 diffoscope/comparators/utils/container.py | 5 +++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/diffoscope/comparators/gzip.py b/diffoscope/comparators/gzip.py
index 70cbc02..6dd1d0b 100644
--- a/diffoscope/comparators/gzip.py
+++ b/diffoscope/comparators/gzip.py
@@ -18,7 +18,6 @@
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
 import re
-import os.path
 import logging
 import subprocess
 
@@ -44,7 +43,7 @@ class GzipContainer(Archive):
 
     @tool_required('gzip')
     def extract(self, member_name, dest_dir):
-        dest_path = os.path.join(dest_dir, member_name)
+        dest_path = self.get_path_name(dest_dir)
         logger.debug('gzip extracting to %s', dest_path)
         with open(dest_path, 'wb') as fp:
             subprocess.check_call(
diff --git a/diffoscope/comparators/utils/container.py b/diffoscope/comparators/utils/container.py
index 5627f5b..36ba8cc 100644
--- a/diffoscope/comparators/utils/container.py
+++ b/diffoscope/comparators/utils/container.py
@@ -18,6 +18,8 @@
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
 import abc
+import uuid
+import os.path
 import logging
 import itertools
 from collections import OrderedDict
@@ -66,6 +68,9 @@ class Container(object, metaclass=abc.ABCMeta):
     def get_member(self, member_name):
         raise NotImplementedError()
 
+    def get_path_name(self, dest_dir):
+      return os.path.join(dest_dir, uuid.uuid4())
+
     def get_filtered_members(self):
         # If your get_member implementation is O(n) then this will be O(n^2)
         # cost. In such cases it is HIGHLY RECOMMENDED to override this as well

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list