Repository navigation
FileSystem.Unix.File.Move uses "rename" in more cases (#40611) - #395
Conversation
* FileSystem.Unix.File.Move use rename in more cases, avoid link/copy when possible, improve performance on file systems that do not support hard links, such as FAT * Adapt Unit Tests for accounting FileSystemWatcher events fired by FileSystem.Unix.File.Move implementation that use rename in more cases, avoiding link/copy when possible
|
@baulig Please give this a review as I don't want to regress against Android. |
| sourceStat.Ino == destStat.Ino && // and source and dest are the same file on that device | ||
| (Interop.Sys.LStat(destFullPath, out destStat) != 0 || // dest file does not exist | ||
| sourceStat.Ino == destStat.Ino) && // source and dest are the same file on that device | ||
| Interop.Sys.Rename(sourceFullPath, destFullPath) == 0) // try the rename |
There was a problem hiding this comment.
It looks like you removed the same device check here - sourceStat.Dev == destStat.Dev. Is this intentional?
There was a problem hiding this comment.
@baulig I asked Mitch to essentially cherry pick the corefx change as it would solve the problem VS is having. I noticed the change and wanted you to guide Mitch so that we would not regress on Android. So, to answer your question, yes it was intentional, but we probably need to put your checks back in. What do you think?
There was a problem hiding this comment.
Right, looking into it further, I'm not sure if it was intentional to call rename for the scenario in which sourceFullPath and destFullPath both lead to files that exist, but exist on different devices, yet still happen to have the same Inode number (file serial number).
It appears that the original case was to catch a simple change in file case, ("aa.txt" -> "AA.txt"), and it looks like the cherry-picked PR was intended to widen the scope in which Rename is called and lower expectations of delete events firing.
Looking at the test cases, it's not obvious to me whether or not there is a check for moving a file from one device to another. Locally adding that same device check and testing, the intended functionality of Rename events firing is maintained.
There was a problem hiding this comment.
You are checking whether both files have the same inode (sourceStat.Ino == destStat.Ino), but without checking for the same device (sourceStat.Dev == destStat.Dev).
The inode check alone is not enough because two different files on two different devices may have the same inode by pure chance. And when that happens, that code is now unexpectedly behaving differently. And since that will be such a rare occurrence, it will be a total nightmare to track down.
Please either put back the device check or explain in a comment why the above mentioned scenario cannot happen, as I don't see that from looking at the code.
There was a problem hiding this comment.
When files exist on different devices, their inode numbers are completely meaningless and you shouldn't even attempt to "compare" them. An inode number is just a way of uniquely indexing a file in a particular file system - and it's therefore unique to that file system. They're also generated mostly randomly (not in a cryptographic sense of course!) and really have no special meaning other than ensuring uniqueness.
I spent some more time looking at that code and I believe the reason we are comparing the inode numbers is to identity the case where one of the files is a link to the other one - or when both are links to the same third file. Using lstat() is far more efficient than readlink().
There was a problem hiding this comment.
Or in other words, if you ever see a piece of code that looks at an inode number without also looking at the device id - something is likely wrong.
There was a problem hiding this comment.
I agree with @baulig. I missed seeing this removal, and the omission seems like an accident/error in the original PR as it is not addressed.
We should probably just re-add the line. We should bring this up in dotnet/runtime too.
There was a problem hiding this comment.
Thanks for the 👀. I re-added the logic to check that the source and dest files have the same device ID and inode serial number.
There was a problem hiding this comment.
Looks good to me now, but let's wait for the CoreFX folks to also address it on their end in dotnet/runtime#34330
dd59c95 to
3509c94
Compare
3509c94 to
217db7e
Compare
|
@monojenkins backport mono-2019-12 |
Co-authored-by: Mitchell Hwang <[email protected]>
Co-authored-by: Mitchell Hwang <[email protected]>
Changes: mono/mono@ecde086...165f4b0 * mono/mono@165f4b03417: [2020-02][debugger] Fix NOT_IMPLEMENTED while debugging. (#19450) * mono/mono@b04dc7e6a48: Bump corefx to get mono/corefx#395 (#19426)
Commits: * mono/mono@165f4b03417: [2020-02][debugger] Fix NOT_IMPLEMENTED while debugging. (dotnet#19450) * mono/mono@b04dc7e6a48: Bump corefx to get mono/corefx#395 (dotnet#19426) Diff: mono/mono@ecde086...165f4b0 Related android PR: dotnet/android#4540
Commits: * mono/mono@165f4b03417: [2020-02][debugger] Fix NOT_IMPLEMENTED while debugging. (#19450) * mono/mono@b04dc7e6a48: Bump corefx to get mono/corefx#395 (#19426) Diff: mono/mono@ecde086...165f4b0 Related android PR: dotnet/android#4540
Commits: * mono/mono@165f4b03417: [2020-02][debugger] Fix NOT_IMPLEMENTED while debugging. (dotnet#19450) * mono/mono@b04dc7e6a48: Bump corefx to get mono/corefx#395 (dotnet#19426) Diff: mono/mono@ecde086...165f4b0 Related android PR: dotnet/android#4540
Commits: * mono/mono@165f4b03417: [2020-02][debugger] Fix NOT_IMPLEMENTED while debugging. (#19450) * mono/mono@b04dc7e6a48: Bump corefx to get mono/corefx#395 (#19426) Diff: mono/mono@ecde086...165f4b0 Related android PR: dotnet/android#4540
Changes: mono/mono@ecde086...165f4b0 * mono/mono@165f4b03417: [2020-02][debugger] Fix NOT_IMPLEMENTED while debugging. (#19450) * mono/mono@b04dc7e6a48: Bump corefx to get mono/corefx#395 (#19426)
Changes: mono/mono@ecde086...165f4b0 * mono/mono@165f4b03417: [2020-02][debugger] Fix NOT_IMPLEMENTED while debugging. (#19450) * mono/mono@b04dc7e6a48: Bump corefx to get mono/corefx#395 (#19426)
Changes: mono/mono@ecde086...165f4b0 * mono/mono@165f4b03417: [2020-02][debugger] Fix NOT_IMPLEMENTED while debugging. (#19450) * mono/mono@b04dc7e6a48: Bump corefx to get mono/corefx#395 (#19426)
Cherry-picked commit message
This PR looks to fix the MonoDevelop.Projects.DotNetCoreFileWatcherTests.AddRenameRemoveSingleFile error described in DevDiv workitem 1089785.
A FileSystemWatcher regression occurred when bots were upgraded from Mojave to Catalina.
It turns out that File Renamed events were not being sent on Catalina though the files were being properly renamed.
To fix, a cherry-pick of a commit on
dotnet/corefxwas applied.Testing:
Reproduced using desktop mono (6.13.0) on macOS Catalina 10.15.3 using the sample code provided, which was uploaded here https://gist.github.com/mdh1418/f2a47838fbd9b53efa53fe18789a5ebb
Fixing:
Applied the changes to
FileSystem.Unix.cstomono/src/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs, ranmake -jand re-ran the sample program.Port of dotnet#40611