From 77acde12bbf6286231bf357ca1161e4bdae52a0c Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Mon, 1 Apr 2024 15:48:53 -0500 Subject: [PATCH] Fix symlink resolution on Windows w/short filenames Two issues here: 1. os.path.realpath() doesn't resolve symlinks at all prior to Python 3.8. Best we can do is skip the test there. 2. It doesn't appear that os.path.realpath() is idempotent on Windows when path resolution requires both symlink resolution and 8.3/short filename resolution. Calling it twice seems to give the result we want. --- src/catkin_pkg/workspaces.py | 4 ++-- test/test_workspaces.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/catkin_pkg/workspaces.py b/src/catkin_pkg/workspaces.py index d6f42730..281565bf 100644 --- a/src/catkin_pkg/workspaces.py +++ b/src/catkin_pkg/workspaces.py @@ -92,8 +92,8 @@ def order_paths(paths_to_order, prefix_paths): def _is_equal_or_in_parents(dir_, path): - dir_ = os.path.normcase(os.path.realpath(dir_)) - path = os.path.normcase(os.path.realpath(path)) + dir_ = os.path.normcase(os.path.realpath(os.path.realpath(dir_))) + path = os.path.normcase(os.path.realpath(os.path.realpath(path))) return path == dir_ or path.startswith(dir_ + os.sep) diff --git a/test/test_workspaces.py b/test/test_workspaces.py index be5a76ad..4729c3de 100644 --- a/test/test_workspaces.py +++ b/test/test_workspaces.py @@ -2,6 +2,7 @@ import os import shutil +import sys import tempfile import unittest @@ -43,6 +44,9 @@ def test_order_paths(self): self.assertEqual(['foo' + os.sep + 'bim', 'bar'], order_paths(['bar', 'foo' + os.sep + 'bim'], ['foo'])) def test_order_paths_with_symlink(self): + if os.name == 'nt' and sys.version_info < (3, 8): + self.skipTest('symlinks are not resolved on Windows prior to Python 3.8') + root_dir = tempfile.mkdtemp() try: foo = os.path.join(root_dir, 'foo')