|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.jgit.storage.file.FileSnapshot
public class FileSnapshot
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 isModified(File)
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
isModified(File)
.
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 isModified(File) if the last modification time of the file is less than 3 seconds ago.
Field Summary | |
---|---|
static FileSnapshot |
DIRTY
A FileSnapshot that is considered to always be modified. |
static FileSnapshot |
MISSING_FILE
A FileSnapshot that is clean if the file does not exist. |
Method Summary | |
---|---|
boolean |
equals(FileSnapshot other)
Compare two snapshots to see if they cache the same information. |
boolean |
equals(Object other)
|
int |
hashCode()
|
boolean |
isModified(File path)
Check if the path may have been modified since the snapshot was saved. |
long |
lastModified()
|
static FileSnapshot |
save(File path)
Record a snapshot for a specific file path. |
static FileSnapshot |
save(long modified)
Record a snapshot for a file for which the last modification time is already known. |
void |
setClean(FileSnapshot other)
Update this snapshot when the content hasn't changed. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final FileSnapshot DIRTY
This instance is useful for application code that wants to lazily read a
file, but only after isModified(File)
gets invoked. The returned
snapshot contains only invalid status information.
public static final FileSnapshot MISSING_FILE
This instance is useful if the application wants to consider a missing
file to be clean. isModified(File)
will return false if the file
path does not exist.
Method Detail |
---|
public static FileSnapshot save(File path)
This method should be invoked before the file is accessed.
path
- the path to later remember. The path's current status
information is saved.
public static FileSnapshot save(long modified)
This method should be invoked before the file is accessed.
modified
- the last modification time of the file
public long lastModified()
public boolean isModified(File path)
path
- the path the snapshot describes.
public void setClean(FileSnapshot other)
If the caller gets true from isModified(File)
, re-reads the
content, discovers the content is identical, and
equals(FileSnapshot)
is true, it can use
setClean(FileSnapshot)
to make a future
isModified(File)
return false. The logic goes something like
this:
if (snapshot.isModified(path)) { FileSnapshot other = FileSnapshot.save(path); Content newContent = ...; if (oldContent.equals(newContent) && snapshot.equals(other)) snapshot.setClean(other); }
other
- the other snapshot.public boolean equals(FileSnapshot other)
other
- the other snapshot.
public boolean equals(Object other)
equals
in class Object
public int hashCode()
hashCode
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |