Changeset View
Changeset View
Standalone View
Standalone View
security/cargo-audit/files/patch-src_main.rs
- This file was added.
Property | Old Value | New Value |
---|---|---|
fbsd:nokeywords | null | yes \ No newline at end of property |
svn:eol-style | null | native \ No newline at end of property |
svn:mime-type | null | text/plain \ No newline at end of property |
--- src/main.rs.orig 2018-07-29 21:14:21 UTC | |||||
+++ src/main.rs | |||||
@@ -59,6 +59,14 @@ struct AuditOpts { | |||||
)] | |||||
db: Option<String>, | |||||
+ /// Fetch/update the advisory database and exit | |||||
+ #[options( | |||||
+ no_short, | |||||
+ long = "fetch-only", | |||||
+ help = "fetch the advisory database and exit" | |||||
+ )] | |||||
+ fetch_only: bool, | |||||
+ | |||||
/// Path to the advisory database git repository | |||||
#[options( | |||||
short = "f", | |||||
@@ -67,6 +75,14 @@ struct AuditOpts { | |||||
)] | |||||
file: Option<String>, | |||||
+ /// Do not allow network connections | |||||
+ #[options( | |||||
+ no_short, | |||||
+ long = "offline", | |||||
+ help = "do not allow network connections" | |||||
+ )] | |||||
+ offline: bool, | |||||
+ | |||||
/// Allow stale advisory databases that haven't been recently updated | |||||
#[options(no_short, long = "stale", help = "allow stale database")] | |||||
stale: bool, | |||||
@@ -108,7 +124,9 @@ impl Default for AuditOpts { | |||||
AuditOpts { | |||||
color: "auto".into(), | |||||
db: None, | |||||
+ fetch_only: false, | |||||
file: None, | |||||
+ offline: false, | |||||
stale: false, | |||||
target_arch: None, | |||||
target_os: None, | |||||
@@ -170,13 +188,19 @@ fn load_advisory_db(opts: &AuditOpts) -> AdvisoryDatab | |||||
.map(PathBuf::from) | |||||
.unwrap_or_else(Repository::default_path); | |||||
- status_ok!("Fetching", "advisory database from `{}`", opts.url); | |||||
+ let advisory_db_repo = if opts.offline { | |||||
+ Repository::open(&advisory_repo_path) | |||||
+ } else { | |||||
+ status_ok!("Fetching", "advisory database from `{}`", opts.url); | |||||
+ Repository::fetch(&opts.url, &advisory_repo_path, !opts.stale) | |||||
+ }.unwrap_or_else(|e| { | |||||
+ status_error!("couldn't fetch advisory database: {}", e); | |||||
+ exit(1); | |||||
+ }); | |||||
- let advisory_db_repo = Repository::fetch(&opts.url, &advisory_repo_path, !opts.stale) | |||||
- .unwrap_or_else(|e| { | |||||
- status_error!("couldn't fetch advisory database: {}", e); | |||||
- exit(1); | |||||
- }); | |||||
+ if opts.fetch_only { | |||||
+ exit(0); | |||||
+ } | |||||
let advisory_db = AdvisoryDatabase::from_repository(&advisory_db_repo).unwrap_or_else(|e| { | |||||
status_error!("error loading advisory database: {}", e); |