From 0ae7b3ae53b69a29a430667364eedb1d001cf2bd Mon Sep 17 00:00:00 2001 From: Benjamin Winger Date: Tue, 4 Aug 2020 15:09:19 -0400 Subject: [PATCH 1/3] Fall back to guess_mime_mimedb if file command fails in guess_mime_file --- patoolib/util.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/patoolib/util.py b/patoolib/util.py index e0976bd..db1abca 100644 --- a/patoolib/util.py +++ b/patoolib/util.py @@ -294,16 +294,15 @@ def guess_mime_file (filename): cmd = [file_prog, "--brief", "--mime", "--uncompress", filename] try: outparts = backtick(cmd).strip().split(";") + mime2 = outparts[0].split(" ", 1)[0] except OSError: - # ignore errors, as file(1) is only a fallback - return mime, encoding - mime2 = outparts[0].split(" ", 1)[0] + mime2 = None # Some file(1) implementations return an empty or unknown mime type # when the uncompressor program is not installed, other # implementation return the original file type. # The following detects both cases. if (mime2 in ('application/x-empty', 'application/octet-stream') or - mime2 in Mime2Encoding): + mime2 in Mime2Encoding or not mime2): # The uncompressor program file(1) uses is not installed # or is not able to uncompress. # Try to get mime information from the file extension. From b576de0ef9bac2706b2585c094b9be82851ed182 Mon Sep 17 00:00:00 2001 From: Benjamin Winger Date: Mon, 25 Jan 2021 09:25:43 -0500 Subject: [PATCH 2/3] Fixed patoolib.util:stripext handling of compressed tar files --- patoolib/util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/patoolib/util.py b/patoolib/util.py index db1abca..3beac5f 100644 --- a/patoolib/util.py +++ b/patoolib/util.py @@ -493,7 +493,10 @@ def shell_quote_nt (value): def stripext (filename): """Return the basename without extension of given filename.""" - return os.path.splitext(os.path.basename(filename))[0] + basename, _ = os.path.splitext(os.path.basename(filename)) + if basename.endswith(".tar"): + basename, _ = os.path.splitext(basename) + return basename def get_single_outfile (directory, archive, extension=""): From b1b44849d7b78e09f14b9ec75f62348c1ef74d50 Mon Sep 17 00:00:00 2001 From: Benjamin Winger Date: Mon, 25 Jan 2021 11:35:21 -0500 Subject: [PATCH 3/3] Added test for stripext --- tests/test_util.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_util.py b/tests/test_util.py index 94a836e..ea68b77 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -37,3 +37,10 @@ class UtilTest (unittest.TestCase): filename2 = os.path.join(parentdir, '.') self.assertFalse(util.is_same_file(filename1, filename2)) self.assertFalse(util.is_same_filename(filename1, filename2)) + + def test_stripext(self): + self.assertTrue(util.stripext("bar.gz") == "bar") + self.assertTrue(util.stripext("foo/bar.tar.gz") == "bar") + self.assertTrue(util.stripext("foo/bartar.gz") == "bartar") + self.assertTrue(util.stripext("foo/bar.7z") == "bar") + self.assertTrue(util.stripext("foo/bar") == "bar")