Skip to content

Commit

Permalink
document Repository
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Aug 1, 2023
1 parent 981a3b5 commit 015d58f
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 35 deletions.
4 changes: 2 additions & 2 deletions crates/rustic_core/src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::{
backend::{dry_run::DryRunBackend, stdin::StdinSource},
repofile::SnapshotFile,
repository::{IndexedIds, IndexedTree},
Id, LocalSource, LocalSourceFilterOptions, LocalSourceSaveOptions, Open, PathList,
ProgressBars, Repository, RusticResult, SnapshotGroup, SnapshotGroupCriterion,
Id, LocalSource, LocalSourceFilterOptions, LocalSourceSaveOptions, PathList, ProgressBars,
Repository, RusticResult, SnapshotGroup, SnapshotGroupCriterion,
};

#[cfg_attr(feature = "clap", derive(clap::Parser))]
Expand Down
3 changes: 2 additions & 1 deletion crates/rustic_core/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::{
backend::decrypt::{DecryptBackend, DecryptWriteBackend},
error::CommandErrorKind,
repofile::ConfigFile,
Key, Open, Repository, RusticResult,
repository::Open,
Key, Repository, RusticResult,
};

pub(crate) fn apply_config<P, S: Open>(
Expand Down
4 changes: 2 additions & 2 deletions crates/rustic_core/src/commands/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
blob::{packer::Packer, tree::TreeStreamerOnce, BlobType},
index::{indexer::Indexer, IndexedBackend, ReadIndex},
repofile::SnapshotFile,
repository::{IndexedFull, IndexedIds, IndexedTree},
Open, ProgressBars, Repository, RusticResult,
repository::{IndexedFull, IndexedIds, IndexedTree, Open},
ProgressBars, Repository, RusticResult,
};

#[derive(Debug)]
Expand Down
3 changes: 2 additions & 1 deletion crates/rustic_core/src/commands/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::{
crypto::hasher::hash,
error::CommandErrorKind,
repofile::KeyFile,
Id, Key, Open, Repository, RusticResult,
repository::Open,
Id, Key, Repository, RusticResult,
};

#[cfg_attr(feature = "clap", derive(clap::Parser))]
Expand Down
2 changes: 1 addition & 1 deletion crates/rustic_core/src/commands/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
index::{indexer::Indexer, ReadIndex},
repofile::{SnapshotFile, SnapshotSummary},
repository::IndexedTree,
Id, Open, PathList, Progress, ProgressBars, Repository, RusticResult,
Id, PathList, Progress, ProgressBars, Repository, RusticResult,
};

pub(crate) fn merge_snapshots<P: ProgressBars, S: IndexedTree>(
Expand Down
3 changes: 2 additions & 1 deletion crates/rustic_core/src/commands/repair/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use crate::{
error::CommandErrorKind,
index::indexer::Indexer,
repofile::{IndexFile, IndexPack, PackHeader, PackHeaderRef},
Open, Progress, ProgressBars, Repository, RusticResult,
repository::Open,
Progress, ProgressBars, Repository, RusticResult,
};

#[cfg_attr(feature = "clap", derive(clap::Parser))]
Expand Down
2 changes: 1 addition & 1 deletion crates/rustic_core/src/commands/repair/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
index::{indexer::Indexer, IndexedBackend, ReadIndex},
repofile::SnapshotFile,
repository::{IndexedFull, IndexedTree},
Id, Open, ProgressBars, Repository, RusticResult, StringList,
Id, ProgressBars, Repository, RusticResult, StringList,
};

#[cfg_attr(feature = "clap", derive(clap::Parser))]
Expand Down
4 changes: 2 additions & 2 deletions crates/rustic_core/src/commands/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::{
},
blob::BlobType,
error::CommandErrorKind,
repository::{IndexedFull, IndexedTree},
Id, LocalDestination, Open, Progress, ProgressBars, Repository, RusticResult,
repository::{IndexedFull, IndexedTree, Open},
Id, LocalDestination, Progress, ProgressBars, Repository, RusticResult,
};

pub(crate) mod constants {
Expand Down
2 changes: 1 addition & 1 deletion crates/rustic_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ pub use crate::{
repofile::snapshotfile::{
PathList, SnapshotGroup, SnapshotGroupCriterion, SnapshotOptions, StringList,
},
repository::{IndexedFull, Open, OpenStatus, Repository, RepositoryOptions},
repository::{IndexedFull, OpenStatus, Repository, RepositoryOptions},
};
34 changes: 18 additions & 16 deletions crates/rustic_core/src/repofile/snapshotfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl SnapshotFile {
.to_string()
};

let time = opts.time.unwrap_or(Local::now());
let time = opts.time.unwrap_or_else(Local::now);

let delete = match (opts.delete_never, opts.delete_after) {
(true, _) => DeleteOption::Never,
Expand All @@ -282,22 +282,23 @@ impl SnapshotFile {
(false, None) => DeleteOption::NotSet,
};

let command: String = if let Some(command) = &opts.command {
command.clone()
} else {
std::env::args_os()
.map(|s| s.to_string_lossy().to_string())
.collect::<Vec<_>>()
.join(" ")
};
let command: String = opts.command.as_ref().map_or_else(
|| {
std::env::args_os()
.map(|s| s.to_string_lossy().to_string())
.collect::<Vec<_>>()
.join(" ")
},
|command| command.clone(),
);

let mut snap = Self {
time,
hostname,
label: opts.label.clone().unwrap_or_default(),
delete,
summary: Some(SnapshotSummary {
command: command.into(),
command,
..Default::default()
}),
description: opts.description.clone(),
Expand Down Expand Up @@ -672,7 +673,7 @@ impl SnapshotGroup {
}

#[derive(Serialize, Deserialize, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
/// StringList is a rustic-internal list of Strings. It is used within [`SnapshotFile`]
/// `StringList` is a rustic-internal list of Strings. It is used within [`SnapshotFile`]
pub struct StringList(pub(crate) Vec<String>);

impl FromStr for StringList {
Expand Down Expand Up @@ -760,13 +761,14 @@ impl StringList {
self.0.join("\n")
}

/// Turn this [`StringList`] into an Iterator
pub fn iter(&self) -> std::slice::Iter<'_, String> {
self.0.iter()
}
}

#[derive(Default, Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
/// PathList is a rustic-internal list of PathBufs. It is used in the [`crate::Repository::backup`] command.
/// `PathList` is a rustic-internal list of `PathBuf`s. It is used in the [`crate::Repository::backup`] command.
pub struct PathList(Vec<PathBuf>);

impl Display for PathList {
Expand All @@ -782,7 +784,7 @@ impl Display for PathList {
}

impl PathList {
/// Create a PathList from Strings.
/// Create a `PathList` from `String`s.
pub fn from_strings<I>(source: I) -> Self
where
I: IntoIterator,
Expand All @@ -796,7 +798,7 @@ impl PathList {
)
}

/// Create a PathList by parsing a Strings containing paths separated by whitspaces.
/// Create a `PathList` by parsing a Strings containing paths separated by whitspaces.
pub fn from_string(sources: &str) -> RusticResult<Self> {
let sources = parse_command::<()>(sources)
.map_err(SnapshotFileErrorKind::FromNomError)?
Expand All @@ -805,13 +807,13 @@ impl PathList {
}

#[must_use]
/// Number of paths in the PathList.
/// Number of paths in the `PathList`.
pub fn len(&self) -> usize {
self.0.len()
}

#[must_use]
/// Returns whether the PathList is empty.
/// Returns whether the `PathList` is empty.
pub fn is_empty(&self) -> bool {
self.0.len() == 0
}
Expand Down
Loading

0 comments on commit 015d58f

Please sign in to comment.