artifactize-foundation 0.27.0

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

#[test]
fn lookup_probe_distinguishes_case_aliases_from_distinct_hard_links() {
    let scratch = tempfile::tempdir().unwrap();
    let directory = files::open_directory(scratch.path()).unwrap();
    assert_eq!(probe_case_sensitive(&directory).unwrap(), None);
    let named = scratch.path().join("Entry");
    let alternate = scratch.path().join("entry");
    fs::write(&named, b"test entry").unwrap();
    let native_sensitive = !alternate.try_exists().unwrap();
    assert_eq!(
        probe_case_sensitive(&directory).unwrap(),
        Some(native_sensitive)
    );
    if native_sensitive {
        fs::hard_link(named, alternate).unwrap();
        assert_eq!(probe_case_sensitive(&directory).unwrap(), Some(true));
    }
}

#[test]
fn empty_directory_probe_removes_its_disposable_entry() {
    let scratch = tempfile::tempdir().unwrap();
    let directory = files::open_directory(scratch.path()).unwrap();
    let sample = scratch.path().join("NewName");
    fs::create_dir(&sample).unwrap();
    let native_sensitive = !scratch.path().join("newname").try_exists().unwrap();
    fs::remove_dir(&sample).unwrap();

    assert_eq!(probe_new_name(&directory).unwrap(), Some(native_sensitive));
    assert!(fs::read_dir(scratch.path()).unwrap().next().is_none());
}

#[test]
fn empty_mount_policies_respect_the_driver_options() {
    // mountinfo includes escaped paths, optional propagation fields and superblock options.
    let mounts = "45 31 0:10 / /media/FAT\\040default rw - vfat /dev/sdb1 rw,utf8\n\
                  46 31 0:11 / /media/FAT-strict rw shared:3 - vfat /dev/sdb2 rw,check=s\n\
                  47 31 0:12 / /media/NTFS-default rw - ntfs3 /dev/sdb3 rw\n\
                  48 31 0:13 / /media/NTFS-insensitive rw - ntfs3 /dev/sdb4 rw,nocase\n\
                  49 31 0:14 / /media/SMB-default rw - cifs //host/share rw,vers=3.1.1\n\
                  50 31 0:15 / /media/SMB-insensitive rw - smb3 //host/share rw,nocase";
    assert_eq!(mount_policy(mounts, 45, FAT_MAGIC), Some(false));
    assert_eq!(mount_policy(mounts, 46, FAT_MAGIC), Some(true));
    assert_eq!(mount_policy(mounts, 47, NTFS_MAGIC), Some(true));
    assert_eq!(mount_policy(mounts, 48, NTFS_MAGIC), Some(false));
    assert_eq!(mount_policy(mounts, 49, CIFS_MAGIC), None);
    assert_eq!(mount_policy(mounts, 50, SMB2_MAGIC), Some(false));
    assert_eq!(mount_policy(mounts, 51, SMB2_MAGIC), None);
}

#[test]
fn volume_upcase_does_not_strip_accents_or_expand_letters() {
    let key = |name| NamePolicy::Upcase.key(OsStr::new(name)).unwrap();
    assert_eq!(key("Café"), key("CAFÉ"));
    assert_ne!(key("Café"), key("Cafe"));
    assert_ne!(key("Café"), key("Cafe\u{301}"));
    assert_ne!(key("Straße"), key("STRASSE"));
}