pub struct FileSnapshot { /* private fields */ }Expand description
A pre-operation snapshot that can prove whether a file’s contents changed.
Most filesystems provide a stable metadata-change token, so the inexpensive identity is sufficient. Linux NFS can reconcile client and server timestamps after a writer has closed the file, making two metadata reads disagree without any intervening write. Those files carry a content digest instead, while retaining length and file identity to detect replacement. Callers use the same comparison either way and do not need to know which filesystem supplied the file.
Implementations§
Source§impl FileSnapshot
impl FileSnapshot
Sourcepub fn capture(path: &Path) -> Result<Option<Self>>
pub fn capture(path: &Path) -> Result<Option<Self>>
Capture the strongest comparison the file’s filesystem can support.
Sourcepub fn capture_with_cache(
path: &Path,
digests: &dyn FileDigestCache,
) -> Result<Option<Self>>
pub fn capture_with_cache( path: &Path, digests: &dyn FileDigestCache, ) -> Result<Option<Self>>
Capture a snapshot while reusing or publishing a content digest through the session ledger when the filesystem requires one.
Sourcepub fn capture_content_with_cache(
path: &Path,
digests: &dyn FileDigestCache,
) -> Result<Option<Self>>
pub fn capture_content_with_cache( path: &Path, digests: &dyn FileDigestCache, ) -> Result<Option<Self>>
Capture a content-backed snapshot whatever the filesystem, for a file whose metadata is expected to change without its bytes.
A compiler artifact is one: rustc hardlinks the .rmeta it just
emitted into its incremental session directory when it finishes, which
bumps the change token of a file a pipelined dependent is already
reading. Comparing the bytes, length, and file object instead accepts
that and still rejects a replacement or a rewrite.
Sourcepub fn matches(
&self,
identity: Option<&FileIdentity>,
content: &CacheDigest,
) -> bool
pub fn matches( &self, identity: Option<&FileIdentity>, content: &CacheDigest, ) -> bool
Whether identity and content still describe this snapshot.
A content-backed snapshot ignores both timestamps: NFS can reconcile mtime as well as ctime without a content change. Matching endpoint digests cannot detect an intervening edit that restores the original bytes. Digest-cache lookup still uses timestamps to decide when a digest needs refreshing; this comparison performs no additional reads.
Sourcepub fn proves_content_change(&self) -> bool
pub fn proves_content_change(&self) -> bool
Whether a mismatch proves the file’s contents changed.