-
Notifications
You must be signed in to change notification settings - Fork 263
Don't fail file open/writes silently #880
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
Conversation
int main(int const argc, char** argv) | ||
{ | ||
// Dynamically enable long path support | ||
((unsigned char*)(NtCurrentTeb()->ProcessEnvironmentBlock))[3] |= 0x80; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not be calling undocumented APIs from cppwinrt.exe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an alternative or do we pull it out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative is to create an app manifest; I had tried doing that, the manifest was getting embedded, but long path were still not working. We could pull out this one line from the code and leave the error reporting, and I can try to rework the manifest. LMK what you'd like to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR to use the manifest here: #882
Fixes #877
(moving from remote branch PR in #877)
Context
React Native for Windows creates apps that can end up with some paths that need to be built that are too long (e.g.
C:\users\myname\source\repos\MyAppProject\node_modules\react-native-windows\Microsoft.ReactNative\Generated Files\winrt\Insert.Your.Favorite.Long.Namespace.Here.h
). We see lots of issues where people are creating their project starting in an already pretty deeply-nested folder, and the build fails.Root cause
The reason the build fails is because certain headers that cppwinrt is supposed to generate are not on disk. After tracing this down, it turns out that this comes from the fact that the
std::ofstream
constructor does not throw on error. Instead, it will set its internal handle to null, and you have to checkmyofstream.good()
before continuing. The alternative is to construct an emptyofstream
, set a flag that says you want exceptions, and then callopen()
, which is what I ended up doing.With that part of the fix, you now get an error instead of "silently failing and returning success" which today causes the build to fail later on:
The second part of the fix is to turn on Long Path support. This normally requires a manifest. I tried embedding the manifest through VS and jumping through all them hoopz, but in the end the alternative is one line in
main()
to set a bit in the PEB. With that fix, at least long path errors won't be a thing (as long as you have the per-machine setting turned on too); but now also if we fail to write a file (e.g. file was held open exclusively), we will now correctly get an error instead of silently failing/succeeding.