I encountered a problem that std::fs::remove_dir_all always fails when deleting a network shared folder on Windows VM inside Parallels Desktop for Mac.
This is annoying because remove_dir_all is used in build scripts in many crates and also by cargo itself. Each rust build prints many warnings like following:
warning: failed to garbage collect finalized incremental compilation session directory `\\?\UNC\Mac\Home\src\samples\parallels-problem\target\debug\incremental\parallels_problem-3d161pebl2984\s-h5ylcgmdc5-1sl1tye-5kba3ot62n4mzposecklyv93z`: The parameter is incorrect. (os error 87)
warning: failed to garbage collect finalized incremental compilation session directory `\\?\UNC\Mac\Home\src\samples\parallels-problem\target\debug\incremental\parallels_problem-3d161pebl2984\s-h5ypnw5wyg-nhle4-3t64cga38i2hprb2a1y2w1iyj`: The parameter is incorrect. (os error 87)
...
cwd: \\Mac\Home\src\samples\parallels-problem
thread 'main' panicked at src/main.rs:13:32:
remove_dir_all works: Os { code: 87, kind: InvalidInput, message: "The parameter is incorrect." }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\parallels-problem.exe` (exit code: 101)
I'm not sure if it's a problem in rust or in Parallels.
I would locate the actual platform-specific implementation of remove_dir_all(), then copy'n'paste it into a test project, and go through it step-by-step to try to pin-point exactly what goes wrong.
It doesn't show the place of the original panic but the point of expect call:
cwd: \\Mac\Home\src\samples\parallels-problem
thread 'main' panicked at src\main.rs:8:32:
remove_dir_all works: Os { code: 87, kind: InvalidInput, message: "The parameter is incorrect." }
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181/library\std\src\panicking.rs:692
1: core::panicking::panic_fmt
at /rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181/library\core\src\panicking.rs:75
2: core::result::unwrap_failed
at /rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181/library\core\src\result.rs:1704
3: enum2$<core::result::Result<tuple$<>,std::io::error::Error> >::expect<tuple$<>,std::io::error::Error>
at /rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181\library\core\src\result.rs:1061
4: parallels_problem::main
at \Mac\Home\src\samples\parallels-problem\src\main.rs:8
5: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
at /rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181\library\core\src\ops\function.rs:250
6: core::hint::black_box
at /rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181\library\core\src\hint.rs:475
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\parallels-problem.exe` (exit code: 101)
Another way to do it is to run the code in a debugger and step into remove_dir_all().
According to this thread, you're supposed to be able to step into std if you just tell the debugger where it can find the source files.
Not sure how to do this in Windows though.
If you don't have a development environment set up inside the virtual machine where the problems occur, you might want to set up remote debugging using msvsmon and connect to it using the Visual Studio debugger.
Is there a free version of Parallels? I'm curious to see if this is reproducible.
Thank you for the suggestion. Yes, I do you have development environment set up.
I'll try to debug it in VS and step into remove_dir_all.
Is there a free version of Parallels? I'm curious to see if this is reproducible.
There is a 14day trial on their website. If you decide to install it, disable 'fancy' stuff as much as possible and only allow to share 'Mac' files with the VM. Do not share 'Windows' (otherwise it will add a lot of shortcuts/symlinks to the host machine). Personally I just share ~/src Mac folder with the VM.
Looks like rust analyzer doesn't work on ARM. This platform (win32-arm64) is not suported (exact quote).
I'm going to try on an Intel machine.
update: I tried to uninstall vscode arm64 and installed x64 version instead. Debugging works now.
update: I managed to step and mapped the std source code. Thank you!
On an Intel machine with 1.82-x86_64-pc-windows-msvc toolchain I got similar results. I still can't step into fill_dir_buf, but now the process doest exit and I can see that the error definitely happens inside fill_dir_buf.
fill_dir_buf is an unsafe { ... } wrapper around a call to GetFileInformationByHandleEx, so it's probably inlined, and that's why I can't step into it.
Unfortunately I can't see variable values. p <variable> in debug console always returns use of undeclared identifier error.
Update 1: I decided to try to call GetFileInformationByHandleEx directly.
I added the windows crate, but it is dependent on proc-macro2 which uses remove_dir_all in custom build command which fails with The parameter is incorrect. (os error 87) :(. The loop is complete now.
I managed to create a simple sample which calls GetFileInformationByHandleEx with FileIdBothDirectoryRestartInfo request and it also returns the 87 error.