Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ArchGetFileName on windows for file paths with special characters #3545

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

mnaehrig
Copy link
Contributor

Description of Change(s)

ArchGetFileName called std::filesystem::canonical() with an utf8-encoded std::string, but on windows std::filesystem::path expects std::string with system encoding. To fix this issue the std::filesystem::path is now created from the utf16-encoded string, which is returned by GetFinalPathNameByHandleW().

Checklist

ArchGetFileName called std::filesystem::canonical() with an utf8-encoded std::string, but on windows std::filesystem::path expects an std::string with system encoding. To fix this issue the std::filesystem::path is now created from the utf16-encoded string, which is returned by GetFinalPathNameByHandleW().
@nvmkuruc
Copy link
Collaborator

Do you have a test case that shows the failure state?

Simplifying things the function to use the existing Arch converter seems like a good change.

@mnaehrig
Copy link
Contributor Author

You just need a usd file with a non-ASCII character in it's name, e.g. "würfel.usd". If you try to open it in usdview on windows, std::filesystem::canonical raises an exception.

@jesschimein
Copy link
Collaborator

Filed as internal issue #USD-10702

(This is an automated message. See here for more information.)

@jesschimein
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -96,7 +96,12 @@ 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);
#if defined(ARCH_OS_WINDOWS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious if there a solution that could use u8path to avoid forking the test behavior around the platform?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forking could be avoided using u8path. I didn't use it because it's deprecated in C++20 and may be removed with future versions (C++26 or later). But if this is no problem I would change it.

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.

3 participants