artifactize-foundation 0.27.2

Native file, path and executable primitives for Artifactize.
Documentation
//! Owner-only files and directories, with native file identity.

mod directory;
pub(super) use directory::ScratchParent;
pub use directory::{
    PrivateTempDir, create_private_dir_all, private_named_dir, private_tempdir_in,
};
#[cfg(target_os = "macos")]
pub(super) mod macos;
mod pinned;
#[cfg(unix)]
mod unix;
#[cfg(windows)]
mod windows;
pub use pinned::{PinnedDir, PinnedFile, open_workspace_file};

#[cfg(unix)]
pub use unix::*;
#[cfg(windows)]
pub use windows::{
    PRIVATE_DIRECTORY, PRIVATE_FILE, create_private_dir, create_private_file, file_identity,
    is_owner_only, is_private_dir, is_private_file, private_options, remove_tree, restrict_file,
    sync_dir, user_identity,
};

#[cfg(windows)]
pub use windows::Local as OwnerDescriptor;

#[cfg(windows)]
pub fn owner_descriptor() -> std::io::Result<OwnerDescriptor> {
    windows::owner_only(false)
}

/// A file's stable identity on its volume, independent of path spelling.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct FileIdentity {
    volume: u64,
    index: u128,
}

impl FileIdentity {
    /// The volume and object identifiers, for a lease keyed by the object rather than its name.
    pub fn parts(self) -> (u64, u128) {
        (self.volume, self.index)
    }
}

/// Admit the same literal scratch names on every host, including after suffixing a prefix.
fn checked_basename(name: &str) -> std::io::Result<()> {
    if !super::files::portable_basename(name) {
        return Err(std::io::ErrorKind::InvalidInput.into());
    }
    Ok(())
}

#[cfg(test)]
mod tests;