Skip to content

Commit

Permalink
Merge pull request #748 from rustic-rs/api
Browse files Browse the repository at this point in the history
Rework `rustic_core` API
  • Loading branch information
aawsome authored Jul 15, 2023
2 parents ae5f835 + 5dc742b commit 464d7d5
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 53 deletions.
19 changes: 1 addition & 18 deletions crates/rustic_core/src/blob.rs
Original file line number Diff line number Diff line change
@@ -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<NonZeroU32>,
}

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,
)]
Expand Down
7 changes: 4 additions & 3 deletions crates/rustic_core/src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions crates/rustic_core/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/rustic_core/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P, S: Open>(
Expand Down
2 changes: 1 addition & 1 deletion crates/rustic_core/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
13 changes: 8 additions & 5 deletions crates/rustic_core/src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/rustic_core/src/crypto/aespoly1305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Key {
}

#[must_use]
pub fn to_keys(&self) -> (Vec<u8>, Vec<u8>, Vec<u8>) {
pub fn to_keys(self) -> (Vec<u8>, Vec<u8>, Vec<u8>) {
let mut encrypt = vec![0; 32];
let mut k = vec![0; 16];
let mut r = vec![0; 16];
Expand Down
23 changes: 8 additions & 15 deletions crates/rustic_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -148,5 +141,5 @@ pub use crate::{
SnapshotOptions, StringList,
},
},
repository::{read_password_from_reader, Open, OpenStatus, Repository, RepositoryOptions},
repository::{Open, OpenStatus, Repository, RepositoryOptions},
};
13 changes: 8 additions & 5 deletions crates/rustic_core/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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;
Expand Down

0 comments on commit 464d7d5

Please sign in to comment.