pub struct BinaryCache { /* private fields */ }Expand description
On-disk cache for downloaded upgrade binaries.
Implementations§
Source§impl BinaryCache
impl BinaryCache
Sourcepub fn new(cache_dir: PathBuf) -> Self
pub fn new(cache_dir: PathBuf) -> Self
Create a new binary cache backed by the given directory.
Sourcepub fn cached_binary_path(&self, version: &str) -> PathBuf
pub fn cached_binary_path(&self, version: &str) -> PathBuf
Return the path where a cached binary for version would be stored.
Sourcepub fn get_verified(&self, version: &str) -> Option<PathBuf>
pub fn get_verified(&self, version: &str) -> Option<PathBuf>
Return the cached binary path if it exists and its SHA-256 matches
the stored metadata. Returns None on any mismatch or error.
Sourcepub fn store(&self, version: &str, source_path: &Path) -> Result<()>
pub fn store(&self, version: &str, source_path: &Path) -> Result<()>
Store a binary in the cache.
Uses a write-to-temp-then-rename strategy so that readers never
observe partially written files. The metadata file is written last
so that get_verified only succeeds once both files are complete.
§Errors
Returns an error if the binary cannot be read or the cache files cannot be written.
Sourcepub fn acquire_download_lock(&self) -> Result<DownloadLockGuard>
pub fn acquire_download_lock(&self) -> Result<DownloadLockGuard>
Acquire an exclusive download lock and return the guard.
This prevents multiple nodes from downloading the same archive concurrently — the first acquires the lock and downloads, the rest wait and then find the binary already cached.
The lock is released when the returned guard is dropped.
Note: lock_exclusive() blocks the calling thread. Callers in
async contexts should wrap this call in tokio::task::spawn_blocking.
§Errors
Returns an error if the lock file cannot be created or acquired.
Trait Implementations§
Source§impl Clone for BinaryCache
impl Clone for BinaryCache
Source§fn clone(&self) -> BinaryCache
fn clone(&self) -> BinaryCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BinaryCache
impl RefUnwindSafe for BinaryCache
impl Send for BinaryCache
impl Sync for BinaryCache
impl Unpin for BinaryCache
impl UnsafeUnpin for BinaryCache
impl UnwindSafe for BinaryCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more