[gobject-introspection] scanner: Fix error on Windows in case source files are on different drives
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] scanner: Fix error on Windows in case source files are on different drives
- Date: Sun, 21 Apr 2019 09:22:43 +0000 (UTC)
commit c2d8dab8250d3cc6969fcabfd9f606ffe9c63823
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sun Apr 21 10:59:28 2019 +0200
scanner: Fix error on Windows in case source files are on different drives
os.path.commonpath() raises ValueError if the paths given to it are on different
drives.
Handle that case by giving up and add a test.
Reported here: https://github.com/msys2/MINGW-packages/pull/5258#issuecomment-485230864
giscanner/scannermain.py | 7 ++++++-
tests/scanner/test_scanner.py | 10 ++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index c004fb19..4b723695 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -505,7 +505,12 @@ def get_source_root_dirs(options, filenames):
if not dirs:
return []
- common = os.path.commonpath(dirs)
+ try:
+ common = os.path.commonpath(dirs)
+ except ValueError:
+ # ValueError: On Windows in case the paths are on different drives
+ return dirs
+
# If the only common path is the root directory give up
if os.path.dirname(common) == common:
return dirs
diff --git a/tests/scanner/test_scanner.py b/tests/scanner/test_scanner.py
index 2513c0de..85953964 100644
--- a/tests/scanner/test_scanner.py
+++ b/tests/scanner/test_scanner.py
@@ -25,6 +25,16 @@ class TestScanner(unittest.TestCase):
paths = get_source_root_dirs(options, [])
self.assertEqual(paths, [])
+ @unittest.skipUnless(os.name == "nt", "Windows only")
+ def test_get_source_root_dirs_different_drives(self):
+ options = optparse.Values({"sources_top_dirs": []})
+ names = [
+ os.path.join("X:", os.sep, "foo"),
+ os.path.join("Y:", os.sep, "bar"),
+ ]
+ paths = get_source_root_dirs(options, names)
+ self.assertEqual(paths, list(map(os.path.dirname, names)))
+
if __name__ == '__main__':
unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]