9

In the docs it says that replacing files are guaranteed to be atomic on POSIX systems. Does this mean that it's not atomic on Windows?

Gavin
  • 95
  • 1
  • 5
  • 4
    The docs actually say "If successful, the renaming will be an atomic operation", and then in parenthesis "((this is a POSIX requirement)". So it reads, to me at least, like the operation on all OSes is atomic if successful, and the POSIX thing perhaps added motivation for this. – kabanus Aug 15 '18 at 16:00
  • 1
    Relevant dialogue from Python bug tracker: https://bugs.python.org/issue27886 –  Aug 15 '18 at 16:04

1 Answers1

5

As visible in this thread the atomic replace functionality for windows has been added for version 3.3.

The patch is visible here.

In the background MoveFileEx with when nessesary the MOVEFILE_REPLACE_EXISTING flag added is called.

MoveFileEx is the same method as the openjdk calls. I can't find any documentation stating it is atomic, but the community seems to rely on it.

mhsmith
  • 6,675
  • 3
  • 41
  • 58
NtFreX
  • 10,379
  • 2
  • 43
  • 63
  • 1
    The MSVC STL guys claim that `MoveFileEx` is atomic, and `SetFileInformationByHandle`+`FileRenameInfoEx` might also be. See https://github.com/microsoft/STL/pull/2062#issuecomment-1139106197 – zwhconst Oct 31 '22 at 11:28