Skip to content

Commit

Permalink
chore(deps): remove Derivative and replace with Default impl due to R…
Browse files Browse the repository at this point in the history
…USTSEC-2024-0388 (#359)

Fixes #350

---------

Signed-off-by: simonsan <[email protected]>
  • Loading branch information
simonsan authored Nov 18, 2024
1 parent 1d1a596 commit ea8d3cd
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 35 deletions.
2 changes: 0 additions & 2 deletions .cargo/audit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
12 changes: 0 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
17 changes: 13 additions & 4 deletions crates/core/src/blob/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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>
Expand Down
75 changes: 61 additions & 14 deletions crates/core/src/repofile/snapshotfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -229,11 +227,9 @@ pub struct SnapshotSummary {
/// # Note
///
/// This may differ from the snapshot `time`.
#[derivative(Default(value = "Local::now()"))]
pub backup_start: DateTime<Local>,

/// The time that the backup has been finished.
#[derivative(Default(value = "Local::now()"))]
pub backup_end: DateTime<Local>,

/// Total duration of the backup in seconds, i.e. the time between `backup_start` and `backup_end`
Expand All @@ -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`].
///
Expand All @@ -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,
Expand All @@ -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/<ID>`
Expand All @@ -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<Local>,

/// 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,

Expand Down Expand Up @@ -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`].
///
Expand Down
2 changes: 0 additions & 2 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
# "[email protected]", # you can also ignore yanked crate versions if you wish
# { crate = "[email protected]", reason = "you can specify why you are ignoring the yanked crate" },
Expand Down

0 comments on commit ea8d3cd

Please sign in to comment.