diff --git a/crates/platform/src/temp.rs b/crates/platform/src/temp.rs index 9ac40da86..e2ece0b3c 100644 --- a/crates/platform/src/temp.rs +++ b/crates/platform/src/temp.rs @@ -121,18 +121,24 @@ fn check_plain(name: &str) -> std::io::Result<()> { /// `is_symlink()` is never true. // cadcraft: crates/ui-egui/src/control.rs:609 is_private_shot_dir pub fn is_private_dir(meta: &Metadata) -> bool { - if !meta.is_dir() || meta.file_type().is_symlink() { - return false; - } - #[cfg(unix)] - { - use std::os::unix::fs::PermissionsExt as _; - meta.permissions().mode() & 0o077 == 0 - } - #[cfg(not(unix))] - { - true - } + // A real directory, so nothing is followed, whose mode grants group and other nothing; the + // mode comes off this same snapshot, never a second stat. + meta.is_dir() && !meta.file_type().is_symlink() && has_private_mode(meta) +} + +/// The Unix half of [`is_private_dir`]: `meta`'s mode has no group or other permission bit. It +/// reads the mode off the same snapshot the caller was given, so it never stats another file. +#[cfg(unix)] +fn has_private_mode(meta: &Metadata) -> bool { + use std::os::unix::fs::PermissionsExt as _; + meta.permissions().mode() & 0o077 == 0 +} + +/// Without Unix mode bits, the documented fallback accepts a real directory once the caller has +/// rejected files and symlinks; this does not inspect or make a claim about platform ACLs. +#[cfg(not(unix))] +fn has_private_mode(_meta: &Metadata) -> bool { + true } /// Temporary folders the app owns until it is done with them: print previews open in the system diff --git a/crates/platform/src/temp_tests.rs b/crates/platform/src/temp_tests.rs index 71684bfae..386589df1 100644 --- a/crates/platform/src/temp_tests.rs +++ b/crates/platform/src/temp_tests.rs @@ -11,6 +11,9 @@ fn private_dir_is_owner_only_and_removed_on_drop() { let path = dir.path().to_path_buf(); assert!(is_private_dir(&std::fs::symlink_metadata(&path).unwrap())); let (file_path, _file) = dir.create("a.txt").unwrap(); + assert_eq!(file_path.file_name(), Some(std::ffi::OsStr::new("a.txt")), "the created path is the plain name, as asked"); + assert_eq!(file_path.parent(), Some(path.as_path()), "the file is created inside the private folder"); + assert!(std::fs::symlink_metadata(&file_path).is_ok(), "the file exists on disk on every platform"); #[cfg(unix)] { use std::os::unix::fs::PermissionsExt as _; diff --git a/crates/prepress/tests/flatten_write.rs b/crates/prepress/tests/flatten_write.rs index fc25a0107..d6e67a892 100644 --- a/crates/prepress/tests/flatten_write.rs +++ b/crates/prepress/tests/flatten_write.rs @@ -24,7 +24,11 @@ fn solid(r: Rect, tints: &[(InkId, f32)]) -> Item { } fn group(opacity: f32, children: Vec) -> Item { - Item::Group(GroupItem { + Item::Group(group_item(opacity, children)) +} + +fn group_item(opacity: f32, children: Vec) -> GroupItem { + GroupItem { opacity, blend: BlendMode::Normal, isolated: false, @@ -34,7 +38,7 @@ fn group(opacity: f32, children: Vec) -> Item { mask: None, actual_text: None, children, - }) + } } fn page(inks: InkSet, items: Vec) -> DisplayList { @@ -91,7 +95,7 @@ fn an_even_odd_clip_keeps_its_hole_written_or_flattened() { // Two nested squares drawn in the same direction: filled even-odd, the inner one is a hole. let mut ring = Rect::new(0.0, 0.0, 100.0, 100.0).to_path(0.1); ring.extend(Rect::new(25.0, 25.0, 75.0, 75.0).to_path(0.1)); - let Item::Group(half_black) = group(0.5, vec![solid(Rect::new(0.0, 0.0, 100.0, 100.0), &[(K, 1.0)])]) else { unreachable!() }; + let half_black = group_item(0.5, vec![solid(Rect::new(0.0, 0.0, 100.0, 100.0), &[(K, 1.0)])]); let clipped = Item::Group(GroupItem { clip: Some(ring), clip_rule: FillRule::EvenOdd, ..half_black }); let list = page(InkSet::new(), vec![solid(Rect::new(0.0, 0.0, 100.0, 100.0), &[(C, 1.0)]), clipped]); for written in [pdf(&list), flat_pdf(&list)] { diff --git a/crates/svg/src/tree/document_tests.rs b/crates/svg/src/tree/document_tests.rs index 4052f1a56..10dd6f225 100644 --- a/crates/svg/src/tree/document_tests.rs +++ b/crates/svg/src/tree/document_tests.rs @@ -321,7 +321,7 @@ fn elements_usvg_leaves_out_are_listed() { fn local_text_is_placed_and_bounded_in_its_parents_frame() { let mut options = usvg::Options::default(); let fonts = options.fontdb_mut(); - fonts.load_font_data(include_bytes!("../../../ui/tests/fonts/NotoSans-test.ttf").to_vec()); + fonts.load_font_data(include_bytes!("../../../ui-contract/tests/fonts/NotoSans-test.ttf").to_vec()); let family = fonts.faces().next().unwrap().families[0].0.clone(); let svg = format!( r#"Hi"# diff --git a/crates/update/src/packages.rs b/crates/update/src/packages.rs index 3561b7f0c..81725184a 100644 --- a/crates/update/src/packages.rs +++ b/crates/update/src/packages.rs @@ -223,8 +223,9 @@ pub(crate) fn oci_ref_available(reference: &str, expected: &version::Version, li } #[cfg(all(test, target_os = "linux", feature = "oci_migration"))] +#[allow(clippy::unwrap_used, reason = "tests fail by panicking")] mod migration_tests { - use super::*; + use super::{oci_ref_available, version}; use craft_ui::testing::trial; #[trial] diff --git a/crates/update/src/updater.rs b/crates/update/src/updater.rs index 19cb40371..11986ce7e 100644 --- a/crates/update/src/updater.rs +++ b/crates/update/src/updater.rs @@ -1068,7 +1068,7 @@ fn prompt_id() -> craft_ui::dialog::DialogId { dialog_id("updateDialog.prompt") } -#[cfg(feature = "screen-testing")] +#[cfg(any(test, feature = "screen-testing"))] impl Updater { /// Waits for the running check's answer on its channel (its thread always sends one, or ends /// and closes the channel), then hands it to `tick` as a pass would; then does the same for diff --git a/crates/window/src/desktop.rs b/crates/window/src/desktop.rs index 599cd3772..f49fc6d45 100644 --- a/crates/window/src/desktop.rs +++ b/crates/window/src/desktop.rs @@ -67,11 +67,11 @@ pub fn theme_svgs(theme: &str, icons: [&str; N]) -> [Option Option { let mut inside = false; @@ -25,7 +25,7 @@ pub(crate) fn ini_value(text: &str, section: &str, key: &str) -> Option None } -#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", test))] +#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] /// KWin's button order (`[org.kde.kdecoration2]` `ButtonsOnLeft` / `ButtonsOnRight`, one letter a /// button: `I` minimize, `A` maximize, `X` close) as a GTK layout string. Missing keys keep KWin's /// defaults: the window menu on the left, minimize, maximize and close on the right. @@ -46,7 +46,7 @@ pub(crate) fn kwin_layout(kwinrc: &str) -> String { format!("{}:{}", side("ButtonsOnLeft", "MS"), side("ButtonsOnRight", "HIAX")) } -#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", test))] +#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] /// The `gtk-decoration-layout` and `gtk-theme-name` of a GTK 3 `settings.ini`. pub(crate) fn gtk_settings(settings_ini: &str) -> (Option, Option) { (ini_value(settings_ini, "Settings", "gtk-decoration-layout"), ini_value(settings_ini, "Settings", "gtk-theme-name")) @@ -219,7 +219,7 @@ pub(crate) fn read_gtk_theme(var: &dyn Fn(&str) -> Option) -> Option String {