diff --git a/Cargo.toml b/Cargo.toml index 195e604e..08d40e03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,11 +75,11 @@ codegen-units = 1 unsafe_code = "forbid" missing_docs = "warn" rust_2018_idioms = { level = "warn", priority = -1 } +bad_style = { level = "warn", priority = -1 } trivial_casts = "warn" unused_lifetimes = "warn" unused_qualifications = "warn" -bad_style = "warn" -dead_code = "allow" # TODO: "warn" +dead_code = "warn" improper_ctypes = "warn" missing_copy_implementations = "warn" missing_debug_implementations = "warn" diff --git a/crates/core/src/backend.rs b/crates/core/src/backend.rs index ffd54609..7720414a 100644 --- a/crates/core/src/backend.rs +++ b/crates/core/src/backend.rs @@ -483,48 +483,6 @@ pub trait ReadSource: Sync + Send { fn entries(&self) -> Self::Iter; } -/// Trait for backends that can write to a source. -/// -/// This trait is implemented by all backends that can write data to a source. -pub trait WriteSource: Clone { - /// Create a new source. - /// - /// # Type Parameters - /// - /// * `P` - The type of the path. - /// - /// # Arguments - /// - /// * `path` - The path of the source. - /// * `node` - The node information of the source. - fn create>(&self, path: P, node: Node); - - /// Set the metadata of a source. - /// - /// # Type Parameters - /// - /// * `P` - The type of the path. - /// - /// # Arguments - /// - /// * `path` - The path of the source. - /// * `node` - The node information of the source. - fn set_metadata>(&self, path: P, node: Node); - - /// Write data to a source at the given offset. - /// - /// # Type Parameters - /// - /// * `P` - The type of the path. - /// - /// # Arguments - /// - /// * `path` - The path of the source. - /// * `offset` - The offset to write at. - /// * `data` - The data to write. - fn write_at>(&self, path: P, offset: u64, data: Bytes); -} - /// The backends a repository can be initialized and operated on /// /// # Note diff --git a/crates/core/src/backend/local_destination.rs b/crates/core/src/backend/local_destination.rs index 05a65677..9d7bcc90 100644 --- a/crates/core/src/backend/local_destination.rs +++ b/crates/core/src/backend/local_destination.rs @@ -40,6 +40,7 @@ pub enum LocalDestinationErrorKind { DirectoryCreationFailed(std::io::Error), /// file `{0:?}` should have a parent FileDoesNotHaveParent(PathBuf), + #[cfg(any(target_os = "macos", target_os = "openbsd"))] /// `DeviceID` could not be converted to other type `{target}` of device `{device}`: `{source}` DeviceIdConversionFailed { target: String, diff --git a/crates/core/src/blob.rs b/crates/core/src/blob.rs index e353004d..e8c616c9 100644 --- a/crates/core/src/blob.rs +++ b/crates/core/src/blob.rs @@ -3,7 +3,6 @@ pub(crate) mod tree; use std::{cmp::Ordering, num::NonZeroU32}; -use derive_more::Constructor; use enum_map::{Enum, EnumMap}; use serde_derive::{Deserialize, Serialize}; @@ -118,21 +117,6 @@ macro_rules! impl_blobid { impl_blobid!(DataId, BlobType::Data); -/// A `Blob` is a file that is stored in the backend. -/// -/// It can be a `tree` or a `data` blob. -/// -/// A `tree` blob is a file that contains a list of other blobs. -/// A `data` blob is a file that contains the actual data. -#[derive(Debug, PartialEq, Eq, Copy, Clone, Constructor)] -pub(crate) struct Blob { - /// The type of the blob - tpe: BlobType, - - /// The id of the blob - id: BlobId, -} - /// `BlobLocation` contains information about a blob within a pack #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub struct BlobLocation { @@ -190,10 +174,6 @@ impl BlobLocations { self.blobs.iter().map(|bl| bl.0.length).sum() } - pub fn data_length(&self) -> u32 { - self.blobs.iter().map(|bl| bl.0.data_length()).sum() - } - pub fn from_blob_location(location: BlobLocation, target: T) -> Self { Self { offset: location.offset, diff --git a/crates/core/src/blob/packer.rs b/crates/core/src/blob/packer.rs index 81d9b7b4..3b6b4059 100644 --- a/crates/core/src/blob/packer.rs +++ b/crates/core/src/blob/packer.rs @@ -24,7 +24,7 @@ use crate::{ index::{IndexEntry, indexer::SharedIndexer}, repofile::{ configfile::ConfigFile, - indexfile::{IndexBlob, IndexPack}, + indexfile::IndexPack, packfile::{PackHeaderLength, PackHeaderRef, PackId}, snapshotfile::SnapshotSummary, }, @@ -40,12 +40,6 @@ pub enum PackerErrorKind { from: &'static str, source: std::num::TryFromIntError, }, - /// Sending crossbeam message failed: `id`: `{id:?}`, `data`: `{data:?}` : `{source}` - SendingCrossbeamMessage { - id: BlobId, - data: Bytes, - source: crossbeam_channel::SendError<(Bytes, BlobId)>, - }, /// Sending crossbeam data message failed: `data`: `{data:?}`, `index_pack`: `{index_pack:?}` : `{source}` SendingCrossbeamDataMessage { data: Bytes, @@ -822,13 +816,6 @@ pub struct CopyPackBlobs { } impl CopyPackBlobs { - pub fn from_index_blob(pack_id: PackId, blob: IndexBlob) -> Self { - Self { - pack_id, - locations: BlobLocations::from_blob_location(blob.location, blob.id), - } - } - pub fn from_index_entry(entry: IndexEntry, id: BlobId) -> Self { Self { pack_id: entry.pack, @@ -864,8 +851,6 @@ where be_src: BE, /// The packer to write to. packer: Packer, - /// The size limit of the pack file. - size_limit: u32, /// the blob type blob_type: BlobType, } @@ -896,11 +881,9 @@ impl BlobCopier { pack_sizer: PackSizer, ) -> RusticResult { let packer = Packer::new(be_dst, blob_type, indexer, pack_sizer)?; - let size_limit = pack_sizer.pack_size(); Ok(Self { be_src, packer, - size_limit, blob_type, }) } diff --git a/crates/core/src/blob/tree.rs b/crates/core/src/blob/tree.rs index de93426d..b721e7a8 100644 --- a/crates/core/src/blob/tree.rs +++ b/crates/core/src/blob/tree.rs @@ -514,21 +514,6 @@ where BE: DecryptReadBackend, I: ReadGlobalIndex, { - /// Creates a new `NodeStreamer`. - /// - /// # Arguments - /// - /// * `be` - The backend to read from. - /// * `node` - The node to start from. - /// - /// # Errors - /// - /// * If the tree ID is not found in the backend. - /// * If deserialization fails. - pub fn new(be: BE, index: &'a I, node: &Node) -> RusticResult { - Self::new_streamer(be, index, node, None, true) - } - /// Creates a new `NodeStreamer`. /// /// # Arguments diff --git a/crates/core/src/blob/tree/modify.rs b/crates/core/src/blob/tree/modify.rs index cb5d217b..a8605963 100644 --- a/crates/core/src/blob/tree/modify.rs +++ b/crates/core/src/blob/tree/modify.rs @@ -29,7 +29,6 @@ pub enum ModifierChange { #[derive(Debug)] pub enum ModifierAction { Change(ModifierChange), - WriteChangedTree(Tree), Process(TreeId), } @@ -76,9 +75,6 @@ pub trait Visitor { } } -pub struct DefaultVisitor; -impl Visitor for DefaultVisitor {} - pub struct TreeModifier<'a, BE: DecryptWriteBackend, I: ReadGlobalIndex> { be: &'a BE, index: &'a I, @@ -112,10 +108,6 @@ impl<'a, BE: DecryptFullBackend, I: ReadGlobalIndex> TreeModifier<'a, BE, I> { let mut changed = false; let tree = match visitor.pre_process(&path, id) { ModifierAction::Change(change) => return Ok(change), - ModifierAction::WriteChangedTree(tree) => { - changed = true; - tree - } ModifierAction::Process(id) => { match visitor.pre_process_tree(Tree::from_backend(self.be, self.index, id))? { TreeAction::ProcessChangedTree(tree) => { diff --git a/crates/core/src/blob/tree/rewrite.rs b/crates/core/src/blob/tree/rewrite.rs index 2a12eafd..4a3d38e2 100644 --- a/crates/core/src/blob/tree/rewrite.rs +++ b/crates/core/src/blob/tree/rewrite.rs @@ -47,8 +47,7 @@ pub struct RewriteTreesOptions { } #[derive(Debug)] -pub struct RewriteVisitor<'a, I: ReadGlobalIndex> { - index: &'a I, +pub struct RewriteVisitor { overrides: Override, node_modification: NodeModification, all_trees: bool, @@ -57,10 +56,9 @@ pub struct RewriteVisitor<'a, I: ReadGlobalIndex> { summary: BTreeMap, } -impl<'a, I: ReadGlobalIndex> RewriteVisitor<'a, I> { - pub fn new(index: &'a I, opts: &RewriteTreesOptions) -> RusticResult { +impl RewriteVisitor { + pub fn new(opts: &RewriteTreesOptions) -> RusticResult { Ok(Self { - index, overrides: opts.excludes.as_override()?, node_modification: opts.node_modification.clone(), all_trees: opts.all_trees, @@ -71,7 +69,7 @@ impl<'a, I: ReadGlobalIndex> RewriteVisitor<'a, I> { } } -impl Visitor for RewriteVisitor<'_, I> { +impl Visitor for RewriteVisitor { fn pre_process(&self, path: &PathBuf, id: TreeId) -> ModifierAction { if self.unchanged.contains(&(path.clone(), id)) { ModifierAction::Change(ModifierChange::Unchanged) @@ -125,7 +123,7 @@ impl Visitor for RewriteVisitor<'_, I> { pub struct Rewriter<'a, BE: DecryptWriteBackend, I: ReadGlobalIndex> { modifier: TreeModifier<'a, BE, I>, - visitor: RewriteVisitor<'a, I>, + visitor: RewriteVisitor, } impl<'a, BE: DecryptFullBackend, I: ReadGlobalIndex> Rewriter<'a, BE, I> { @@ -137,7 +135,7 @@ impl<'a, BE: DecryptFullBackend, I: ReadGlobalIndex> Rewriter<'a, BE, I> { dry_run: bool, ) -> RusticResult { let modifier = TreeModifier::new(be, index, config, dry_run)?; - let visitor = RewriteVisitor::new(index, opts)?; + let visitor = RewriteVisitor::new(opts)?; Ok(Self { modifier, visitor }) } @@ -189,10 +187,4 @@ impl Summary { self.size += node.meta.size; } } - - pub fn from_node(node: &Node) -> Self { - let mut summary = Self::default(); - summary.update(node); - summary - } } diff --git a/crates/core/src/chunker/rabin.rs b/crates/core/src/chunker/rabin.rs index 67f8eb73..66646c16 100644 --- a/crates/core/src/chunker/rabin.rs +++ b/crates/core/src/chunker/rabin.rs @@ -6,16 +6,8 @@ use rustic_cdc::{Polynom, Polynom64, Rabin64, RollingHash64}; use crate::error::{ErrorKind, RusticError, RusticResult}; pub(super) mod constants { - /// The Splitmask is used to determine if a chunk is a chunk boundary. - pub(super) const SIZE: usize = 1 << 20; /// The size of a kilobyte. pub(super) const KB: usize = 1024; - /// The size of a megabyte. - pub(super) const MB: usize = 1024 * KB; - /// The minimum size of a chunk. - pub(super) const MIN_SIZE: usize = 512 * KB; - /// The maximum size of a chunk. - pub(super) const MAX_SIZE: usize = 8 * MB; /// Buffer size used for reading - TODO: Find out optimal size for best performance! pub(super) const BUF_SIZE: usize = 4 * KB; /// Random polynomial maximum tries. @@ -331,18 +323,19 @@ mod tests { use rand::prelude::*; use std::io::{Cursor, repeat}; + /// The Splitmask is used to determine if a chunk is a chunk boundary. + const SIZE: usize = 1 << 20; + /// The size of a megabyte. + const MB: usize = 1024 * constants::KB; + /// The minimum size of a chunk. + const MIN_SIZE: usize = 512 * constants::KB; + /// The maximum size of a chunk. + const MAX_SIZE: usize = 8 * MB; + fn chunker(reader: R, size_hint: usize) -> ChunkIter { let poly = 0x003D_A335_8B4D_C173; let rabin = Rabin64::new_with_polynom(6, &poly); - ChunkIter::new( - rabin, - constants::SIZE, - constants::MIN_SIZE, - constants::MAX_SIZE, - reader, - size_hint, - ) - .unwrap() + ChunkIter::new(rabin, SIZE, MIN_SIZE, MAX_SIZE, reader, size_hint).unwrap() } #[test] @@ -388,6 +381,6 @@ mod tests { let mut chunker = chunker(&mut reader, usize::MAX); let chunk = chunker.next().unwrap().unwrap(); - assert_eq!(constants::MIN_SIZE, chunk.len()); + assert_eq!(MIN_SIZE, chunk.len()); } } diff --git a/crates/core/src/commands/check.rs b/crates/core/src/commands/check.rs index 1c20b033..001efbcc 100644 --- a/crates/core/src/commands/check.rs +++ b/crates/core/src/commands/check.rs @@ -1113,6 +1113,7 @@ mod tests { ); } + #[test] fn test_read_subset_n_m() { let test_packs = test_packs(&mut rng()); let mut all_packs: BTreeSet<_> = test_packs.iter().map(|pack| pack.id).collect(); diff --git a/crates/core/src/id.rs b/crates/core/src/id.rs index b7f69128..d0ef1f58 100644 --- a/crates/core/src/id.rs +++ b/crates/core/src/id.rs @@ -128,7 +128,7 @@ impl Id { pub fn parse_some(name: &str, tpe: FileType) -> Option { name.parse() .inspect_err(|err| { - debug!("ignoring {name} which is no ID while listing {tpe}: {err}",); + debug!("ignoring {name} which is no ID while listing {tpe}: {err}"); }) .ok() } diff --git a/crates/core/src/index/binarysorted.rs b/crates/core/src/index/binarysorted.rs index c49fb1c6..fc6f9fa8 100644 --- a/crates/core/src/index/binarysorted.rs +++ b/crates/core/src/index/binarysorted.rs @@ -104,11 +104,6 @@ impl IndexCollector { &self.0[BlobType::Tree].packs } - #[must_use] - pub fn data_packs(&self) -> &Vec<(PackId, u32)> { - &self.0[BlobType::Data].packs - } - // Turns Collector into an index by sorting the entries by ID. #[must_use] pub fn into_index(self) -> Index { diff --git a/crates/core/src/repofile/snapshotfile.rs b/crates/core/src/repofile/snapshotfile.rs index 80acd80a..3d90e27d 100644 --- a/crates/core/src/repofile/snapshotfile.rs +++ b/crates/core/src/repofile/snapshotfile.rs @@ -818,27 +818,6 @@ impl SnapshotFile { Self::from_backend(be, &SnapshotId::from(id)) } - /// Get a list of [`SnapshotFile`]s from the backend by supplying a list of/parts of their Ids - /// - /// # Arguments - /// - /// * `be` - The backend to use - /// * `ids` - The list of (parts of the) ids of the snapshots - /// * `p` - A progress bar to use - /// - /// # Errors - /// - /// * If the string is not a valid hexadecimal string - /// * If no id could be found. - /// * If the id is not unique. - pub(crate) fn from_ids>( - be: &B, - ids: &[T], - p: &Progress, - ) -> RusticResult> { - Self::update_from_ids(be, Vec::new(), ids, p) - } - /// Update a list of [`SnapshotFile`]s from the backend by supplying a list of/parts of their Ids /// /// # Arguments diff --git a/crates/core/tests/warm_up.rs b/crates/core/tests/warm_up.rs index 7b5a68d1..cc9ca1e7 100644 --- a/crates/core/tests/warm_up.rs +++ b/crates/core/tests/warm_up.rs @@ -15,10 +15,7 @@ use tempfile::tempdir; use rustic_core::{CommandInput, Id, RepositoryBackends, RepositoryOptions, repofile::PackId}; use rustic_testing::backend::in_memory_backend::InMemoryBackend; -type RepoOpen = rustic_core::Repository; - // Test constants -const DEFAULT_BATCH_SIZE: usize = 1; const PACK_ID_HEX_LENGTH: usize = 64; /// Helper to create a test script that logs invocations and arguments