-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
fs::write fails on long file name in deep directory path on windows #76586
Comments
|
@the8472 long paths are enabled. It works with the |
Perhaps, or C# has an application manifest that sets the |
It's not. I think C# might be using UNC path so this works. Can you try with C++? |
It seems C++ fails silently... #include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream myFile("C:\\Users\\testing.user\\.bvm\\bins\\nodejs-node-8.12.0\\node-v8.12.0-win-x64\\node_modules\\npm\\test\\npm_cache\\_cacache\\content-v2\\sha512\\32\\c8\\6992ba4671408a292bb3f2fae4cd10416dcedb6a214c169054af6bcc792b6ea56f7245333357cc59e4f84660380604b5ff338258ad46973218d864799b5e");
myFile << "test";
myFile.close();
std::cout << "Wrote\n"; // this outputs, but the file is not created
return 0;
} By the way, I'm starting to think this is just something that should be handled manually be the developer when working with paths. I'm remembering now that |
Unfortunately Rust does not support application manifests at all therefore you'd have to use a custom linker option. Although even this only helps if you always control the environment your application will run in. |
Maybe the documentation could be updated to add a note on Windows that, depending on the application, it might be necessary to canonalize very long paths for it to work. |
The question would be where to place it, the issue is likely not unique to |
|
|
Canonicalize won't work in any case. It requires opening the path before you can canonicalize the path. Opening the path was the issue in the first place so this is a chicken and egg situation. |
I was not aware of these caveats, I was basing myself on this:
|
There are several ways to improve this situation (and are by no means mutually exclusive):
|
Just encountered the same issue. I found a partial "workaround", but it only applies to reading and not writing. As an example, let's say we have a file named Oddly enough, using the verbatim path prefix (
|
This specific issue should hopefully be fixed in nightly by #89174, which is currently scheduled for the 1.58.0 release. This implements @retep998 fourth bullet point (automatically handles long paths). #89270 implemented the third ( |
Closing as fixed. The original issues has been addressed, there is also now an (unstable) |
Run the following code and ensure the application has access to the folder.
Expected behaviour: It should create the file as I can create the file in file explorer and using other utilities like 7zip.
Actual behaviour: It errors with
Os { code: 3, kind: NotFound, message: "The system cannot find the path specified." }
Meta
rustc +nightly --version --verbose
:Other Info
The following equivalent application works fine in C# on the same system:
Edit: It occurs after the path length exceeds 260 characters.
The text was updated successfully, but these errors were encountered: