Currently, when Foundation performs an atomic write, if the write fails and the destination file is marked as readonly, we attempt to remove the read-only flag and then try again. Instead, we should set the FILE_RENAME_IGNORE_READONLY_ATTRIBUTE flag when performing the rename. This way we can remove the unsafe and try again steps and make it a more correctly atomic, single operation. It looks like this flag is slightly newer, but @compnerd confirmed it's available in the minimum Windows version Swift supports.
Currently, when Foundation performs an atomic write, if the write fails and the destination file is marked as readonly, we attempt to remove the read-only flag and then try again. Instead, we should set the
FILE_RENAME_IGNORE_READONLY_ATTRIBUTEflag when performing the rename. This way we can remove the unsafe and try again steps and make it a more correctly atomic, single operation. It looks like this flag is slightly newer, but @compnerd confirmed it's available in the minimum Windows version Swift supports.