Skip to content

Commit

Permalink
Fix advisory db path resolution (#303)
Browse files Browse the repository at this point in the history
* Fix unintended behavior change in 0.8.0

* Update CHANGELOG

* Remove smush, add back tame-gcs
  • Loading branch information
Jake-Shadle authored Oct 22, 2020
1 parent ae0224f commit 38be1dd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [Unreleased] - ReleaseDate
### Fixed
- [PR#303](https://github.com/EmbarkStudios/cargo-deny/pull/303) fixed [#302](https://github.com/EmbarkStudios/cargo-deny/issues/302) by reverting an unintended behavior change in how the default path for advisory databases was resolved.

## [0.8.1] - 2020-10-21
### Fixed
- [PR#297](https://github.com/EmbarkStudios/cargo-deny/pull/297) fixed a couple of diagnostics to have codes.
Expand Down
4 changes: 2 additions & 2 deletions scripts/check_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const REPOS: &[&str] = &[
//"git://github.com/EmbarkStudios/cargo-fetcher.git",
"git://github.com/bitshifter/glam-rs.git",
"git://github.com/EmbarkStudios/physx-rs.git",
"git://github.com/gwihlidal/smush-rs.git",
//"git://github.com/EmbarkStudios/tame-gcs.git",
//"git://github.com/gwihlidal/smush-rs.git",
"git://github.com/EmbarkStudios/tame-gcs.git",
"git://github.com/EmbarkStudios/tame-oauth.git",
"git://github.com/EmbarkStudios/texture-synthesis.git",
//"git://github.com/hyperium/tonic.git",
Expand Down
2 changes: 1 addition & 1 deletion src/advisories/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn yanked() -> Spanned<LintLevel> {
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct Config {
/// Path to the root directory where advisory databases are stored (default: ~/.cargo/advisory-dbs)
/// Path to the root directory where advisory databases are stored (default: $CARGO_HOME/advisory-dbs)
pub db_path: Option<PathBuf>,
/// URL to the advisory database's git repo (default: https://github.com/RustSec/advisory-db)
pub db_url: Option<Spanned<String>>,
Expand Down
42 changes: 23 additions & 19 deletions src/advisories/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ pub use rustsec::{advisory::Id, lockfile::Lockfile, Database, Vulnerability};
use std::path::{Path, PathBuf};
use url::Url;

const ADVISORY_DB_ROOT: &str = "~/.cargo/advisory-dbs";

/// Whether the database will be fetched or not
#[derive(Copy, Clone)]
pub enum Fetch {
Expand All @@ -28,25 +26,31 @@ impl DbSet {
mut urls: Vec<Url>,
fetch: Fetch,
) -> Result<Self, Error> {
let root = root
.as_ref()
.map(AsRef::as_ref)
.unwrap_or_else(|| Path::new(ADVISORY_DB_ROOT));

let root_db_path = if root.starts_with("~") {
match home::home_dir() {
Some(home) => home.join(root.strip_prefix("~").unwrap()),
None => {
log::warn!(
"unable to resolve path '{}', falling back to the default advisory path",
root.display()
);

home::cargo_home().context("failed to resolve CARGO_HOME")?
let root_db_path = match root {
Some(root) => {
let user_root = root.as_ref();
if user_root.starts_with("~") {
match home::home_dir() {
Some(home) => home.join(user_root.strip_prefix("~").unwrap()),
None => {
log::warn!(
"unable to resolve path '{}', falling back to the default advisory path",
user_root.display()
);

// This would only succeed of CARGO_HOME was explicitly set
home::cargo_home()
.context("failed to resolve CARGO_HOME")?
.join("advisory-dbs")
}
}
} else {
user_root.to_owned()
}
}
} else {
root.to_owned()
None => home::cargo_home()
.context("failed to resolve CARGO_HOME")?
.join("advisory-dbs"),
};

if urls.is_empty() {
Expand Down

0 comments on commit 38be1dd

Please sign in to comment.