mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Format: build on FreeBSD (rustix has no xattr calls there)
The 0.11.0 release's FreeBSD job failed: copy_xattrs used rustix's fsetxattr/flistxattr/fgetxattr, which rustix offers only on Linux, Android and Apple systems. The real copy is now gated to those, and other Unix systems get a no-op copy_xattrs, as Windows has. The xattr tests are gated the same way; the Unix mode test now also checks that no temporary file is left behind. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
cd79a5a9e8
commit
8ede07b096
3 files changed
+17
-9
No files matched your search
@@ -591,7 +591,7 @@ mod tests {
|
||||
|
||||
/// #7095: replacing a file through the automation path keeps the old file's extended
|
||||
/// attributes, the same as a save through `atomic_write` does.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
#[test]
|
||||
fn write_keeps_the_replaced_files_extended_attributes() {
|
||||
#[cfg(target_os = "macos")]
|
||||
|
||||
@@ -32,17 +32,17 @@ use std::os::fd::BorrowedFd;
|
||||
|
||||
/// Largest attribute-name list [`copy_xattrs`] will read. Names are short; a file with a
|
||||
/// megabyte of them is not something a save should spend memory on.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
const MAX_XATTR_NAMES: usize = 1 << 20;
|
||||
|
||||
/// Largest single attribute value [`copy_xattrs`] will carry over. Finder tags and `user.*`
|
||||
/// attributes are tens of bytes; a resource fork can be large, and past this it is not worth
|
||||
/// holding a copy of it in memory during a save.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
const MAX_XATTR_VALUE: usize = 16 << 20;
|
||||
|
||||
/// First read size for an attribute list or value; grown on `ERANGE`.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
const XATTR_CHUNK: usize = 4 << 10;
|
||||
|
||||
/// Copy, best effort, everything [`crate::atomic::atomic_write`] should carry from the file it
|
||||
@@ -92,7 +92,7 @@ fn copy_xattrs_at(from: &Path, to: &Path) -> io::Result<()> {
|
||||
/// `com.apple.rootless` on macOS and `security.*` on Linux belong to the system and refuse to
|
||||
/// be written by an ordinary process, and failing a document save over one would be absurd.
|
||||
/// `Err` means the attribute *list* could not be read, so nothing was copied.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
pub fn copy_xattrs(from: BorrowedFd<'_>, to: BorrowedFd<'_>) -> io::Result<()> {
|
||||
use rustix::fs::{XattrFlags, fsetxattr};
|
||||
|
||||
@@ -106,9 +106,16 @@ pub fn copy_xattrs(from: BorrowedFd<'_>, to: BorrowedFd<'_>) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// [`copy_xattrs`] where rustix offers no extended-attribute calls (FreeBSD and the other BSDs):
|
||||
/// nothing is copied, as on Windows.
|
||||
#[cfg(all(unix, not(any(target_os = "linux", target_os = "android", target_vendor = "apple"))))]
|
||||
pub fn copy_xattrs(_from: BorrowedFd<'_>, _to: BorrowedFd<'_>) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Attributes that describe how the *old* file's bytes are stored rather than anything about
|
||||
/// the document, and so must never be pinned onto a file holding different bytes.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
fn skip_xattr(name: &[u8]) -> bool {
|
||||
// `com.apple.decmpfs` marks a file whose data lives compressed inside the attribute itself.
|
||||
// The kernel hides it from a plain `listxattr` and refuses to set it, but a file claiming
|
||||
@@ -117,7 +124,7 @@ fn skip_xattr(name: &[u8]) -> bool {
|
||||
}
|
||||
|
||||
/// The NUL-separated attribute names of `fd`.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
fn list_xattrs(fd: BorrowedFd<'_>) -> io::Result<Vec<u8>> {
|
||||
let mut buf = vec![0u8; XATTR_CHUNK];
|
||||
loop {
|
||||
@@ -137,7 +144,7 @@ fn list_xattrs(fd: BorrowedFd<'_>) -> io::Result<Vec<u8>> {
|
||||
/// The value of one attribute, or `None` if it cannot be read or is larger than
|
||||
/// [`MAX_XATTR_VALUE`]. A missing value is normal: another process may remove an attribute
|
||||
/// between the listing and the read.
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
fn read_xattr(fd: BorrowedFd<'_>, name: &[u8]) -> Option<Vec<u8>> {
|
||||
let mut buf = vec![0u8; XATTR_CHUNK];
|
||||
loop {
|
||||
|
||||
@@ -36,7 +36,7 @@ fn assert_no_temp(dir: &Path) {
|
||||
|
||||
// ---------------------------------------------------------------- extended attributes (Unix)
|
||||
|
||||
#[cfg(unix)]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
mod xattrs {
|
||||
use super::*;
|
||||
|
||||
@@ -164,6 +164,7 @@ fn replacing_a_file_keeps_its_mode() {
|
||||
atomic_write(&p, b"second").unwrap();
|
||||
|
||||
assert_eq!(std::fs::metadata(&p).unwrap().permissions().mode() & 0o777, 0o600);
|
||||
assert_no_temp(&d.0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- ACL (macOS)
|
||||
|
||||
Reference in new issue
Block a user