libyaml-safer/tests/data/build.rs
David Tolnay 447a4caa09
Resolve needless_borrow pedantic clippy lint in test
error: the borrowed expression implements the required traits
      --> tests/data/build.rs:23:43
       |
    23 |     let response = reqwest::blocking::get(&url)?.error_for_status()?;
       |                                           ^^^^ help: change this to: `url`
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
       = note: `-D clippy::needless-borrow` implied by `-D clippy::all`
2022-10-24 21:33:15 -07:00

46 lines
1.3 KiB
Rust

#![allow(clippy::uninlined_format_args)]
use anyhow::Result;
use flate2::read::GzDecoder;
use std::fs;
use std::path::Path;
use tar::Archive;
const TAG: &str = "data-2020-02-11";
fn main() {
let needs_clone = match fs::read_to_string("yaml-test-suite/COMMIT") {
Err(_) => true,
Ok(contents) => contents.trim() != TAG,
};
if needs_clone {
download_and_unpack().unwrap();
}
}
fn download_and_unpack() -> Result<()> {
let url = format!("https://github.com/yaml/yaml-test-suite/archive/refs/tags/{TAG}.tar.gz");
let response = reqwest::blocking::get(url)?.error_for_status()?;
let decoder = GzDecoder::new(response);
let mut archive = Archive::new(decoder);
let prefix = format!("yaml-test-suite-{}", TAG);
let yaml_test_suite = Path::new("yaml-test-suite");
if yaml_test_suite.exists() {
fs::remove_dir_all(yaml_test_suite)?;
}
for entry in archive.entries()? {
let mut entry = entry?;
let path = entry.path()?;
if path == Path::new("pax_global_header") {
continue;
}
let relative = path.strip_prefix(&prefix)?;
let out = yaml_test_suite.join(relative);
entry.unpack(&out)?;
}
fs::write("yaml-test-suite/COMMIT", TAG)?;
Ok(())
}