From 7fe32ae758f15f751f8062cdaff9ef5b7fac37d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 6 May 2021 12:37:01 +0200 Subject: [PATCH] util: Strip file:// from local urls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure that the function returns a path even for local files specified by file:// urls. JIRA: RHELCMP-5340 Signed-off-by: Lubomír Sedlář --- pungi/util.py | 2 ++ tests/test_util.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/pungi/util.py b/pungi/util.py index cf1ec8ee..c5717bde 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -1046,6 +1046,8 @@ def as_local_file(url): yield local_filename finally: os.remove(local_filename) + elif url.startswith("file://"): + yield url[7:] else: # Not a remote url, return unchanged. yield url diff --git a/tests/test_util.py b/tests/test_util.py index 29d85cfa..181c91d8 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1060,3 +1060,8 @@ class TestAsLocalFile(PungiTestCase): self.assertEqual(fn, self.filename) self.assertTrue(os.path.exists(self.filename)) self.assertFalse(os.path.exists(self.filename)) + + def test_file_url(self, urlretrieve): + with util.as_local_file("file:///tmp/foo") as fn: + self.assertEqual(fn, "/tmp/foo") + self.assertEqual(urlretrieve.call_args_list, [])