Skip to content

Fix verbatim prefix handling in junction creation#31

Merged
tesuji merged 2 commits intotesuji:mainfrom
DK26:main
Jan 17, 2026
Merged

Fix verbatim prefix handling in junction creation#31
tesuji merged 2 commits intotesuji:mainfrom
DK26:main

Conversation

@DK26
Copy link
Contributor

@DK26 DK26 commented Dec 15, 2025

Fix verbatim prefix handling in junction creation

Summary

This PR fixes #30 where junction::create() silently fails when called with paths containing the Windows verbatim prefix (\\?\).

Problem

When paths from std::fs::canonicalize() are passed to junction::create(), the function returns Ok(()) but creates a broken junction that cannot be accessed. This is because:

  1. get_full_path() returns the path with the verbatim prefix intact
  2. create() then prepends the NT prefix \??\ unconditionally
  3. The resulting reparse point data contains an invalid double prefix: \??\\\?\C:\...

Solution

Strip the Win32 verbatim prefix (\\?\) from the target path before constructing the reparse point data. This is done in create() right after calling get_full_path(), which is the correct location since:

  • The Win32-to-NT path conversion is a concern of junction creation, not path normalization
  • It matches the existing pattern in get_target() which strips the \??\ prefix when reading
  • It uses strip_prefix().unwrap_or() so paths without the prefix are unchanged

Testing

  • Added regression test create_with_verbatim_prefix_paths that uses fs::canonicalize() to obtain verbatim paths
  • All existing tests continue to pass
  • Manually verified all CI checks pass locally

DK26 added 2 commits December 15, 2025 16:49
Junction creation now correctly handles paths with Windows verbatim
prefix (\\?\). The prefix is stripped before constructing the reparse
point data, preventing double-prefix corruption.
Copy link
Owner

@tesuji tesuji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for not responding sooner.

LGTM with one nit.

Copy link
Owner

@tesuji tesuji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Ty.

I misunderstood between \\.\ and \??\.

@tesuji tesuji merged commit d831760 into tesuji:main Jan 17, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Junction creation fails silently with verbatim \\?\ prefix paths

2 participants