artifactize-foundation 0.27.1

Native file, path and executable primitives for Artifactize.
Documentation
use super::*;

#[test]
fn scratch_names_are_literal_children_on_every_host() {
    let root = tempfile::tempdir().unwrap();
    for name in [
        "../other",
        "..\\other",
        "/other",
        "C:other",
        "item:stream",
        "a\0b",
        "NUL.txt",
    ] {
        assert_eq!(
            private_named_dir(root.path(), name).err().unwrap().kind(),
            std::io::ErrorKind::InvalidInput
        );
        assert_eq!(
            private_tempdir_in(name, root.path()).err().unwrap().kind(),
            std::io::ErrorKind::InvalidInput
        );
    }
    for name in ["", ".", "..", "name.", "name ", "COM².log"] {
        assert_eq!(
            private_named_dir(root.path(), name).err().unwrap().kind(),
            std::io::ErrorKind::InvalidInput
        );
    }
    let directory = private_named_dir(root.path(), "a literal name").unwrap();
    assert_eq!(directory.path().file_name().unwrap(), "a literal name");
}

// Protecting ancestors from other OS users is outside FND-PRIVATE: a shared,
// non-sticky ancestor still yields an owner-only scratch directory.
#[cfg(unix)]
#[test]
fn shared_ancestor_still_yields_owner_only_scratch() {
    use std::{fs, os::unix::fs::PermissionsExt};
    let root = tempfile::tempdir().unwrap();
    let shared = root.path().join("shared");
    let nested = shared.join("nested");
    create_private_dir_all(&nested).unwrap();
    fs::set_permissions(&shared, fs::Permissions::from_mode(0o777)).unwrap();
    let lease = private_tempdir_in("protected-", &nested).unwrap();
    assert!(is_private_dir(lease.path()).unwrap());
    let kept = lease.keep().unwrap();
    assert!(is_private_dir(&kept).unwrap());
    fs::remove_dir(kept).unwrap();
}

// Unix can make an owned directory inaccessible even to its owner through mode bits.
#[cfg(unix)]
#[test]
fn recursive_creation_restores_owner_access_but_does_not_follow_a_link() {
    use std::{fs, os::unix::fs::PermissionsExt};

    let root = tempfile::tempdir().unwrap();
    let shared = root.path().join("shared parent");
    crate::platform::tests::shared_directory(&shared);
    let legacy = shared.join("legacy");
    fs::create_dir(&legacy).unwrap();
    const NO_ACCESS: u32 = 0o000;
    fs::set_permissions(&legacy, fs::Permissions::from_mode(NO_ACCESS)).unwrap();
    let alias = shared.join("alias");
    crate::platform::tests::directory_link(&legacy, &alias);
    assert!(create_private_dir_all(&alias.join(".")).is_err());
    assert!(!is_private_dir(&legacy).unwrap());
    create_private_dir_all(&legacy).unwrap();
    assert!(is_private_dir(&legacy).unwrap());
    assert!(!is_private_dir(&shared).unwrap());
    fs::write(legacy.join("new file"), b"owner writable").unwrap();
}