pub struct ScopedPath(/* private fields */);Expand description
A path the scope let through: canonical, inside a granted folder (or a file dropped this session), not sensitive.
Only ScopeStore::resolve and crate::access::Access::resolve make one, so a function that takes a ScopedPath
can never be handed a path the scope did not see. A read goes through ScopedPath::open, which confirms that the
opened file is still this one.
use krizaka_rust::scope::ScopeStore;
let dir = tempfile::tempdir()?;
let home = dir.path().canonicalize()?;
std::fs::create_dir(home.join("docs"))?;
std::fs::write(home.join("docs/a.txt"), "hello")?;
let mut scope = ScopeStore::default();
scope.grant_with_home(&home.join("docs"), Some(&home))?;
let file = scope.resolve_with_home(&home.join("docs/a.txt"), Some(&home))?;
assert_eq!(krizaka_rust::files::preview(&file, &Default::default())?.text.as_deref(), Some("hello"));It cannot be made from a bare path:
let _ = krizaka_rust::scope::ScopedPath(std::path::PathBuf::from("/etc/hosts"));Implementations§
Source§impl ScopedPath
impl ScopedPath
pub fn as_path(&self) -> &Path
pub fn into_path_buf(self) -> PathBuf
Sourcepub fn open(&self) -> Result<File, ScopeError>
pub fn open(&self) -> Result<File, ScopeError>
Opens the file once, read only, and confirms the descriptor is the file the scope let through.
The path may have changed since it was resolved: the file, or one of its parent folders, swapped for a link out of the grant. The last component is opened without following a link, and the system is asked where the opened file really is; anything but the resolved path is refused. Read the metadata and the content from the returned file, never from the path again.