-
Notifications
You must be signed in to change notification settings - Fork 4.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
System.IO.Directory.Move fails between two mounts on Linux #31149
Comments
Based on the documentation, this might be expected, or at least known, behavior:
|
/cc @JeremyKuhne |
dotnet/corefx#40611 related? |
It is something we didn't put effort in to support, primarily because the code was utilizing |
@vcsjones is correct, this is documented and I didn't read the documentation thoroughly. On the other hand I think there are compelling arguments for a feature request for this. Unix-programs are normally agnostic to which volume/mount a folder belongs to. |
Would it be less effort if the fallback behavior was to run |
I'd personally have rathered Directory.Move and File.Move just failed when trying to span volumes even on Windows. Tracking down that bug left behind by another developer was not a fun day. (The developer assumed it was atomic, and some other process managed to get in between and read half the file--hint: file locks don't always work on network volumes being accessed by multiple computers.) |
@joshudson Aren’t you just back at writing your own Directory.Move then? (And in addition you’ll need mechanisms for checking volumes files belongs to, and in case of Unix where path/volumes are configurable, do that always) |
@hsorbo: Better a misconfigured program failing than losing data. Detecting cross-volume is easy. Don't pass |
@joshudson getting rid of it on windows is probably not in the cards as its breaking change (maybe worth a new issue). MoveFileEx is windows API, not unix/posix (and i think file locking is uncommon thing on unixes). Making consumers implement Directory.Move because of the problem has no guarantees for data loss in concurrent programming is, in my book, not a very strong argument for not supporting this scenario. |
I came upon a scenario that encountered this today involving Docker. Anytime Directory.Move gets invoked on a directory created in a previous Docker layer, you will hit this issue. Docker utilizes overlay mounts to union the layers of a Docker image. Modifying files in a previous Docker layer is something you typically try to avoid because it causes image bloat. That being said there are times this has to be done. The end user scenario that hit this is |
FYI this also happens on macOS. summaryTrying to move files on a folder shared to everyone on a Microsoft Windows Server 2012R2 to a local macos folder. I should add this happens on
dotnet infodotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.100
Commit: cd82f021f4
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.14
OS Platform: Darwin
RID: osx.10.14-x64
Base Path: /usr/local/share/dotnet/sdk/3.1.100/
Host (useful for support):
Version: 3.1.0
Commit: 65f04fb6db
.NET Core SDKs installed:
3.1.100 [/usr/local/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download environmentscreenfetch -n
solrevdev@macmini
OS: 64bit Mac OS X 10.14.6 18G95
Kernel: x86_64 Darwin 18.7.0
Uptime: 23d 19h 10m
Packages: 415
Shell: zsh 5.7.1
Resolution: 2560x1440
DE: Aqua
WM: Quartz Compositor
WM Theme: Blue (Dark)
Disk: 404G / 525G (78%)
CPU: Intel Core i5-4278U @ 2.60GHz
GPU: Intel Iris
RAM: 8856MiB / 16384MiB |
Triage: As I mentioned above, I'm ok with trying to add cross volume moves, it would just require a lot of work and thorough tests. The underlying API on Windows that we use doesn't support it and we'd want to make sure we're matching in volume moves as closely as possible (that is, as the Win32 |
@JeremyKuhne It seems typo - should be "on Unix". One way to fix is in PowerShell/PowerShell#13044 |
This behaviour is based on how |
Perhaps we could enhance the API with a flag to disable default cross-volume coping for performance reasons. |
No, I meant Windows. We'd want to also look at moving files from |
@JeremyKuhne This should already works if MOVEFILE_COPY_ALLOWED flag is used in MoveFile()
|
.Net Framework has another implementation https://referencesource.microsoft.com/#mscorlib/system/io/longpath.cs,410 - the MOVEFILE_COPY_ALLOWED flag is not used. Although the question is how correctly the Windows API works for mount reparse (OneDrive) points. |
It seems @rjmholt tried FileInfo.MoveTo() for cross-volume on current PowerShell Core and it throws - is it a bug in .Net or docs? |
Yes, my bad, flashbacks to
@carlossanlop can you follow up? |
Full error:
|
@JeremyKuhne |
@DaniilShmelev can you share more about the regression? What regressed? |
@danmoseley just to be clear - the regression happened due to us adding |
On Linux/netcore3
System.IO.Directory.Move
throwsSystem.IO.IOException: Invalid cross-device link
when trying to move a folder between two mounts/disks in Linux.System.IO.Directory.Move("/tmp/foo","/tmp/baz"); //works
System.IO.Directory.Move("/mnt/notsamedisk/foo","/tmp/baz"); //throws
uname -a
Linux Test 5.0.0-1018-azure dotnet/corefx#19~18.04.1-Ubuntu SMP Wed Aug 21 05:13:05 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered: