-
Notifications
You must be signed in to change notification settings - Fork 49
How atomic is renameFile? #109
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
Comments
This is a fairly nuanced issue on Windows: https://stackoverflow.com/q/167414 According to the Niall Douglas' explanation in "Racing the File System" at CppCon and Doug E. Cook's comment on MSDN forums, DocsI think the documentation could be clarified by weakening the guarantees of this function on Windows, as the atomicity of this function seems unclear on that platform. Alternative 1"Racing the File System" notes that there is a more exotic, NTFS-specific alternative:
However, I don't know if this might break other use cases, since users might be unintentionally relying on the fallback behavior when moving files from one volume to another, so this is unlikely to work as a general purpose replacement for To allow an open file to be replaced, the (This approach is not used in the standard libraries of other languages, e.g. both Python and Rust use the more conventional Alternative 2There is an older API |
@Rufflewind: I think it's fine if the solution is to weaken the guarantee on Windows |
What is the status of this? HLS depend on it too. |
Is
System.Directory.renameFile
supposed to safely handle two parallel renames that share the same destination?The documentation says:
... but it doesn't clarify what should happen if two concurrent processes rename two files to the same destination for the first time.
The context for this is: dhall-lang/dhall-haskell#1904
What we ran into is that we were using the
atomic-write
package and in the course of doing so ran into a situation where two parallel writes attempted to write to the same destination file at the same time. Under the hood, each write creates a temporary file and usesrenameFile
to move the temporarily file to the final destination. If they rename to the same destination in parallel we see a conflict on Windows. On Linux things work without problems.The text was updated successfully, but these errors were encountered: