Skip to content

Commit ffaeafc

Browse files
committed
add possibility to lock file types or complete repository
1 parent 2a06815 commit ffaeafc

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

crates/core/src/commands/lock.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::{
2323
progress::{Progress, ProgressBars},
2424
repofile::{IndexFile, SnapshotFile},
2525
repository::{Open, Repository},
26+
ALL_FILE_TYPES,
2627
};
2728

2829
pub(super) mod constants {
@@ -163,6 +164,29 @@ impl LockOptions {
163164
}
164165
}
165166

167+
pub fn lock_repo<P: ProgressBars, S>(
168+
repo: &Repository<P, S>,
169+
until: Option<DateTime<Local>>,
170+
) -> RusticResult<()> {
171+
for file_type in ALL_FILE_TYPES {
172+
lock_all_files(repo, file_type, until)?
173+
}
174+
Ok(())
175+
}
176+
177+
pub fn lock_all_files<P: ProgressBars, S>(
178+
repo: &Repository<P, S>,
179+
file_type: FileType,
180+
until: Option<DateTime<Local>>,
181+
) -> RusticResult<()> {
182+
let p = &repo
183+
.pb
184+
.progress_spinner(format!("losting {file_type:?} files.."));
185+
let ids: Vec<_> = repo.list(file_type)?.collect();
186+
p.finish();
187+
lock_files(repo, file_type, &ids, until)
188+
}
189+
166190
fn lock_files<P: ProgressBars, S>(
167191
repo: &Repository<P, S>,
168192
file_type: FileType,

crates/core/src/repository.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
};
1111

1212
use bytes::Bytes;
13-
use chrono::Local;
13+
use chrono::{DateTime, Local};
1414
use derive_setters::Setters;
1515
use log::{debug, error, info};
1616
use serde_with::{serde_as, DisplayFromStr};
@@ -38,7 +38,7 @@ use crate::{
3838
copy::CopySnapshot,
3939
forget::{ForgetGroups, KeepOptions},
4040
key::KeyOptions,
41-
lock::LockOptions,
41+
lock::{lock_all_files, lock_repo, LockOptions},
4242
prune::{PruneOptions, PrunePlan},
4343
repair::{index::RepairIndexOptions, snapshots::RepairSnapshotsOptions},
4444
repoinfo::{IndexInfos, RepoFileInfos},
@@ -1060,6 +1060,37 @@ impl<P: ProgressBars, S: Open> Repository<P, S> {
10601060
opts.get_plan(self)
10611061
}
10621062

1063+
/// Lock the complete repository, i.e. everything in the storage backend.
1064+
///
1065+
/// # Arguments
1066+
///
1067+
/// * `until` - until when to lock. None means lock forever.
1068+
///
1069+
/// # Errors
1070+
///
1071+
// TODO: Document errors
1072+
pub fn lock_repo(&self, until: Option<DateTime<Local>>) -> RusticResult<()> {
1073+
lock_repo(self, until)
1074+
}
1075+
1076+
/// Lock all repository files of the given type
1077+
///
1078+
/// # Arguments
1079+
///
1080+
/// * `file_type` - the file type to lock
1081+
/// * `until` - until when to lock. None means lock forever.
1082+
///
1083+
/// # Errors
1084+
///
1085+
// TODO: Document errors
1086+
pub fn lock_repo_files(
1087+
&self,
1088+
file_type: FileType,
1089+
until: Option<DateTime<Local>>,
1090+
) -> RusticResult<()> {
1091+
lock_all_files(self, file_type, until)
1092+
}
1093+
10631094
/// Lock snapshot and pack files needed for the given snapshots
10641095
///
10651096
/// # Arguments
@@ -1071,7 +1102,7 @@ impl<P: ProgressBars, S: Open> Repository<P, S> {
10711102
/// # Errors
10721103
///
10731104
// TODO: Document errors
1074-
pub fn lock(&self, opts: &LockOptions, snaps: &[SnapshotFile]) -> RusticResult<()> {
1105+
pub fn lock_snaphots(&self, opts: &LockOptions, snaps: &[SnapshotFile]) -> RusticResult<()> {
10751106
let now = Local::now();
10761107
opts.lock(self, snaps, now)
10771108
}

0 commit comments

Comments
 (0)