Skip to content

Commit

Permalink
Fix another issue with unresolvable reparse points on Windows. ArchRe…
Browse files Browse the repository at this point in the history
…adLink

can return the passed in path if it refers to an "NT Object Manager" path,
and we need to handle this as if it isn't a reparse point, because we can't
follow the link.
  • Loading branch information
marktucker authored and Vijin Ravindran committed Jan 29, 2025
1 parent 1669880 commit c771613
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 12 additions & 4 deletions pxr/base/tf/fileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,22 @@ Tf_HasAttribute(

// Ignore reparse points on network volumes. They can't be resolved
// properly, so simply remove the reparse point attribute and treat
// it like a regular file/directory.
// it like a regular file/directory. Also ignore reparse points where
// TfReadLink returns the passed in path. As described in ArchReadLink,
// this will happen in cases where the reparse points are NT Object
// Manager paths, which cannot be used as file paths. Or if TfReadLink
// returns an empty string, that means we could not resolve the link
// at all, so treat it as if it is not a link.
std::string linkPath;
if ((attribs & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
// Calling PathIsNetworkPath sometimes sets the "last error" to an
// error code indicating an incomplete overlapped I/O function. We
// want to ignore this error.
DWORD olderr = GetLastError();
if (PathIsNetworkPathW(pathW.c_str())) {
linkPath = TfReadLink(path.c_str());
if (PathIsNetworkPathW(pathW.c_str()) ||
linkPath.empty() ||
path == linkPath) {
attribs &= ~FILE_ATTRIBUTE_REPARSE_POINT;
}
SetLastError(olderr);
Expand All @@ -106,8 +115,7 @@ Tf_HasAttribute(
}

// Read symlinks until we find the real file.
return Tf_HasAttribute(TfReadLink(path.c_str()), resolveSymlinks,
attribute, expected);
return Tf_HasAttribute(linkPath, resolveSymlinks, attribute, expected);
}

// Same as above but the bits in attribute must all be set.
Expand Down
8 changes: 2 additions & 6 deletions pxr/base/tf/pathUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ _ExpandSymlinks(const std::string& path)
prefix.push_back('\\');
}
if (TfIsLink(prefix)) {
// Expand the link and repeat with the new path if the path changed.
// The path may remain unchanged or be empty if the link type is
// unsupported or the mount destination is not available.
auto newPrefix = TfReadLink(prefix);
if (!newPrefix.empty() && newPrefix != prefix)
return _ExpandSymlinks(newPrefix + path.substr(i));
// Expand the link and repeat with the new path.
return _ExpandSymlinks(TfReadLink(prefix) + path.substr(i));
}
i = path.find_first_of("/\\", i + 1);
}
Expand Down

0 comments on commit c771613

Please sign in to comment.