From b48ff8e985246a3efd7ce6023849ee8a0ccb54de Mon Sep 17 00:00:00 2001 From: simonsan <14062932+simonsan@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:41:46 +0100 Subject: [PATCH 1/2] chore(deps): remove Derivative and replace with Default impl due to RUSTSEC-2024-0388 Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com> --- .cargo/audit.toml | 2 - Cargo.lock | 12 ---- crates/core/Cargo.toml | 1 - crates/core/src/blob/tree.rs | 17 ++++-- crates/core/src/repofile/snapshotfile.rs | 75 +++++++++++++++++++----- deny.toml | 2 - 6 files changed, 74 insertions(+), 35 deletions(-) diff --git a/.cargo/audit.toml b/.cargo/audit.toml index aa1db3e6..dce04a22 100644 --- a/.cargo/audit.toml +++ b/.cargo/audit.toml @@ -5,6 +5,4 @@ ignore = [ "RUSTSEC-2023-0071", # FIXME: backoff => used in backend, need to be replaced with backon "RUSTSEC-2024-0384", - # FIXME: derivative => used for default impls - "RUSTSEC-2024-0388", ] diff --git a/Cargo.lock b/Cargo.lock index 9145600f..83eec76f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1096,17 +1096,6 @@ dependencies = [ "serde", ] -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "derive_destructure2" version = "0.1.3" @@ -3620,7 +3609,6 @@ dependencies = [ "conflate", "crossbeam-channel", "dav-server", - "derivative", "derive_more", "derive_setters", "dirs", diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index e7ca9064..7a1535b2 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -45,7 +45,6 @@ displaydoc = { workspace = true } thiserror = { workspace = true } # macros -derivative = "2.2.0" derive_more = { version = "1.0.0", features = ["add", "constructor", "display", "from", "deref", "from_str"] } derive_setters = "0.1.6" diff --git a/crates/core/src/blob/tree.rs b/crates/core/src/blob/tree.rs index e28d079d..2e64a24e 100644 --- a/crates/core/src/blob/tree.rs +++ b/crates/core/src/blob/tree.rs @@ -8,7 +8,6 @@ use std::{ }; use crossbeam_channel::{bounded, unbounded, Receiver, Sender}; -use derivative::Derivative; use derive_setters::Setters; use ignore::overrides::{Override, OverrideBuilder}; use ignore::Match; @@ -455,8 +454,7 @@ impl IntoIterator for Tree { } #[cfg_attr(feature = "clap", derive(clap::Parser))] -#[derive(Derivative, Clone, Debug, Setters)] -#[derivative(Default)] +#[derive(Clone, Debug, Setters)] #[setters(into)] #[non_exhaustive] /// Options for listing the `Nodes` of a `Tree` @@ -488,10 +486,21 @@ pub struct TreeStreamerOptions { /// recursively list the dir #[cfg_attr(feature = "clap", clap(long))] - #[derivative(Default(value = "true"))] pub recursive: bool, } +impl Default for TreeStreamerOptions { + fn default() -> Self { + Self { + glob: Vec::default(), + iglob: Vec::default(), + glob_file: Vec::default(), + iglob_file: Vec::default(), + recursive: true, + } + } +} + /// [`NodeStreamer`] recursively streams all nodes of a given tree including all subtrees in-order #[derive(Debug, Clone)] pub struct NodeStreamer<'a, BE, I> diff --git a/crates/core/src/repofile/snapshotfile.rs b/crates/core/src/repofile/snapshotfile.rs index ec7eecc6..66718986 100644 --- a/crates/core/src/repofile/snapshotfile.rs +++ b/crates/core/src/repofile/snapshotfile.rs @@ -9,7 +9,6 @@ use std::{ use chrono::{DateTime, Duration, Local, OutOfRangeError}; #[cfg(feature = "clap")] use clap::ValueHint; -use derivative::Derivative; use derive_setters::Setters; use dunce::canonicalize; use gethostname::gethostname; @@ -162,9 +161,8 @@ impl SnapshotOptions { /// /// This is an extended version of the summaryOutput structure of restic in /// restic/internal/ui/backup$/json.go -#[derive(Serialize, Deserialize, Debug, Clone, Derivative)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(default)] -#[derivative(Default)] #[non_exhaustive] pub struct SnapshotSummary { /// New files compared to the last (i.e. parent) snapshot @@ -229,11 +227,9 @@ pub struct SnapshotSummary { /// # Note /// /// This may differ from the snapshot `time`. - #[derivative(Default(value = "Local::now()"))] pub backup_start: DateTime, /// The time that the backup has been finished. - #[derivative(Default(value = "Local::now()"))] pub backup_end: DateTime, /// Total duration of the backup in seconds, i.e. the time between `backup_start` and `backup_end` @@ -243,6 +239,36 @@ pub struct SnapshotSummary { pub total_duration: f64, } +impl Default for SnapshotSummary { + fn default() -> Self { + Self { + files_new: Default::default(), + files_changed: Default::default(), + files_unmodified: Default::default(), + total_files_processed: Default::default(), + total_bytes_processed: Default::default(), + dirs_new: Default::default(), + dirs_changed: Default::default(), + dirs_unmodified: Default::default(), + total_dirs_processed: Default::default(), + total_dirsize_processed: Default::default(), + data_blobs: Default::default(), + tree_blobs: Default::default(), + data_added: Default::default(), + data_added_packed: Default::default(), + data_added_files: Default::default(), + data_added_files_packed: Default::default(), + data_added_trees: Default::default(), + data_added_trees_packed: Default::default(), + command: String::default(), + backup_start: Local::now(), + backup_end: Local::now(), + backup_duration: Default::default(), + total_duration: Default::default(), + } + } +} + impl SnapshotSummary { /// Create a new [`SnapshotSummary`]. /// @@ -269,11 +295,10 @@ impl SnapshotSummary { } /// Options for deleting snapshots. -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Derivative, Copy)] -#[derivative(Default)] +#[derive(Serialize, Default, Deserialize, Debug, Clone, PartialEq, Eq, Copy)] pub enum DeleteOption { /// No delete option set. - #[derivative(Default)] + #[default] NotSet, /// This snapshot should be never deleted (remove-protection). Never, @@ -291,8 +316,7 @@ impl DeleteOption { impl_repofile!(SnapshotId, FileType::Snapshot, SnapshotFile); #[skip_serializing_none] -#[derive(Debug, Clone, Serialize, Deserialize, Derivative)] -#[derivative(Default)] +#[derive(Debug, Clone, Serialize, Deserialize)] /// A [`SnapshotFile`] is the repository representation of the snapshot metadata saved in a repository. /// /// It is usually saved in the repository under `snapshot/` @@ -302,14 +326,10 @@ impl_repofile!(SnapshotId, FileType::Snapshot, SnapshotFile); /// [`SnapshotFile`] implements [`Eq`], [`PartialEq`], [`Ord`], [`PartialOrd`] by comparing only the `time` field. /// If you need another ordering, you have to implement that yourself. pub struct SnapshotFile { - #[derivative(Default(value = "Local::now()"))] /// Timestamp of this snapshot pub time: DateTime, /// Program identifier and its version that have been used to create this snapshot. - #[derivative(Default( - value = "\"rustic \".to_string() + option_env!(\"PROJECT_VERSION\").unwrap_or(env!(\"CARGO_PKG_VERSION\"))" - ))] #[serde(default, skip_serializing_if = "String::is_empty")] pub program_version: String, @@ -364,6 +384,33 @@ pub struct SnapshotFile { pub id: SnapshotId, } +impl Default for SnapshotFile { + fn default() -> Self { + Self { + time: Local::now(), + program_version: { + let project_version = + option_env!("PROJECT_VERSION").unwrap_or(env!("CARGO_PKG_VERSION")); + format!("rustic {project_version}") + }, + parent: Option::default(), + tree: TreeId::default(), + label: String::default(), + paths: StringList::default(), + hostname: String::default(), + username: String::default(), + uid: Default::default(), + gid: Default::default(), + tags: StringList::default(), + original: Option::default(), + delete: DeleteOption::default(), + summary: Option::default(), + description: Option::default(), + id: SnapshotId::default(), + } + } +} + impl SnapshotFile { /// Create a [`SnapshotFile`] from [`SnapshotOptions`]. /// diff --git a/deny.toml b/deny.toml index 6c630191..ac487054 100644 --- a/deny.toml +++ b/deny.toml @@ -76,8 +76,6 @@ ignore = [ "RUSTSEC-2023-0071", # FIXME: backoff => used in backend, need to be replaced with backon "RUSTSEC-2024-0384", - # FIXME: derivative => used for default impls - "RUSTSEC-2024-0388", # { id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, # "a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish # { crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" }, From 640ed581391da2fcf39cb88b159a4b1cdc1dfb48 Mon Sep 17 00:00:00 2001 From: simonsan <14062932+simonsan@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:46:11 +0100 Subject: [PATCH 2/2] remove from cargo-deny cargo-audit configs Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com> --- .cargo/audit.toml | 2 -- deny.toml | 2 -- 2 files changed, 4 deletions(-) diff --git a/.cargo/audit.toml b/.cargo/audit.toml index 0bc8ac81..0b118933 100644 --- a/.cargo/audit.toml +++ b/.cargo/audit.toml @@ -3,6 +3,4 @@ ignore = [ # FIXME!: See https://github.com/RustCrypto/RSA/issues/19#issuecomment-1822995643. # There is no workaround available yet. "RUSTSEC-2023-0071", - # FIXME: derivative => used for default impls - "RUSTSEC-2024-0388", ] diff --git a/deny.toml b/deny.toml index cf9ba173..d2c10e72 100644 --- a/deny.toml +++ b/deny.toml @@ -74,8 +74,6 @@ ignore = [ # FIXME!: See https://github.com/RustCrypto/RSA/issues/19#issuecomment-1822995643. # There is no workaround available yet. "RUSTSEC-2023-0071", - # FIXME: derivative => used for default impls - "RUSTSEC-2024-0388", # { id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, # "a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish # { crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" },