8

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?

Highflyer108
  • 85
  • 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

4

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
  • 5,549
  • 2
  • 34
  • 56
NtFreX
  • 8,977
  • 2
  • 37
  • 61