pack/src/main.rs

37 lines
1.1 KiB
Rust

extern crate flate2;
extern crate tar;
use flate2::read::GzDecoder;
use tar::Archive;
use std::fs::File;
use std::io::prelude::*;
use reqwest::Client;
use reqwest::header::ETAG;
fn main() -> Result<(), std::io::Error> {
let client = Client::new();
let mut resp = client.get("http://mirrors.advancedhosters.com/archlinux/core/os/x86_64/bash-5.0.009-1-x86_64.pkg.tar.xz")
.send().expect("Failed to make request");
if resp.status().is_success() {
if let Some(etag) = resp.headers().get(ETAG) {
std::fs::write("etag", etag.as_bytes()).expect("Failed to write ETAG...");
}
let mut file = File::create("/imperfect/repo/arch/tarballs/bash.pkg.tar.xz").expect("file creation failed. Did you setup arch? Do you have permission?");
resp.copy_to(&mut file).expect("failed to write file");
}
let path = "/imperfect/pkgs/tarballs/bash.pkg.tar.xz";
let tar_gz = File::open(path).expect("Failed to open tar file...");
let tar = GzDecoder::new(tar_gz);
let mut archive = Archive::new(tar);
archive.unpack("/imperfect/pkgs/tarball").expect("Could not unpack tarball");
Ok(())
}