Skip to content

Commit

Permalink
Enable try_io_result for rustsec_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Dec 9, 2023
1 parent 1f557ab commit 8cd2951
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions rustsec_util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ libraries = [
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/supplementary" },
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/restriction/inconsistent_qualification" },
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/restriction/suboptimal_pattern" },
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/restriction/try_io_result" },
]
6 changes: 4 additions & 2 deletions rustsec_util/src/bin/rustsec_advisories.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{ensure, Result};
use anyhow::{ensure, Context, Result};
use cargo_metadata::MetadataCommand;
use once_cell::sync::Lazy;
use regex::Regex;
Expand Down Expand Up @@ -44,7 +44,9 @@ fn main() -> Result<()> {

for advisory in advisories {
print!("{}...", advisory.metadata.package);
std::io::stdout().flush()?;
std::io::stdout()
.flush()
.with_context(|| "failed to flush stdout")?;

let tempdir = test_package(advisory.metadata.package.as_str())?;

Expand Down
6 changes: 4 additions & 2 deletions rustsec_util/src/bin/rustsec_issues.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{Context, Result};
use log::debug;
use once_cell::sync::Lazy;
use regex::Regex;
Expand Down Expand Up @@ -66,7 +66,9 @@ fn main() -> Result<()> {
}
checked.insert(name);
print!("{name}...");
std::io::stdout().flush()?;
std::io::stdout()
.flush()
.with_context(|| "failed to flush stdout")?;
if is_unmaintained(name)? {
println!("found");
advisory_outcomes.push((name, advisory_url.clone(), Outcome::Found));
Expand Down
15 changes: 10 additions & 5 deletions rustsec_util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{ensure, Result};
use anyhow::{ensure, Context, Result};
use once_cell::sync::Lazy;
use std::{
env::consts::EXE_SUFFIX,
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn display_advisory_outcomes<T: MaybeToString + PartialEq + strum::IntoEnumI
}

pub fn test_package(package: &str) -> Result<TempDir> {
let tempdir = tempdir()?;
let tempdir = tempdir().with_context(|| "failed to create temporary directory")?;

let output = command_output(
Command::new("cargo")
Expand All @@ -91,10 +91,13 @@ pub fn test_package(package: &str) -> Result<TempDir> {
)?;
ensure!(output.status.success());

let path = tempdir.path().join("Cargo.toml");
let mut manifest = OpenOptions::new()
.append(true)
.open(tempdir.path().join("Cargo.toml"))?;
writeln!(manifest, r#"{package} = "*""#)?;
.open(&path)
.with_context(|| format!("failed to open {path:?}"))?;
writeln!(manifest, r#"{package} = "*""#)
.with_context(|| format!("failed to write to {path:?}"))?;

Ok(tempdir)
}
Expand All @@ -119,7 +122,9 @@ pub fn cargo_unmaintained(name: &str, dir: &Path) -> Command {

#[cfg_attr(dylint_lib = "general", allow(non_local_effect_before_error_return))]
pub fn command_output(command: &mut Command) -> Result<Output> {
let output = command.output()?;
let output = command
.output()
.with_context(|| format!("failed to execute command: {command:?}"))?;
let status = output.status;
let stdout = String::from_utf8(output.stdout)?;
let stderr = String::from_utf8(output.stderr)?;
Expand Down

0 comments on commit 8cd2951

Please sign in to comment.