From b1dd0d3193c3b4a2cad8e8c22047bfc17bb1d5e3 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Thu, 3 Dec 2015 11:59:49 +0100 Subject: [PATCH 3/3] Fix destination name in libarchive if the member name starts with a / --- diffoscope/comparators/libarchive.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/diffoscope/comparators/libarchive.py b/diffoscope/comparators/libarchive.py index f8d5b4f..ee004b3 100644 --- a/diffoscope/comparators/libarchive.py +++ b/diffoscope/comparators/libarchive.py @@ -21,6 +21,7 @@ from contextlib import contextmanager import ctypes import os.path +import os import libarchive from diffoscope import logger from diffoscope.comparators.device import Device @@ -120,11 +121,15 @@ class LibarchiveContainer(Archive): return member_names def extract(self, member_name, dest_dir): - dest_path = os.path.join(dest_dir, os.path.basename(member_name)) + dest_path = '%s%s%s' % (dest_dir, os.sep, member_name) logger.debug('libarchive extracting %s to %s', member_name, dest_path) with libarchive.file_reader(self.source.path) as archive: for entry in archive: if entry.pathname == member_name: + try: + os.makedirs(os.path.dirname(dest_path)) + except FileExistsError: + pass logger.debug('entry found, writing %s', dest_path) with open(dest_path, 'wb') as f: for buf in entry.get_blocks(): -- 2.6.3