Skip to content

Commit 1114e13

Browse files
committed
adapt init and docu
1 parent 6878626 commit 1114e13

File tree

3 files changed

+96
-41
lines changed

3 files changed

+96
-41
lines changed

crates/core/src/commands/init.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ pub(crate) fn init<P, S>(
4747
let repo_id = RepositoryId::from(Id::random());
4848
let chunker_poly = random_poly()?;
4949
let mut config = ConfigFile::new(2, repo_id, chunker_poly);
50-
if repo.be_hot.is_some() {
51-
// for hot/cold repository, `config` must be identical to thee config file which is read by the backend, i.e. the one saved in the hot repo.
52-
// Note: init_with_config does handle the is_hot config correctly for the hot and the cold repo.
53-
config.is_hot = Some(true);
54-
}
5550
config_opts.apply(&mut config)?;
5651

5752
let key = init_with_config(repo, pass, key_opts, &config)?;
@@ -60,7 +55,7 @@ pub(crate) fn init<P, S>(
6055
Ok((key, config))
6156
}
6257

63-
/// Save a [`ConfigFile`] only to the hot part of a repository
58+
/// Initialize a new repository using a given [`ConfigFile`]
6459
///
6560
/// # Type Parameters
6661
///
@@ -69,15 +64,18 @@ pub(crate) fn init<P, S>(
6964
///
7065
/// # Arguments
7166
///
72-
/// * `repo` - The repository to save the config to
73-
/// * `new_config` - The config to save
74-
/// * `key` - The key to encrypt the config with
67+
/// * `repo` - The repository to initialize.
68+
/// * `pass` - The password to encrypt the key with.
69+
/// * `key_opts` - The options to create the key with.
70+
/// * `config` - The config to use
7571
///
7672
/// # Errors
7773
///
78-
/// * [`CryptBackendErrorKind::SerializingToJsonByteVectorFailed`] - If the file could not be serialized to json.
74+
/// * If the file could not be serialized to json.
75+
///
76+
/// # Returns
7977
///
80-
/// [`CryptBackendErrorKind::SerializingToJsonByteVectorFailed`]: crate::error::CryptBackendErrorKind::SerializingToJsonByteVectorFailed
78+
/// The key used to encrypt the config.
8179
pub(crate) fn init_with_config<P, S>(
8280
repo: &Repository<P, S>,
8381
pass: &str,

crates/core/src/commands/repair/hotcold.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ use crate::{
1010
RusticResult, WriteBackend, ALL_FILE_TYPES,
1111
};
1212

13+
/// Repairs a hot/cold repository by copying missing files (except pack files) over from one to the other part.
14+
///
15+
/// # Type Parameters
16+
///
17+
/// * `P` - The progress bar type.
18+
/// * `S` - The state the repository is in.
19+
///
20+
/// # Arguments
21+
///
22+
/// * `repo` - The repository
23+
/// * `dry_run` - Do a dry run
1324
pub(crate) fn repair_hotcold<P: ProgressBars, S>(
1425
repo: &Repository<P, S>,
1526
dry_run: bool,
@@ -22,6 +33,17 @@ pub(crate) fn repair_hotcold<P: ProgressBars, S>(
2233
Ok(())
2334
}
2435

36+
/// Repairs a hot/cold repository by copying missing tree pack files over from one to the other part.
37+
///
38+
/// # Type Parameters
39+
///
40+
/// * `P` - The progress bar type.
41+
/// * `S` - The state the repository is in.
42+
///
43+
/// # Arguments
44+
///
45+
/// * `repo` - The repository
46+
/// * `dry_run` - Do a dry run
2547
pub(crate) fn repair_hotcold_packs<P: ProgressBars, S: Open>(
2648
repo: &Repository<P, S>,
2749
dry_run: bool,
@@ -35,6 +57,19 @@ pub(crate) fn repair_hotcold_packs<P: ProgressBars, S: Open>(
3557
)
3658
}
3759

60+
/// Copy relevant+misssing files in a hot/cold repository from one to the other part.
61+
///
62+
/// # Type Parameters
63+
///
64+
/// * `P` - The progress bar type.
65+
/// * `S` - The state the repository is in.
66+
///
67+
/// # Arguments
68+
///
69+
/// * `repo` - The repository
70+
/// * `file_type` - The filetype to copy
71+
/// * `is_relevalt` - A closure to determine whether the id is relevat
72+
/// * `dry_run` - Do a dry run
3873
pub(crate) fn correct_missing_files<P: ProgressBars, S>(
3974
repo: &Repository<P, S>,
4075
file_type: FileType,
@@ -91,6 +126,14 @@ pub(crate) fn correct_missing_files<P: ProgressBars, S>(
91126
Ok(())
92127
}
93128

129+
/// Copy a list of files from one repo to another.
130+
///
131+
/// # Arguments
132+
///
133+
/// * `files` - The list of file ids to copy
134+
/// * `file_type` - The filetype to copy
135+
/// * `from` - The backend to read from
136+
/// * `to` - The backend to write to
94137
fn copy(
95138
files: Vec<Id>,
96139
file_type: FileType,
@@ -104,6 +147,20 @@ fn copy(
104147
Ok(())
105148
}
106149

150+
/// Get all tree packs from from within the repository.
151+
///
152+
/// # Type Parameters
153+
///
154+
/// * `P` - The progress bar type.
155+
/// * `S` - The state the repository is in.
156+
///
157+
/// # Arguments
158+
///
159+
/// * `repo` - The repository
160+
///
161+
/// # Returns
162+
///
163+
/// The set of pack ids.
107164
pub(crate) fn get_tree_packs<P: ProgressBars, S: Open>(
108165
repo: &Repository<P, S>,
109166
) -> RusticResult<BTreeSet<PackId>> {
@@ -121,6 +178,22 @@ pub(crate) fn get_tree_packs<P: ProgressBars, S: Open>(
121178
Ok(tree_packs)
122179
}
123180

181+
/// Find missing files in the hot or cold part of the repository.
182+
///
183+
/// # Type Parameters
184+
///
185+
/// * `P` - The progress bar type.
186+
/// * `S` - The state the repository is in.
187+
///
188+
/// # Arguments
189+
///
190+
/// * `repo` - The repository
191+
/// * `file_type` - The filetype to use
192+
/// * `is_relevalt` - A closure to determine whether the id is relevat
193+
///
194+
/// # Returns
195+
///
196+
/// A tuple containing ids missing in hot part, the total size, ids missing in cold part and the corresponding total size.
124197
pub(crate) fn get_missing_files<P: ProgressBars, S>(
125198
repo: &Repository<P, S>,
126199
file_type: FileType,

crates/core/src/repository.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -708,18 +708,18 @@ impl<P, S> Repository<P, S> {
708708
/// * If the config file has `is_hot` set to `false` but the repository is hot
709709
fn open_raw(mut self, key: Key, config: ConfigFile) -> RusticResult<Repository<P, OpenStatus>> {
710710
match (config.is_hot == Some(true), self.be_hot.is_some()) {
711-
(true, false) => return Err(
712-
RusticError::new(
711+
(true, false) => {
712+
return Err(RusticError::new(
713713
ErrorKind::Repository,
714714
"The given repository is a hot repository! Please use `--repo-hot` in combination with the normal repo. Aborting.",
715-
)
716-
),
717-
(false, true) => return Err(
718-
RusticError::new(
715+
));
716+
}
717+
(false, true) => {
718+
return Err(RusticError::new(
719719
ErrorKind::Repository,
720720
"The given repository is not a hot repository! Aborting.",
721-
)
722-
),
721+
));
722+
}
723723
_ => {}
724724
}
725725

@@ -944,24 +944,10 @@ impl<P, S: Open> Repository<P, S> {
944944
self.status.dbe()
945945
}
946946

947-
/// Save a [`ConfigFile`] only to the hot part of a repository
948-
///
949-
/// # Type Parameters
950-
///
951-
/// * `P` - The progress bar type.
952-
/// * `S` - The state the repository is in.
953-
///
954-
/// # Arguments
955-
///
956-
/// * `repo` - The repository to save the config to
957-
/// * `new_config` - The config to save
958-
/// * `key` - The key to encrypt the config with
959-
///
947+
/// Init only the hot repository, i.e. Save the [`ConfigFile`] only to the hot part of a repository
960948
/// # Errors
961949
///
962-
/// * [`CryptBackendErrorKind::SerializingToJsonByteVectorFailed`] - If the file could not be serialized to json.
963-
///
964-
/// [`CryptBackendErrorKind::SerializingToJsonByteVectorFailed`]: crate::error::CryptBackendErrorKind::SerializingToJsonByteVectorFailed
950+
/// * If the config file could not be saved.
965951
pub fn init_hot(&self) -> RusticResult<()> {
966952
if let Some(hot_be) = self.be_hot.clone() {
967953
hot_be.create()?;
@@ -1203,12 +1189,10 @@ impl<P: ProgressBars, S: Open> Repository<P, S> {
12031189
/// * If the files could not be deleted.
12041190
pub fn delete_snapshots(&self, ids: &[SnapshotId]) -> RusticResult<()> {
12051191
if self.config().append_only == Some(true) {
1206-
return Err(
1207-
RusticError::new(
1208-
ErrorKind::Repository,
1209-
"Repository is in append-only mode and snapshots cannot be deleted from it. Aborting.",
1210-
)
1211-
);
1192+
return Err(RusticError::new(
1193+
ErrorKind::Repository,
1194+
"Repository is in append-only mode and snapshots cannot be deleted from it. Aborting.",
1195+
));
12121196
}
12131197
let p = self.pb.progress_counter("removing snapshots...");
12141198
self.dbe().delete_list(true, ids.iter(), p)?;

0 commit comments

Comments
 (0)