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?
            Asked
            
        
        
            Active
            
        
            Viewed 870 times
        
    9
            
            
        - 
                    4The 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
 - 
                    1Relevant dialogue from Python bug tracker: https://bugs.python.org/issue27886 – Aug 15 '18 at 16:04
 
1 Answers
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.
- 
                    1The 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