From 5dc742b13f20052a4b98afc2f4b59bdbd0687f22 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Fri, 14 Jul 2023 22:32:25 +0200 Subject: [PATCH] overwork API --- crates/rustic_core/src/blob.rs | 19 +--------------- crates/rustic_core/src/commands/backup.rs | 7 +++--- crates/rustic_core/src/commands/check.rs | 8 ++++--- crates/rustic_core/src/commands/config.rs | 4 ++-- crates/rustic_core/src/commands/init.rs | 2 +- crates/rustic_core/src/commands/prune.rs | 13 ++++++----- crates/rustic_core/src/crypto/aespoly1305.rs | 2 +- crates/rustic_core/src/lib.rs | 23 +++++++------------- crates/rustic_core/src/repository.rs | 13 ++++++----- 9 files changed, 38 insertions(+), 53 deletions(-) diff --git a/crates/rustic_core/src/blob.rs b/crates/rustic_core/src/blob.rs index 6ebd9df6e..347b4422f 100644 --- a/crates/rustic_core/src/blob.rs +++ b/crates/rustic_core/src/blob.rs @@ -1,31 +1,14 @@ pub(crate) mod packer; pub(crate) mod tree; -use std::{num::NonZeroU32, ops::Add}; +use std::ops::Add; use derive_more::Constructor; use enum_map::{Enum, EnumMap}; - use serde::{Deserialize, Serialize}; use crate::id::Id; -#[derive(Debug, Hash, PartialEq, Eq, Default, Clone, Copy)] -pub struct BlobLocation { - pub offset: u32, - pub length: u32, - pub uncompressed_length: Option, -} - -impl BlobLocation { - #[must_use] - pub fn data_length(&self) -> u64 { - self.uncompressed_length - .map_or(self.length - 32, |length| length.get()) - .into() - } -} - #[derive( Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Enum, )] diff --git a/crates/rustic_core/src/commands/backup.rs b/crates/rustic_core/src/commands/backup.rs index dcf61f191..c2ad62117 100644 --- a/crates/rustic_core/src/commands/backup.rs +++ b/crates/rustic_core/src/commands/backup.rs @@ -11,10 +11,11 @@ use serde::Deserialize; use crate::{ archiver::{parent::Parent, Archiver}, + backend::dry_run::DryRunBackend, repository::{IndexedIds, IndexedTree}, - DryRunBackend, Id, LocalSource, LocalSourceFilterOptions, LocalSourceSaveOptions, Open, - PathList, ProgressBars, Repository, RusticResult, SnapshotFile, SnapshotGroup, - SnapshotGroupCriterion, StdinSource, + Id, LocalSource, LocalSourceFilterOptions, LocalSourceSaveOptions, Open, PathList, + ProgressBars, Repository, RusticResult, SnapshotFile, SnapshotGroup, SnapshotGroupCriterion, + StdinSource, }; /// `backup` subcommand diff --git a/crates/rustic_core/src/commands/check.rs b/crates/rustic_core/src/commands/check.rs index d7c624ad6..6804294cf 100644 --- a/crates/rustic_core/src/commands/check.rs +++ b/crates/rustic_core/src/commands/check.rs @@ -8,12 +8,14 @@ use rayon::prelude::{IntoParallelIterator, ParallelBridge, ParallelIterator}; use zstd::stream::decode_all; use crate::{ + backend::cache::Cache, hash, + index::binarysorted::{IndexCollector, IndexType}, progress::ProgressBars, repository::{Open, Repository}, - BlobType, Cache, DecryptReadBackend, FileType, Id, IndexBackend, IndexCollector, IndexFile, - IndexPack, IndexType, IndexedBackend, NodeType, PackHeader, PackHeaderLength, PackHeaderRef, - Progress, ReadBackend, RusticResult, SnapshotFile, TreeStreamerOnce, + BlobType, DecryptReadBackend, FileType, Id, IndexBackend, IndexFile, IndexPack, IndexedBackend, + NodeType, PackHeader, PackHeaderLength, PackHeaderRef, Progress, ReadBackend, RusticResult, + SnapshotFile, TreeStreamerOnce, }; /// `check` subcommand diff --git a/crates/rustic_core/src/commands/config.rs b/crates/rustic_core/src/commands/config.rs index 1ee0cc626..768767c51 100644 --- a/crates/rustic_core/src/commands/config.rs +++ b/crates/rustic_core/src/commands/config.rs @@ -2,8 +2,8 @@ use bytesize::ByteSize; use crate::{ - error::CommandErrorKind, ConfigFile, DecryptBackend, DecryptWriteBackend, Key, Open, - Repository, RusticResult, + backend::decrypt::DecryptBackend, error::CommandErrorKind, ConfigFile, DecryptWriteBackend, + Key, Open, Repository, RusticResult, }; pub(crate) fn apply_config( diff --git a/crates/rustic_core/src/commands/init.rs b/crates/rustic_core/src/commands/init.rs index 13d7f11be..538d9fe08 100644 --- a/crates/rustic_core/src/commands/init.rs +++ b/crates/rustic_core/src/commands/init.rs @@ -3,7 +3,7 @@ use log::info; use crate::{ - commands::config::save_config, random_poly, ConfigFile, ConfigOpts, Id, Key, KeyOpts, + chunker::random_poly, commands::config::save_config, ConfigFile, ConfigOpts, Id, Key, KeyOpts, Repository, RusticResult, WriteBackend, }; diff --git a/crates/rustic_core/src/commands/prune.rs b/crates/rustic_core/src/commands/prune.rs index bffa5bea9..e428e7dc8 100644 --- a/crates/rustic_core/src/commands/prune.rs +++ b/crates/rustic_core/src/commands/prune.rs @@ -19,11 +19,14 @@ use itertools::Itertools; use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use crate::{ - error::CommandErrorKind, repository::Open, BlobType, BlobTypeMap, DecryptReadBackend, - DecryptWriteBackend, FileType, HeaderEntry, Id, IndexBackend, IndexBlob, IndexCollector, - IndexFile, IndexPack, IndexType, IndexedBackend, Indexer, Initialize, NodeType, PackSizer, - Progress, ProgressBars, ReadBackend, ReadIndex, Repacker, Repository, RusticResult, - SnapshotFile, Sum, TreeStreamerOnce, + blob::packer::{PackSizer, Repacker}, + error::CommandErrorKind, + index::binarysorted::{IndexCollector, IndexType}, + repository::Open, + BlobType, BlobTypeMap, DecryptReadBackend, DecryptWriteBackend, FileType, HeaderEntry, Id, + IndexBackend, IndexBlob, IndexFile, IndexPack, IndexedBackend, Indexer, Initialize, NodeType, + Progress, ProgressBars, ReadBackend, ReadIndex, Repository, RusticResult, SnapshotFile, Sum, + TreeStreamerOnce, }; pub(super) mod constants { diff --git a/crates/rustic_core/src/crypto/aespoly1305.rs b/crates/rustic_core/src/crypto/aespoly1305.rs index fa82762e1..0338c9f4b 100644 --- a/crates/rustic_core/src/crypto/aespoly1305.rs +++ b/crates/rustic_core/src/crypto/aespoly1305.rs @@ -36,7 +36,7 @@ impl Key { } #[must_use] - pub fn to_keys(&self) -> (Vec, Vec, Vec) { + pub fn to_keys(self) -> (Vec, Vec, Vec) { let mut encrypt = vec![0; 32]; let mut k = vec![0; 16]; let mut r = vec![0; 16]; diff --git a/crates/rustic_core/src/lib.rs b/crates/rustic_core/src/lib.rs index a4a3ddb25..4ca2f157f 100644 --- a/crates/rustic_core/src/lib.rs +++ b/crates/rustic_core/src/lib.rs @@ -99,25 +99,22 @@ pub(crate) mod progress; pub(crate) mod repofile; pub(crate) mod repository; +pub(crate) use crate::crypto::aespoly1305::Key; // rustic_core Public API pub use crate::{ backend::{ - cache::Cache, - decrypt::{DecryptBackend, DecryptFullBackend, DecryptReadBackend, DecryptWriteBackend}, - dry_run::DryRunBackend, + decrypt::{DecryptReadBackend, DecryptWriteBackend}, ignore::{LocalSource, LocalSourceFilterOptions, LocalSourceSaveOptions}, local::LocalDestination, node::{Node, NodeType}, stdin::StdinSource, - FileType, ReadBackend, ReadSource, ReadSourceEntry, ReadSourceOpen, WriteBackend, - WriteSource, ALL_FILE_TYPES, + FileType, ReadBackend, ReadSourceEntry, WriteBackend, ALL_FILE_TYPES, }, blob::{ - packer::{PackSizer, Packer, Repacker}, + packer::Packer, tree::{merge_trees, NodeStreamer, Tree, TreeStreamerOnce, TreeStreamerOptions}, - BlobLocation, BlobType, BlobTypeMap, Initialize, Sum, + BlobType, BlobTypeMap, Initialize, Sum, }, - chunker::random_poly, commands::{ backup::{BackupOpts, ParentOpts}, check::CheckOpts, @@ -129,14 +126,10 @@ pub use crate::{ repoinfo::{BlobInfo, IndexInfos, PackInfo, RepoFileInfo, RepoFileInfos}, restore::{FileDirStats, RestoreInfos, RestoreOpts, RestoreStats}, }, - crypto::{aespoly1305::Key, hasher::hash}, + crypto::hasher::hash, error::{RusticError, RusticResult}, id::Id, - index::{ - binarysorted::{IndexCollector, IndexType}, - indexer::Indexer, - IndexBackend, IndexEntry, IndexedBackend, ReadIndex, - }, + index::{indexer::Indexer, IndexBackend, IndexedBackend, ReadIndex}, progress::{NoProgress, NoProgressBars, Progress, ProgressBars}, repofile::{ configfile::ConfigFile, @@ -148,5 +141,5 @@ pub use crate::{ SnapshotOptions, StringList, }, }, - repository::{read_password_from_reader, Open, OpenStatus, Repository, RepositoryOptions}, + repository::{Open, OpenStatus, Repository, RepositoryOptions}, }; diff --git a/crates/rustic_core/src/repository.rs b/crates/rustic_core/src/repository.rs index de3963437..d8a271112 100644 --- a/crates/rustic_core/src/repository.rs +++ b/crates/rustic_core/src/repository.rs @@ -24,8 +24,11 @@ use serde_with::{serde_as, DisplayFromStr}; use crate::{ backend::{ - cache::Cache, cache::CachedBackend, choose::ChooseBackend, decrypt::DecryptBackend, - decrypt::DecryptReadBackend, decrypt::DecryptWriteBackend, hotcold::HotColdBackend, + cache::Cache, + cache::CachedBackend, + choose::ChooseBackend, + decrypt::{DecryptBackend, DecryptFullBackend, DecryptReadBackend, DecryptWriteBackend}, + hotcold::HotColdBackend, FileType, ReadBackend, }, commands::{ @@ -43,9 +46,9 @@ use crate::{ error::{KeyFileErrorKind, RepositoryErrorKind, RusticErrorKind}, repofile::RepoFile, repofile::{configfile::ConfigFile, keyfile::find_key_in_backend}, - BlobType, DecryptFullBackend, Id, IndexBackend, IndexedBackend, LocalDestination, - NoProgressBars, Node, NodeStreamer, PathList, ProgressBars, PruneOpts, PrunePlan, RusticResult, - SnapshotFile, SnapshotGroup, SnapshotGroupCriterion, Tree, TreeStreamerOptions, + BlobType, Id, IndexBackend, IndexedBackend, LocalDestination, NoProgressBars, Node, + NodeStreamer, PathList, ProgressBars, PruneOpts, PrunePlan, RusticResult, SnapshotFile, + SnapshotGroup, SnapshotGroupCriterion, Tree, TreeStreamerOptions, }; mod warm_up;