Skip to content

Commit

Permalink
Fix symlink resolution on Windows w/short filenames
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cottsay committed Apr 1, 2024
1 parent 6b13f03 commit 77acde1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/catkin_pkg/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 4 additions & 0 deletions test/test_workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import shutil
import sys
import tempfile
import unittest

Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 77acde1

Please sign in to comment.