Locus
Metadata and Permissions
Typed metadata and POSIX bit helpers, without automatic identity authorization.
FileMetadata describes files, directories and symlinks. PermissionMode masks to the nine rwx bits and answers bit tests; these helper methods do not identify a current user or enforce an authorization decision. Runtime write hooks require the policy-hooks feature and an installed LocusPolicy. Governance strings and metadata modes alone are not a capability check.
This example is checked against source signatures; it was not compiled or run during this documentation pass.
use locus::{EntryType, FileMetadata, PermissionMode};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// FileMetadata models a file, directory, or symlink. Each constructor seeds
// creation/modified/accessed timestamps and a version starting at 1.
let dir_meta = FileMetadata::new_directory(0o755);
let file_meta = FileMetadata::new_file(1024, 0o640, [0u8; 32]);
let link_meta = FileMetadata::new_symlink("/etc/hosts".to_string(), 0o777);
assert_eq!(dir_meta.entry_type, EntryType::Directory);
assert!(file_meta.is_file());
assert!(link_meta.is_symlink());
// PermissionMode masks the raw u32 to the 9 POSIX rwxrwxrwx bits and offers
// typed predicates so callers don't bit-twiddle constants at the call site.
let mode = PermissionMode::new(file_meta.mode);
assert!(mode.owner_can_read());
assert!(mode.owner_can_write());
assert!(!mode.other_can_write());
println!(
"dir mode={:o} file size={} blob_id_set={} link target={:?}",
dir_meta.mode,
file_meta.size,
file_meta.blob_id.is_some(),
link_meta.symlink_target,
);
Ok(())
}