Skip to content

fix: windows drive letters remap to unc paths#2104

Open
maxnbk wants to merge 18 commits into
AcademySoftwareFoundation:mainfrom
maxnbk:fix/windows-drive-letters-remap-to-unc-paths
Open

fix: windows drive letters remap to unc paths#2104
maxnbk wants to merge 18 commits into
AcademySoftwareFoundation:mainfrom
maxnbk:fix/windows-drive-letters-remap-to-unc-paths

Conversation

@maxnbk
Copy link
Copy Markdown
Contributor

@maxnbk maxnbk commented May 14, 2026

Closes #2045 and #1438 .
Partial but not complete fix for #1909 (Intentional, I feel that the work that was occurring in the gitbash PR would ultimately resolve this behavior?) .

Explanations:

os.path.realpath on Python 3.8+ Windows silently expands mapped drive letters to their underlying UNC paths. Because canonical_path calls realpath, FileSystemPackageRepository was storing a UNC self.location even when the caller supplied a drive-letter path. This caused make_resource_handle, which does a raw string comparison, to raise ResourceError on every drive-letter handle against a UNC-stored repository.

The fix:

On Windows, canonical_path now uses os.path.abspath instead of os.path.realpath. This preserves path style (drive-letter stays drive-letter, UNC stays UNC) and restores the pre-3.8 normalization behavior without a network-resolution side-effect. A make_resource_handle override is also added to the filesystem plugin to handle residual case or separator mismatches via canonical_path.

Extension of work:

A resolve_links_on_windows config flag (default False) has been added for sites that need some form of symlink/junction resolution on Windows. When enabled, a purpose-built _windows_realpath walks components of the path using os.readlink, resolving real symlinks without actually touching the drive root, in order to avoid the UNC-expansion side-effect entirely. Long-path support (\\?\ prefix handling) is included, with the relevant test skipped on hosts that do not have LongPathsEnabled=1 in the registry. Note: I'm aware that we need to move off of the winreg module, but since we have it for now, might as well use it.

Testing:

This was tested against an actual Drive-letter-map-with-matching-UNC-network-share .

====EDIT====

This PR has been extended with a broader real_path migration.

real_path() helper - A new utility function in filesystem.py that replaces os.path.realpath at all call sites where path-style stability is required.
On Windows, it is delegated to os.path.abspath to preserve the drive-letter style.
On all other platforms, it is delegated to os.path.realpath to preserve symlink resolution.
Importantly, no config-flag is required - the correct behavior is derived from the OS, not user preference. canonical_path from the original PR slice now calls real_path internally.

Call-site migration - All non-test os.path.realpath code that touched stored, serialized, or compared paths have been updated:

  • filesystem.py - canonical_path, is_subdirectory
  • resolved_context.py - _adjust_variant_for_bundling
  • serialise.py - open_file_for_write, load_from_file
  • suite.py - Suite.save, Suite.load
  • system.py - rez_bin_path
  • rezplugins/build_system/cmake.py - also corrects a pre-existing dead-code bug (os.path.abspath used as a truthiness check where os.path.isabs was intended)
  • utils/py_dist.py - egg-to-rez file path comparisons and copy destinations

Relationship to prior work - Several earlier attempts addressed this problem class but were either incomplete/partial, lacked tests, or relied on opt-in config flags:

====END EDIT====

Disclosure:

This PR was AI-assisted with Claude Code, Sonnet 4.6, primarily for diagnostics, logic-tracing, documentation and edge-case verification.

@maxnbk maxnbk requested a review from a team as a code owner May 14, 2026 19:50
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 79.41176% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.02%. Comparing base (6f4bc68) to head (92124cf).

Files with missing lines Patch % Lines
src/rez/utils/filesystem.py 84.44% 3 Missing and 4 partials ⚠️
src/rez/utils/py_dist.py 0.00% 3 Missing ⚠️
src/rezplugins/build_system/cmake.py 33.33% 1 Missing and 1 partial ⚠️
src/rez/rezconfig.py 0.00% 1 Missing ⚠️
src/rezplugins/package_repository/filesystem.py 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2104      +/-   ##
==========================================
+ Coverage   60.95%   61.02%   +0.06%     
==========================================
  Files         164      164              
  Lines       20629    20683      +54     
  Branches     3591     3606      +15     
==========================================
+ Hits        12575    12621      +46     
- Misses       7181     7182       +1     
- Partials      873      880       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maxnbk maxnbk force-pushed the fix/windows-drive-letters-remap-to-unc-paths branch from ae4aeb2 to 92b2b07 Compare May 14, 2026 20:01
@maxnbk maxnbk added the devdays26 ASWF Dev Days 2026 label May 14, 2026
@maxnbk maxnbk force-pushed the fix/windows-drive-letters-remap-to-unc-paths branch from 92b2b07 to 1681466 Compare May 14, 2026 20:36
@JeanChristopheMorinPerso
Copy link
Copy Markdown
Member

@maxnbk What's the relationship to #1856?

During the TSC, @instinct-vfx said that the expected default behavior is that the style should stay consistent based on how the repo was configured?

@JeanChristopheMorinPerso JeanChristopheMorinPerso added this to the Next milestone May 21, 2026
@cfxegbert
Copy link
Copy Markdown
Contributor

Can you please look at #1856. There are a few other places that realpath needs to be replaced.

@maxnbk
Copy link
Copy Markdown
Contributor Author

maxnbk commented May 22, 2026

I'll take a look and see what else needs resolving. I may have to add some more tests to find all the edge-cases. Goal is to incorporate all solutions from all mismatched PRs, as I think there were approximately 3 all trying to solve the same problem with partial/incomplete solutions, and nobody got all corners.

Evidently that extends to me, so I'll re-evaluate and see what I need to do to extend.
Might be this weekend though. :)

maxnbk added 9 commits May 26, 2026 12:31
…is remapped by rez to a UNC path

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…repository filesystem to ensure its consumption

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…-compatible symlink/junction-point resolution behavior

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…ion-behavior intended to produce realpath-like behavior

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…support in optional symlink-resolution for windows

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…ath-aware.

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…d network windows path styles

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…ation

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
@maxnbk maxnbk force-pushed the fix/windows-drive-letters-remap-to-unc-paths branch from 1681466 to 7eb40dc Compare May 26, 2026 17:09
maxnbk added 4 commits May 26, 2026 13:13
…migration points

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…s as needed by py3.8+ realpath changes

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…lization, not for opening/storing/passing

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…roper use of canonical_path vs real_path in resolved_context

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
@maxnbk maxnbk force-pushed the fix/windows-drive-letters-remap-to-unc-paths branch from 7eb40dc to a561892 Compare May 26, 2026 17:15
maxnbk added 3 commits May 26, 2026 13:29
…orm-specific symlink resolution

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…via resolved_context

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
…stead.

Signed-off-by: Stephen Mackenzie <maxnbk@users.noreply.github.com>
@maxnbk maxnbk force-pushed the fix/windows-drive-letters-remap-to-unc-paths branch from a561892 to 29a15fe Compare May 26, 2026 17:30
Signed-off-by: Jean-Christophe Morin <jean_christophe_morin@hotmail.com>
Signed-off-by: Jean-Christophe Morin <jean_christophe_morin@hotmail.com>
@JeanChristopheMorinPerso JeanChristopheMorinPerso modified the milestones: 3.4.0, Next May 30, 2026
@cfxegbert
Copy link
Copy Markdown
Contributor

@JeanChristopheMorinPerso Looks like this didn't get merged into the 3.4.0. What can we do to get this out there?

@JeanChristopheMorinPerso
Copy link
Copy Markdown
Member

Hey @cfxegbert, this was intentional. We had a few more questions to answer and decided to push this to a follow up release. We are planning to do a 3.4.1 release soon-ish to get this PR out.

When I reviewed the PR, I noticed that os.path.islink doesn't do what we thought it would on windows. At least I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devdays26 ASWF Dev Days 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: Repository mismatch with mounted network drives

3 participants