Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Format: build on FreeBSD (rustix has no xattr calls there)

Brandon Thomas8ede07b096af
diff --git a/crates/automation/src/workspace.rs b/crates/automation/src/workspace.rs
index 77f728ce0..99dedac77 100644
--- a/crates/automation/src/workspace.rs
+++ b/crates/automation/src/workspace.rs
@@ -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")]
diff --git a/crates/format/src/atomic/meta.rs b/crates/format/src/atomic/meta.rs
index 6c7cfbc21..10008faa9 100644
--- a/crates/format/src/atomic/meta.rs
+++ b/crates/format/src/atomic/meta.rs
@@ -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 {
diff --git a/crates/format/src/atomic/meta/tests.rs b/crates/format/src/atomic/meta/tests.rs
index 5c8f08c6b..834e87e66 100644
--- a/crates/format/src/atomic/meta/tests.rs
+++ b/crates/format/src/atomic/meta/tests.rs
@@ -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)