pub struct WriteTarget(/* private fields */);Expand description
A write target the city has cleared: no alias at the name or at any directory above it, so a write here lands exactly where the name says.
The invariant lives at the one constructor and the field is private,
so an unchecked path cannot be spelled - every write face takes this
value and nothing else (trybuild tests/ui/write_target.rs). What
the value proves is that the name held no alias at the moment
at asked; the window between that question and the write is the
filesystem’s, which is why the walking faces ask the same rule at
their own sampling point.
Implementations§
Source§impl WriteTarget
impl WriteTarget
Sourcepub fn at(op: &'static str, path: &Path) -> Result<WriteTarget, StorageError>
pub fn at(op: &'static str, path: &Path) -> Result<WriteTarget, StorageError>
The one constructor: path and every directory above it are
examined, and any alias refuses the write whole.
§Errors
StorageError::Alias naming the alias and its kind;
StorageError::Io when a component exists and cannot be examined.
Sourcepub fn within(
op: &'static str,
root: &Path,
path: &Path,
) -> Result<WriteTarget, StorageError>
pub fn within( op: &'static str, root: &Path, path: &Path, ) -> Result<WriteTarget, StorageError>
Clears path for a write inside root, the directory the person
chose: path and every directory between it and root are
examined, and root and everything above it are not, because
where a person keeps a city is their placement rather than a
write a run could redirect (crates/storage/spec/Bundle.lean §8-12). A path outside
root is examined up to the filesystem root, as WriteTarget::at
does.
The bound is found by comparing path components as spelled, so the
caller builds path by joining onto the same root it passes; a
root in another spelling (a trailing separator, a . component,
other case on Windows) is not found, and the walk falls back to the
filesystem root, which is safe but loses the bound.
§Errors
As WriteTarget::at, for an alias at or below the bound.
pub fn as_path(&self) -> &Path
Sourcepub fn replace(self, bytes: &[u8]) -> Result<(), StorageError>
pub fn replace(self, bytes: &[u8]) -> Result<(), StorageError>
Replaces the file at this name with bytes: a staging file
beside it, flushed, given the replaced file’s permissions and
renamed over the name (crates/storage/Spec.lean §8-12, §8-32). A reader finds
the old file or the whole new one.
§Errors
StorageError::Io for a write, flush, permission copy or rename
the filesystem refuses; the name keeps its previous content.
Sourcepub fn create(self, bytes: &[u8]) -> Result<(), StorageError>
pub fn create(self, bytes: &[u8]) -> Result<(), StorageError>
Creates the file at this name only when nothing stands there:
the name is claimed by the filesystem at the moment of the write,
so of two racing creates one succeeds (crates/storage/spec/Alias.lean §8-32).
§Errors
StorageError::NameTaken when anything stands at the name, with
nothing written; StorageError::Io for a create, write or flush
the filesystem refuses.