Summary
atomic_write_file in crates/mds-cli/src/output.rs uses a write-to-tempfile + rename pattern, which is correct for atomic content replacement. This pattern has one won't-fix limitation by construction and two open platform-specific issues.
Won't fix: hard links
rename replaces the directory entry atomically. Any other hard links to the original inode continue to point to the old content — the file at path now has a new inode with link count 1. Hard-link preservation is incompatible with a rename-based atomic write; this is not a bug but a fundamental property of the approach. Documented in the function's doc comment (PR #239).
Open: platform ACL and xattr preservation
- ACLs lost on macOS/Linux: Extended ACL entries on the original file are not copied to the temp file before rename.
- xattrs lost: Extended attributes (used by macOS Finder metadata,
security.selinux on SELinux/AppArmor, etc.) are not copied to the temp file.
- Owner/group not preserved: The temp file is created with the process's effective UID/GID. If the original file was owned by a different user (e.g., a root-owned config), the rename replaces the owner rather than restoring it.
These do not manifest in the common case (user writing their own file, no special labels). They become issues in environments with SELinux/AppArmor file labels or macOS systems where quarantine bits or Finder metadata are attached to files.
Proposed fix
For environments that require ACL/xattr preservation, use platform-specific copy APIs (e.g., copyfile(3) on macOS, copy_file_range + setxattr on Linux) to transfer attributes from the original to the temp file before rename.
References
Summary
atomic_write_fileincrates/mds-cli/src/output.rsuses a write-to-tempfile +renamepattern, which is correct for atomic content replacement. This pattern has one won't-fix limitation by construction and two open platform-specific issues.Won't fix: hard links
renamereplaces the directory entry atomically. Any other hard links to the original inode continue to point to the old content — the file atpathnow has a new inode with link count 1. Hard-link preservation is incompatible with a rename-based atomic write; this is not a bug but a fundamental property of the approach. Documented in the function's doc comment (PR #239).Open: platform ACL and xattr preservation
security.selinuxon SELinux/AppArmor, etc.) are not copied to the temp file.These do not manifest in the common case (user writing their own file, no special labels). They become issues in environments with SELinux/AppArmor file labels or macOS systems where quarantine bits or Finder metadata are attached to files.
Proposed fix
For environments that require ACL/xattr preservation, use platform-specific copy APIs (e.g.,
copyfile(3)on macOS,copy_file_range+setxattron Linux) to transfer attributes from the original to the temp file before rename.References