Created
July 21, 2023 06:51
-
-
Save rtyler/2f6d4653d92820710fca48bcfca4e8bc to your computer and use it in GitHub Desktop.
build.rs for fetching dat tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! Build script for DAT | |
use std::fs::File; | |
use std::io::{BufReader, BufWriter, Write}; | |
use std::path::Path; | |
use flate2::read::GzDecoder; | |
use tar::Archive; | |
const DAT_EXISTS_FILE_CHECK: &str = "tests/dat/.done"; | |
const OUTPUT_FOLDER: &str = "tests/dat"; | |
const VERSION: &str = "0.0.2"; | |
fn main() { | |
if dat_exists() { | |
return; | |
} | |
let tarball_data = download_dat_files(); | |
extract_tarball(tarball_data); | |
write_done_file(); | |
} | |
fn dat_exists() -> bool { | |
Path::new(DAT_EXISTS_FILE_CHECK).exists() | |
} | |
fn download_dat_files() -> Vec<u8> { | |
let tarball_url = format!( | |
"https://github.com/delta-incubator/dat/releases/download/v{version}/deltalake-dat-v{version}.tar.gz", | |
version = VERSION | |
); | |
let response = ureq::get(&tarball_url).call().unwrap(); | |
let mut tarball_data: Vec<u8> = Vec::new(); | |
response | |
.into_reader() | |
.read_to_end(&mut tarball_data) | |
.unwrap(); | |
tarball_data | |
} | |
fn extract_tarball(tarball_data: Vec<u8>) { | |
let tarball = GzDecoder::new(BufReader::new(&tarball_data[..])); | |
let mut archive = Archive::new(tarball); | |
std::fs::create_dir_all(OUTPUT_FOLDER).expect("Failed to create output directory"); | |
archive | |
.unpack(OUTPUT_FOLDER) | |
.expect("Failed to unpack tarball"); | |
} | |
fn write_done_file() { | |
let mut done_file = | |
BufWriter::new(File::create(DAT_EXISTS_FILE_CHECK).expect("Failed to create .done file")); | |
write!(done_file, "done").expect("Failed to write .done file"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment