Skip to content

Commit

Permalink
fix: update dependencies, fix unsafe windows code (#203)
Browse files Browse the repository at this point in the history
* chore: update dependencies to latest

* style: apply automatic clippy fixes

* style: manually fix some clippy errors

* chore: recreate deny.toml

* chore: bump MSRV

* chore: install grcov in Makefile.toml if not present

* style: run cargo fmt

* fix: type error in Windows-only code

* style: run cargo fmt
  • Loading branch information
Shadow53 authored Aug 19, 2024
1 parent 16df032 commit 7ef3bfe
Show file tree
Hide file tree
Showing 14 changed files with 543 additions and 390 deletions.
771 changes: 479 additions & 292 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "BSD-3-Clause"
description = "Hoard backups of files across your filesystem into one location."
homepage = "https://github.com/Shadow53/hoard"
repository = "https://github.com/Shadow53/hoard"
rust-version = "1.70.0"
rust-version = "1.74.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
Expand All @@ -22,8 +22,8 @@ digest = "0.10.7"
futures = { version = "0.3", default-features = false, features = [] }
glob = "0.3"
hex = "0.4.3"
hostname = "0.3"
itertools = "0.11.0"
hostname = "0.4"
itertools = "0.13.0"
md-5 = "0.10.5"
once_cell = "1.15"
open_cmd = { version = "0.1.0", features = ["tracing"] }
Expand All @@ -47,19 +47,19 @@ tracing-subscriber = { version = "0.3", default-features = false, features = ["a
uuid = { version = "1.3", features = ["serde", "v4"] }

[target.'cfg(windows)'.dependencies]
windows = { version = "0.51", features = ["Storage", "Win32_UI_Shell", "Win32_Foundation", "Win32_Globalization"] }
windows = { version = "0.58", features = ["Storage", "Win32_UI_Shell", "Win32_Foundation", "Win32_Globalization"] }

[dev-dependencies]
maplit = "1.0"
rand = "0.8"
serde_test = "1.0"
futures = { version = "0.3", default-features = false, features = ["executor"] }
tokio = { version = "1.28", default-features = false, features = ["process"] }
serial_test = "2.0.0"
serial_test = "3.1.1"

[target.'cfg(windows)'.dev-dependencies]
registry = "1.2"

[target.'cfg(unix)'.dev-dependencies]
nix = "0.27"
nix = "0.29"
pty_closure = "0.1"
1 change: 1 addition & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
dependencies = ["docker-tests", "test-nextest"]

[tasks.grcov]
install_crate = { crate_name = "grcov" }
dependencies = ["clean-all", "test-all"]
# Using `script` is necessary to get the glob expansion
script = """
Expand Down
104 changes: 36 additions & 68 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

# Root options

# The graph table configures how the dependency graph is constructed and thus
# which crates the checks are performed against
[graph]
# If 1 or more target triples (and optionally, target_features) are specified,
# only the specified targets will be checked when running `cargo deny check`.
# This means, if a particular package is only ever used as a target specific
Expand All @@ -22,7 +25,7 @@
targets = [
# The triple can be any string, but only the target triples built in to
# rustc (as of 1.40) can be checked against actual config expressions
#{ triple = "x86_64-unknown-linux-musl" },
#"x86_64-unknown-linux-musl",
# You can also specify which target_features you promise are enabled for a
# particular target. target_features are currently not validated against
# the actual valid features supported by the target architecture.
Expand All @@ -46,6 +49,9 @@ no-default-features = false
# If set, these feature will be enabled when collecting metadata. If `--features`
# is specified on the cmd line they will take precedence over this option.
#features = []

# The output table provides options for how/if diagnostics are outputted
[output]
# When outputting inclusion graphs in diagnostics that include features, this
# option can be used to specify the depth at which feature edges will be added.
# This option is included since the graphs can be quite large and the addition
Expand All @@ -57,35 +63,18 @@ feature-depth = 1
# More documentation for the advisories section can be found here:
# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html
[advisories]
# The path where the advisory database is cloned/fetched into
db-path = "~/.cargo/advisory-db"
# The path where the advisory databases are cloned/fetched into
#db-path = "$CARGO_HOME/advisory-dbs"
# The url(s) of the advisory databases to use
db-urls = ["https://github.com/rustsec/advisory-db"]
# The lint level for security vulnerabilities
vulnerability = "deny"
# The lint level for unmaintained crates
unmaintained = "deny"
# The lint level for crates that have been yanked from their source registry
yanked = "warn"
# The lint level for crates with security notices. Note that as of
# 2019-12-17 there are no security notice advisories in
# https://github.com/rustsec/advisory-db
notice = "warn"
#db-urls = ["https://github.com/rustsec/advisory-db"]
# A list of advisory IDs to ignore. Note that ignored advisories will still
# output a note when they are encountered.
ignore = [
#"RUSTSEC-0000-0000",
#{ 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" },
]
# Threshold for security vulnerabilities, any vulnerability with a CVSS score
# lower than the range specified will be ignored. Note that ignored advisories
# will still output a note when they are encountered.
# * None - CVSS Score 0.0
# * Low - CVSS Score 0.1 - 3.9
# * Medium - CVSS Score 4.0 - 6.9
# * High - CVSS Score 7.0 - 8.9
# * Critical - CVSS Score 9.0 - 10.0
#severity-threshold =

# If this is true, then cargo deny will use the git executable to fetch advisory database.
# If this is false, then it uses a built-in git library.
# Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support.
Expand All @@ -96,38 +85,18 @@ ignore = [
# More documentation for the licenses section can be found here:
# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html
[licenses]
# The lint level for crates which do not have a detectable license
unlicensed = "deny"
# List of explicitly allowed licenses
# See https://spdx.org/licenses/ for list of possible licenses
# [possible values: any SPDX 3.11 short identifier (+ optional exception)].
allow = [
#"MIT",
"Apache-2.0",
"BSD-3-Clause",
"BSL-1.0",
"MIT",
"Unicode-DFS-2016",
#"Apache-2.0",
#"Apache-2.0 WITH LLVM-exception",
]
# List of explicitly disallowed licenses
# See https://spdx.org/licenses/ for list of possible licenses
# [possible values: any SPDX 3.11 short identifier (+ optional exception)].
deny = [
#"Nokia",
]
# Lint level for licenses considered copyleft
copyleft = "deny"
# Blanket approval or denial for OSI-approved or FSF Free/Libre licenses
# * both - The license will be approved if it is both OSI-approved *AND* FSF
# * either - The license will be approved if it is either OSI-approved *OR* FSF
# * osi - The license will be approved if it is OSI approved
# * fsf - The license will be approved if it is FSF Free
# * osi-only - The license will be approved if it is OSI-approved *AND NOT* FSF
# * fsf-only - The license will be approved if it is FSF *AND NOT* OSI-approved
# * neither - This predicate is ignored and the default lint level is used
allow-osi-fsf-free = "either"
# Lint level used when no other predicates are matched
# 1. License isn't in the allow or deny lists
# 2. License isn't copyleft
# 3. License isn't OSI/FSF, or allow-osi-fsf-free = "neither"
default = "deny"
# The confidence threshold for detecting a license from license text.
# The higher the value, the more closely the license text must be to the
# canonical license text of a valid SPDX license file.
Expand All @@ -138,17 +107,15 @@ confidence-threshold = 0.8
exceptions = [
# Each entry is the crate and version constraint, and its specific allow
# list
#{ allow = ["Zlib"], name = "adler32", version = "*" },
#{ allow = ["Zlib"], crate = "adler32" },
]

# Some crates don't have (easily) machine readable licensing information,
# adding a clarification entry for it allows you to manually specify the
# licensing information
#[[licenses.clarify]]
# The name of the crate the clarification applies to
#name = "ring"
# The optional version constraint for the crate
#version = "*"
# The package spec the clarification applies to
#crate = "ring"
# The SPDX expression for the license requirements of the crate
#expression = "MIT AND ISC AND OpenSSL"
# One or more files in the crate's source used as the "source of truth" for
Expand All @@ -157,8 +124,8 @@ exceptions = [
# and the crate will be checked normally, which may produce warnings or errors
# depending on the rest of your configuration
#license-files = [
# Each entry is a crate relative path, and the (opaque) hash of its contents
#{ path = "LICENSE", hash = 0xbd0eed23 }
# Each entry is a crate relative path, and the (opaque) hash of its contents
#{ path = "LICENSE", hash = 0xbd0eed23 }
#]

[licenses.private]
Expand Down Expand Up @@ -198,25 +165,24 @@ workspace-default-features = "allow"
external-default-features = "allow"
# List of crates that are allowed. Use with care!
allow = [
#{ name = "ansi_term", version = "=0.11.0" },
#"[email protected]",
#{ crate = "[email protected]", reason = "you can specify a reason it is allowed" },
]
# List of crates to deny
deny = [
# Each entry the name of a crate and a version range. If version is
# not specified, all versions will be matched.
#{ name = "ansi_term", version = "=0.11.0" },
#
#"[email protected]",
#{ crate = "[email protected]", reason = "you can specify a reason it is banned" },
# Wrapper crates can optionally be specified to allow the crate when it
# is a direct dependency of the otherwise banned crate
#{ name = "ansi_term", version = "=0.11.0", wrappers = [] },
#{ crate = "ansi_term@0.11.0", wrappers = ["this-crate-directly-depends-on-ansi_term"] },
{ name = "serde", version = ">=1.0.172,<=1.0.184" },
]

# List of features to allow/deny
# Each entry the name of a crate and a version range. If version is
# not specified, all versions will be matched.
#[[bans.features]]
#name = "reqwest"
#crate = "reqwest"
# Features to not allow
#deny = ["json"]
# Features to allow
Expand All @@ -237,14 +203,16 @@ deny = [

# Certain crates/versions that will be skipped when doing duplicate detection.
skip = [
#{ name = "ansi_term", version = "=0.11.0" },
#"[email protected]",
#{ crate = "[email protected]", reason = "you can specify a reason why it can't be updated/removed" },
]
# Similarly to `skip` allows you to skip certain crates during duplicate
# detection. Unlike skip, it also includes the entire tree of transitive
# dependencies starting at the specified crate, up to a certain depth, which is
# by default infinite.
skip-tree = [
#{ name = "ansi_term", version = "=0.11.0", depth = 20 },
#"[email protected]", # will be skipped along with _all_ of its direct and transitive dependencies
#{ crate = "[email protected]", depth = 20 },
]

# This section is considered when running `cargo deny check sources`.
Expand All @@ -264,9 +232,9 @@ allow-registry = ["https://github.com/rust-lang/crates.io-index"]
allow-git = []

[sources.allow-org]
# 1 or more github.com organizations to allow git sources for
# github.com organizations to allow git sources for
github = []
# 1 or more gitlab.com organizations to allow git sources for
# gitlab.com organizations to allow git sources for
gitlab = []
# 1 or more bitbucket.org organizations to allow git sources for
# bitbucket.org organizations to allow git sources for
bitbucket = []
4 changes: 2 additions & 2 deletions src/checkers/history/operation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl Operation {
///
/// [`Error::UpgradeRequired`] if this `Operation` is not the most recent schema.
pub fn as_latest_version(&self) -> Result<&Self, Error> {
self.require_latest_version().map(|_| self)
self.require_latest_version().map(|()| self)
}

/// Returns the owned `Operation` if it is the most recent schema version, otherwise returns an error.
Expand All @@ -405,7 +405,7 @@ impl Operation {
///
/// [`Error::UpgradeRequired`] if this `Operation` is not the most recent schema.
pub fn into_latest_version(self) -> Result<Self, Error> {
self.require_latest_version().map(|_| self)
self.require_latest_version().map(|()| self)
}

#[tracing::instrument(name = "operation_from_file")]
Expand Down
4 changes: 2 additions & 2 deletions src/checkers/history/operation/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ pub(crate) async fn cleanup_operations() -> Result<u32, (u32, Error)> {
})
// Return the first error or the number of files deleted.
.fold(Ok((0, ())), |acc, res2| async move {
let (count, _) = acc?;
let (count, ()) = acc?;
res2.map_err(|err| (count, err))?;
Ok((count + 1, ()))
})
.await
.map(|(count, _)| count)
.map(|(count, ())| count)
}

#[tracing::instrument(level = "trace")]
Expand Down
4 changes: 2 additions & 2 deletions src/checkers/history/operation/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl OperationV2 {
.difference(&these_files)
.fold(HashMap::new(), |mut acc, (pile_name, rel_path)| {
acc.entry(pile_name.clone())
.or_insert_with(HashSet::new)
.or_default()
.insert(rel_path.clone());
acc
});
Expand Down Expand Up @@ -454,7 +454,7 @@ impl Pile {
.get(rel_path)
.or_else(|| self.modified.get(rel_path))
.or_else(|| self.unmodified.get(rel_path))
.map(Clone::clone)
.cloned()
}

fn all_files_with_checksums(&self) -> impl Iterator<Item = (&RelativePath, Option<Checksum>)> {
Expand Down
6 changes: 3 additions & 3 deletions src/checksum/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ pub trait Digestable: sealed::Sealed {
}

impl Digestable for md5::Md5 {
type OutputSize = <md5::Md5 as md5::digest::OutputSizeUser>::OutputSize;
type OutputSize = <md5::Md5 as digest::OutputSizeUser>::OutputSize;
const DIGEST_NAME: &'static str = "MD5";
fn digest_to_array<D: AsRef<[u8]>>(data: D) -> GenericArray<u8, Self::OutputSize> {
<md5::Md5 as md5::Digest>::digest(data.as_ref())
}
}

impl Digestable for sha2::Sha256 {
type OutputSize = <sha2::Sha256 as sha2::digest::OutputSizeUser>::OutputSize;
type OutputSize = <sha2::Sha256 as digest::OutputSizeUser>::OutputSize;
const DIGEST_NAME: &'static str = "SHA256";
fn digest_to_array<D: AsRef<[u8]>>(data: D) -> GenericArray<u8, Self::OutputSize> {
<sha2::Sha256 as sha2::Digest>::digest(data.as_ref())
Expand Down Expand Up @@ -119,7 +119,7 @@ where
<<T as Digestable>::OutputSize as Add>::Output: ArrayLength<u8>,
{
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.partial_cmp(&other.0)
Some(self.0.cmp(&other.0))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/config/builder/environment/exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Deref for Executable {

impl fmt::Display for Executable {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
std::fmt::Display::fmt(&self.0.display(), f)
fmt::Display::fmt(&self.0.display(), f)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ pub enum Diff {
Text(String),
/// Binary content differs. Also occurs if a file changes between text and binary formats.
Binary,
/// The left path to diff_files did not exist, but the right path did.
/// The left path to `diff_files` did not exist, but the right path did.
HoardNotExists,
/// The left path to diff_paths existed, but the right path did not.
/// The left path to `diff_paths` existed, but the right path did not.
SystemNotExists,
}

Expand Down
12 changes: 7 additions & 5 deletions src/dirs/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ fn pwstr_len(pwstr: PWSTR) -> usize {
#[allow(unsafe_code)]
pub fn get_known_folder(folder_id: GUID) -> WinResult<PathBuf> {
unsafe {
SHGetKnownFolderPath(&folder_id, KF_FLAG_CREATE, HANDLE(0)).map(|pwstr| {
let slice = std::slice::from_raw_parts(pwstr.0, pwstr_len(pwstr));
PathBuf::from(OsString::from_wide(slice))
})
SHGetKnownFolderPath(&folder_id, KF_FLAG_CREATE, HANDLE(std::ptr::null_mut())).map(
|pwstr| {
let slice = std::slice::from_raw_parts(pwstr.0, pwstr_len(pwstr));
PathBuf::from(OsString::from_wide(slice))
},
)
}
}

Expand All @@ -57,7 +59,7 @@ pub fn set_known_folder(folder_id: GUID, new_path: &Path) -> WinResult<()> {
unsafe {
let new_path: Vec<u16> = new_path.as_os_str().encode_wide().chain([0]).collect();
let new_path = PCWSTR(new_path.as_ptr());
SHSetKnownFolderPath(&folder_id, 0, HANDLE(0), new_path)
SHSetKnownFolderPath(&folder_id, 0, HANDLE(std::ptr::null_mut()), new_path)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/hoard/pile_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl Config {
fn layer(&mut self, other: &Self) {
// Overlay a more general encryption config, if a specific one doesn't exist.
if self.encryption.is_none() {
self.encryption = other.encryption.clone();
self.encryption.clone_from(&other.encryption);
}

self.checksum_type = self.checksum_type.or(other.checksum_type);
Expand Down
Loading

0 comments on commit 7ef3bfe

Please sign in to comment.