Skip to content

atomic_write_file: rename-based write does not preserve platform ACLs, xattrs, or owner/group #226

Description

@dean0x

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

  1. ACLs lost on macOS/Linux: Extended ACL entries on the original file are not copied to the temp file before rename.
  2. xattrs lost: Extended attributes (used by macOS Finder metadata, security.selinux on SELinux/AppArmor, etc.) are not copied to the temp file.
  3. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions