Skip to content

Commit

Permalink
impl locking methode for derived backends and check capabilities in l…
Browse files Browse the repository at this point in the history
…ock commands
  • Loading branch information
aawsome committed Sep 28, 2024
1 parent 812f152 commit 39691dd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions crates/core/src/backend/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{

use anyhow::Result;
use bytes::Bytes;
use chrono::{DateTime, Local};
use dirs::cache_dir;
use log::{trace, warn};
use walkdir::WalkDir;
Expand Down Expand Up @@ -210,6 +211,14 @@ impl WriteBackend for CachedBackend {
}
self.be.remove(tpe, id, cacheable)
}

fn can_lock(&self) -> bool {
self.be.can_lock()
}

fn lock(&self, tpe: FileType, id: &Id, until: Option<DateTime<Local>>) -> Result<()> {
self.be.lock(tpe, id, until)
}
}

/// Backend that caches data in a directory.
Expand Down
9 changes: 9 additions & 0 deletions crates/core/src/backend/dry_run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use bytes::Bytes;
use chrono::{DateTime, Local};
use zstd::decode_all;

use crate::{
Expand Down Expand Up @@ -156,4 +157,12 @@ impl<BE: DecryptFullBackend> WriteBackend for DryRunBackend<BE> {
self.be.remove(tpe, id, cacheable)
}
}

fn can_lock(&self) -> bool {
self.be.can_lock()

Check warning on line 162 in crates/core/src/backend/dry_run.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/backend/dry_run.rs#L161-L162

Added lines #L161 - L162 were not covered by tests
}

fn lock(&self, tpe: FileType, id: &Id, until: Option<DateTime<Local>>) -> Result<()> {
self.be.lock(tpe, id, until)

Check warning on line 166 in crates/core/src/backend/dry_run.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/backend/dry_run.rs#L165-L166

Added lines #L165 - L166 were not covered by tests
}
}
9 changes: 9 additions & 0 deletions crates/core/src/backend/hotcold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use anyhow::Result;
use bytes::Bytes;
use chrono::{DateTime, Local};

use crate::{
backend::{FileType, ReadBackend, WriteBackend},
Expand Down Expand Up @@ -98,4 +99,12 @@ impl WriteBackend for HotColdBackend {
}
Ok(())
}

fn can_lock(&self) -> bool {
self.be.can_lock()
}

fn lock(&self, tpe: FileType, id: &Id, until: Option<DateTime<Local>>) -> Result<()> {
self.be.lock(tpe, id, until)
}
}
17 changes: 16 additions & 1 deletion crates/core/src/commands/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
configfile::ConfigId, IndexFile, IndexId, KeyId, PackId, RepoId, SnapshotFile, SnapshotId,
},
repository::{Open, Repository},
BlobId, TreeId,
BlobId, TreeId, WriteBackend,
};

pub(super) mod constants {
Expand Down Expand Up @@ -52,6 +52,10 @@ impl LockOptions {
snapshots: &[SnapshotFile],
now: DateTime<Local>,
) -> RusticResult<()> {
if !repo.be.can_lock() {
return Err(CommandErrorKind::NoLockingConfigured.into());

Check warning on line 56 in crates/core/src/commands/lock.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/commands/lock.rs#L55-L56

Added lines #L55 - L56 were not covered by tests
}

let pb = &repo.pb;
let be = repo.dbe();

Check warning on line 60 in crates/core/src/commands/lock.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/commands/lock.rs#L59-L60

Added lines #L59 - L60 were not covered by tests

Expand Down Expand Up @@ -82,6 +86,10 @@ impl LockOptions {
snapshots: &[SnapshotFile],
now: DateTime<Local>,
) -> RusticResult<()> {
if !repo.be.can_lock() {
return Err(CommandErrorKind::NoLockingConfigured.into());

Check warning on line 90 in crates/core/src/commands/lock.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/commands/lock.rs#L89-L90

Added lines #L89 - L90 were not covered by tests
}

let mut new_snaps = Vec::new();
let mut remove_snaps = Vec::new();
let mut lock_snaps = Vec::new();

Check warning on line 95 in crates/core/src/commands/lock.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/commands/lock.rs#L93-L95

Added lines #L93 - L95 were not covered by tests
Expand Down Expand Up @@ -119,6 +127,9 @@ impl LockOptions {
index_files: Vec<(IndexId, IndexFile)>,
packs: &BTreeSet<PackId>,
) -> RusticResult<()> {
if !repo.be.can_lock() {
return Err(CommandErrorKind::NoLockingConfigured.into());

Check warning on line 131 in crates/core/src/commands/lock.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/commands/lock.rs#L130-L131

Added lines #L130 - L131 were not covered by tests
}
let mut lock_packs = Vec::new();
let mut remove_index = Vec::new();

Check warning on line 134 in crates/core/src/commands/lock.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/commands/lock.rs#L133-L134

Added lines #L133 - L134 were not covered by tests

Expand Down Expand Up @@ -182,6 +193,10 @@ pub fn lock_all_files<P: ProgressBars, S, ID: RepoId>(
repo: &Repository<P, S>,
until: Option<DateTime<Local>>,
) -> RusticResult<()> {
if !repo.be.can_lock() {
return Err(CommandErrorKind::NoLockingConfigured.into());

Check warning on line 197 in crates/core/src/commands/lock.rs

View check run for this annotation

Codecov / codecov/patch

crates/core/src/commands/lock.rs#L196-L197

Added lines #L196 - L197 were not covered by tests
}

let p = &repo
.pb
.progress_spinner(format!("listing {:?} files..", ID::TYPE));
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ pub enum CommandErrorKind {
PackIdNotFoundinIndex(PackId),
/// Blob Id {0:?} not found in index
BlobIdNotFoundinIndex(BlobId),
/// No locking capability configured for the backend
NoLockingConfigured,
}

/// [`CryptoErrorKind`] describes the errors that can happen while dealing with Cryptographic functions
Expand Down

0 comments on commit 39691dd

Please sign in to comment.