Skip to content

Commit

Permalink
Strip dos device prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
roggiezhang-nv committed Oct 23, 2024
1 parent f2709f9 commit 52e665c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
9 changes: 9 additions & 0 deletions pxr/base/arch/fileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,15 @@ ArchGetFileName(FILE *file)
CP_UTF8, 0, filePath,
-1,
&result.front(), outSize, NULL, NULL);

if (result.length() > 4)
{
std::string prefix = result.substr(0, 4);
if (prefix == "\\\\?\\" || prefix == "\\\\.\\")
{
result = result.substr(4);
}
}
}
return result;
#else
Expand Down
24 changes: 1 addition & 23 deletions pxr/base/arch/testenv/testFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,6 @@ _AbsPathFilter(const std::string& path)
return path;
#endif
}

std::string
_DosDevicePathFilter(const std::string& path)
{
#if defined(ARCH_OS_WINDOWS)
// Strip prefix \\?\ or \\.\ and convert backslashes to forward slashes.
std::string result = path;
if (result.length() > 4)
{
std::string prefix = result.substr(0, 4);
if (prefix == "\\\\?\\" || prefix == "\\\\.\\")
{
result = result.substr(4);
}
}

return ArchNormPath(result);
#else
// Return path as-is.
return path;
#endif
}
}

static bool
Expand Down Expand Up @@ -117,7 +95,7 @@ int main()
// Open a file, check that the file path from FILE* handle is matched.
ARCH_AXIOM((firstFile = ArchOpenFile(firstName.c_str(), "rb")) != NULL);
std::string filePath = ArchGetFileName(firstFile);
ARCH_AXIOM(_DosDevicePathFilter(filePath) == _DosDevicePathFilter(firstName));
ARCH_AXIOM(ArchNormPath(filePath) == ArchNormPath(firstName));
fclose(firstFile);

// Map the file and assert the bytes are what we expect they are.
Expand Down

0 comments on commit 52e665c

Please sign in to comment.