forked from radicle-dev/heartwood
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A `.keep` file in the `objects/pack` directory acts as a lock to ensure that operations like `git gc` do not clean up `.idx` files while a fetch is being performed. It is safe to remove the `.keep` file once a fetch has completed and a reference points to a given object in the packfile. To ensure this happens in `radicle-fetch`, a newtype `Keepfile` is introduced. It uses special `Drop` semantics by attempting to remove the file when the object is dropped -- logging a warning if it fails to do so. `FetchState` is augmented to keep a set of the `Keepfile`s. This ensures that when the fetch completes, either successfully or with a failure, when `FetchState` is dropped then so are the `Keepfile`s. We ensure that the expected behaviour of removing the `.keep`files occurs by adding a check in `e2e::test_replication` to check Alice's repository's packs. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
- Loading branch information
Showing
6 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub(crate) mod mem; | ||
pub(crate) mod repository; | ||
pub(crate) mod packfile; | ||
|
||
pub mod refs; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
/// The [`PathBuf`] which points to a `*.keep` file, which should correspond to | ||
/// a packfile. | ||
/// | ||
/// Upon drop, it attempts to remove the [`PathBuf`] to release the lock on the | ||
/// packfile index, allowing it to be garbage collected. | ||
#[derive(Clone, Debug)] | ||
pub struct Keepfile { | ||
path: PathBuf, | ||
} | ||
|
||
impl Keepfile { | ||
pub fn new<P: AsRef<Path>>(path: P) -> Option<Self> { | ||
let path = path.as_ref(); | ||
match path.extension() { | ||
Some(ext) if ext == "keep" => Some(Self { | ||
path: path.to_path_buf(), | ||
}), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
impl Drop for Keepfile { | ||
fn drop(&mut self) { | ||
if let Err(e) = fs::remove_file(&self.path) { | ||
log::warn!(target: "fetch", "Failed to remove {:?}: {e}", self.path); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters