Fix handling of the database.fetch option #1302
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue and fix overview
This PR fixes #1072 and personal issues using
cargo audit
in an environment without access to the Internet.cargo audit
will still fetch even if the config file has setfetch
to false, requiring the--no-fetch
option to always be supplied in the CLI.The problems are that:
database.fetch
is set to false by default rather than true as the documentation saysrustsec/cargo-audit/src/cli_config.rs
Line 64 in 329bf88
When the config file is set to false, and the
--no-fetch
option is not supplied, this computesconfig.database.fetch = false | true
=true
, when the expected behaviour is that as no CLI flag is provided to overwrite the config file, the config file should be respected.This PR fixes the problem by:
This PR adjusts the logic to use bitwise AND
config.database.fetch &= !self.no_fetch
, so that the following results are computed:Issue reproduction
The issue can be observed by performing the following:
cargo test override_default_fetch_option
database.fetch
is false rather than true by defaultcargo-audit/src/config.rs
from this PR and run the test case again