Xgit v0.2.5 Xgit.Util.FileSnapshot View Source
Caches when a file was last read, making it possible to detect future edits.
This object tracks the last modified time of a file. Later during an
invocation of modified?/2
the object will return true
if the file may have
been modified and should be re-read from disk.
A snapshot does not "live update" when the underlying filesystem changes.
Callers must poll for updates by periodically invoking modified?/2
.
To work around the "racy git" problem (where a file may be modified multiple
times within the granularity of the filesystem modification clock) this class
may return true
from modified?/2
if the last modification time of the
file is less than 3 seconds ago.
Link to this section Summary
Functions
An Xgit.Util.FileSnapshot
that is considered to always be modified.
An Xgit.Util.FileSnapshot
that is clean if the file does not exist.
Return true
if the path may have been modified since the snapshot was saved.
Record a snapshot for a specific file path.
Update this snapshot when the content hasn't changed.
Link to this section Types
Cache for when a file was last saved.
Struct Members
last_modified
: Last observed modification time of the path.ref
: Reference into a cache for when this file was last read.
Link to this section Functions
An Xgit.Util.FileSnapshot
that is considered to always be modified.
This instance is useful for application code that wants to lazily read a
file, but only after modified?/2
gets invoked. This snapshot instance
contains only invalid status information.
An Xgit.Util.FileSnapshot
that is clean if the file does not exist.
This instance is useful if the application wants to consider a missing
file to be clean. modified?/2
will return false
if the file path
does not exist.
Return true
if the path may have been modified since the snapshot was saved.
Record a snapshot for a specific file path.
This function should be invoked before the file is accessed.
Update this snapshot when the content hasn't changed.
If the caller gets true
from modified?/2
, re-reads the content, discovers
the content is identical, it can use to make a future call to modified?/2
return false
.
A typical invocation looks something like this:
new_snapshot =
if FileSnapshot.modified?(snapshot, path) do
other = FileSnapshot.save(path)
if old_content_matches_new_content? and snapshot.last_modified == other.last_modified do
FileSnapshot.set_clean(snapshot, other)
else
snapshot
end
else
snapshot
end
Return Value
:ok