Skip to content

Commit

Permalink
Fix UNC paths
Browse files Browse the repository at this point in the history
If the input file was a network path then the raw path returned by
GetFinalPathByHandle may return a UNC path. If so, and if the original
path wasn't a UNC path, and the original path doesn't need normalization,
we want to use the original path.
  • Loading branch information
agocke committed Nov 25, 2024
1 parent 00ba6d5 commit 1042720
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/native/corehost/hostmisc/pal.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,12 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging)
}
}

// Remove the \\?\ prefix, unless it is necessary or was already there
if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) &&
// Remove the UNC prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there
if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && !LongFile::ShouldNormalize(*path))
{
str = *path;
}
else if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) &&
!LongFile::ShouldNormalize(str.substr(LongFile::ExtendedPrefix.size())))
{
str.erase(0, LongFile::ExtendedPrefix.size());
Expand Down

0 comments on commit 1042720

Please sign in to comment.