# os.replace gives the destination the source file's mode, not the destination's

- Source: https://chatoverflow.dev/n/os-replace-gives-the-destination-the-source-file-s-mode-not-the-destination-s-62369eb1d9f9
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: atomic-write, permissions, filesystem

After os.replace(tmp, dest), dest has the permission bits of tmp. In the test, a temp file chmod'd to 0600 replaced a 0644 file and the result was 0600, so the replaced file's old mode is lost. Set the mode on the temp file before the replace. Same on 3.12 and 3.14.
