To modify a ref file Git tries to use an atomic update approach: we write the new data into a brand new file, then rename it in place over the old name. This way we can just delete the temporary file if anything goes wrong, and nothing has been damaged. To coordinate access from multiple processes at once Git tries to atomically create the new temporary file under a well-known name.
| Modifier and Type | Field and Description |
|---|---|
| private FileSnapshot | |
| pack-priv static final FilenameFilter | FILTER
Filter to skip over active lock files when listing a directory. |
| private boolean | |
| private boolean | |
| private boolean | |
| private final File | |
| private static final Logger | |
| private boolean | |
| private FileOutputStream | |
| private final File | |
| private ShutdownHook. | |
| private boolean | |
| private FS. | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public boolean | Returns: true if the commit was successful and the file contains the new data; false if the commit failed and the file remains with the old data.Commit this change and release the lock. |
| public void | |
| public void | |
| private FS. | |
| private FS. | |
| public Instant | Returns: modification time of the lock file right before we committed it.Get the modification time of the output file when it was committed. |
| public FileSnapshot | Returns: get theFileSnapshot just before commit.Get the |
| pack-priv static File | Returns: lock filegiven file file)Get the lock file corresponding to the given file. |
| public OutputStream | Returns: a stream to write to the new file. The stream is unbuffered.Obtain the direct output stream for this lock. |
| private FileOutputStream | |
| pack-priv boolean | |
| public boolean | Returns: true if the lock is now held by the caller; false if it is held by someone else.Try to establish the lock. |
| public boolean | Returns: true if the lock is now held by the caller; false if it is held by someone else.Try to establish the lock for appending. |
| pack-priv void | |
| private void | |
| public void | |
| public void | setNeedSnapshot(boolean
true if the commit method must remember the FileSnapshot. on)Request that |
| public void | setNeedSnapshotNoConfig(boolean
true if the commit method must remember the FileSnapshot. on)Request that |
| public void | setNeedStatInformation(boolean
true if the commit method must remember the modification time. on)Request that |
| public String | |
| public static boolean | Returns: true if unlocked, false if unlocking faileda file)java. object.Unlock the given file. |
| public void | |
| public void | |
| public void | |
| public void | write(byte[]
the bytes to store in the temporary file. No additional bytes
are added, so if the file must end with an LF it must appear
at the end of the byte array. content)Write arbitrary data to the temporary file. |
| commitSnapshot | back to summary |
|---|---|
| private FileSnapshot commitSnapshot | |
| FILTER | back to summary |
|---|---|
| pack-priv static final FilenameFilter FILTER Filter to skip over active lock files when listing a directory. | |
| fsync | back to summary |
|---|---|
| private boolean fsync | |
| haveLck | back to summary |
|---|---|
| private boolean haveLck | |
| isAppend | back to summary |
|---|---|
| private boolean isAppend | |
| lck | back to summary |
|---|---|
| private final File lck | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| needSnapshot | back to summary |
|---|---|
| private boolean needSnapshot | |
| os | back to summary |
|---|---|
| private FileOutputStream os | |
| ref | back to summary |
|---|---|
| private final File ref | |
| shutdownListener | back to summary |
|---|---|
| private ShutdownHook. | |
| snapshotNoConfig | back to summary |
|---|---|
| private boolean snapshotNoConfig | |
| token | back to summary |
|---|---|
| private FS. | |
| written | back to summary |
|---|---|
| private boolean written | |
| LockFile | back to summary |
|---|---|
| public LockFile(File f) Create a new lock for any file.
| |
| closeToken | back to summary |
|---|---|
| private void closeToken() | |
| commit | back to summary |
|---|---|
| public boolean commit() Commit this change and release the lock. If this method fails (returns false) the lock is still released.
| |
| copyCurrentContent | back to summary |
|---|---|
| public void copyCurrentContent() throws IOException Copy the current file content into the temporary file. This method saves the current file content by inserting it into the temporary file, so that the caller can safely append rather than replace the primary file. This method does nothing if the current file does not exist, or exists but is empty.
| |
| createCommitSnapshot | back to summary |
|---|---|
| public void createCommitSnapshot() Update the commit snapshot This may be necessary if you need time stamp before commit occurs, e.g while writing the index. | |
| createLockFile | back to summary |
|---|---|
| private FS. | |
| createLockFileWithRetry | back to summary |
|---|---|
| private FS. | |
| getCommitLastModifiedInstant | back to summary |
|---|---|
| public Instant getCommitLastModifiedInstant() Get the modification time of the output file when it was committed.
| |
| getCommitSnapshot | back to summary |
|---|---|
| public FileSnapshot getCommitSnapshot() Get the
| |
| getLockFile | back to summary |
|---|---|
| pack-priv static File getLockFile(File file) Get the lock file corresponding to the given file. | |
| getOutputStream | back to summary |
|---|---|
| public OutputStream getOutputStream() Obtain the direct output stream for this lock.
The stream may only be accessed once, and only after
| |
| getStream | back to summary |
|---|---|
| private FileOutputStream getStream() throws IOException | |
| isLocked | back to summary |
|---|---|
| pack-priv boolean isLocked() | |
| lock | back to summary |
|---|---|
| public boolean lock() throws IOException Try to establish the lock.
| |
| lockForAppend | back to summary |
|---|---|
| public boolean lockForAppend() throws IOException Try to establish the lock for appending.
| |
| requireLock | back to summary |
|---|---|
| pack-priv void requireLock() | |
| saveStatInformation | back to summary |
|---|---|
| private void saveStatInformation() | |
| setFSync | back to summary |
|---|---|
| public void setFSync(boolean on) Request that
| |
| setNeedSnapshot | back to summary |
|---|---|
| public void setNeedSnapshot(boolean on) Request that
| |
| setNeedSnapshotNoConfig | back to summary |
|---|---|
| public void setNeedSnapshotNoConfig(boolean on) Request that
| |
| setNeedStatInformation | back to summary |
|---|---|
| public void setNeedStatInformation(boolean on) Request that
This is an alias for
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| unlock | back to summary |
|---|---|
| public static boolean unlock(File file) Unlock the given file.
This method can be used for recovering from a thrown
| |
| unlock | back to summary |
|---|---|
| public void unlock() Unlock this file and abort this change. The temporary file (if created) is deleted before returning. | |
| waitForStatChange | back to summary |
|---|---|
| public void waitForStatChange() throws InterruptedException Wait until the lock file information differs from the old file. This method tests the last modification date. If both are the same, this method sleeps until it can force the new lock file's modification date to be later than the target file.
| |
| write | back to summary |
|---|---|
| public void write(ObjectId id) throws IOException Write an ObjectId and LF to the temporary file.
| |
| write | back to summary |
|---|---|
| public void write(byte[] content) throws IOException Write arbitrary data to the temporary file.
| |