Now does pkgnames right
This commit is contained in:
parent
b51037c42e
commit
8deb3e4953
2 changed files with 13 additions and 7 deletions
BIN
pack
Executable file
BIN
pack
Executable file
Binary file not shown.
20
src/main.rs
20
src/main.rs
|
@ -1,5 +1,6 @@
|
|||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use std::io::Read;
|
||||
|
||||
use reqwest::Client;
|
||||
use reqwest::header::ETAG;
|
||||
|
@ -11,16 +12,17 @@ fn main() -> Result<(), std::io::Error> {
|
|||
|
||||
let args: Vec<_> = std::env::args().collect();
|
||||
if args.len() < 2 {
|
||||
println!("Please enter a package name...");
|
||||
println!("[PACK]: Please enter a package name...");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let split = args[1].as_str().split("::");
|
||||
let vec: Vec<&str> = split.collect();
|
||||
|
||||
println!("Downloading {}", vec[0]);
|
||||
println!("[PACK]: Downloading {}", vec[0]);
|
||||
|
||||
if !Path::new(format!("/usr/pack/repo/{}", vec[1]).as_str()).exists() {
|
||||
println!("Path /usr/pack/repo/{} does not exist. Please setup your environment.", vec[1]);
|
||||
println!("[PACK]: Path /usr/pack/repo/{} does not exist. Please setup your environment.", vec[1]);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
|
@ -28,16 +30,20 @@ fn main() -> Result<(), std::io::Error> {
|
|||
let mut resp = client.get(vec[0])
|
||||
.send().expect("Failed to make request");
|
||||
|
||||
let full_path: Vec<&str> = vec[0].split("/").collect();
|
||||
let pkgname = full_path[full_path.len() - 1];
|
||||
|
||||
if resp.status().is_success() {
|
||||
println!("OK");
|
||||
if let Some(etag) = resp.headers().get(ETAG) {
|
||||
std::fs::write("etag", etag.as_bytes()).expect("Failed to write ETAG...");
|
||||
}
|
||||
|
||||
let mut file = match File::create(format!("/usr/pack/{}/tarballs/bash.pkg.tar.xz", vec[1])) {
|
||||
let mut file = match File::create(format!("/usr/pack/repo/{}/tarballs/{}", vec[1], pkgname)) {
|
||||
Ok(res) => res,
|
||||
Err(_) => {
|
||||
println!("Failed to create file...did you setup arch? Do you have permission to create files?");
|
||||
Err(e) => {
|
||||
println!("Failed to create file...did you setup you environment? Do you have permission to create files?");
|
||||
println!("\nError: {}", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
@ -48,7 +54,7 @@ fn main() -> Result<(), std::io::Error> {
|
|||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let archive = File::open(format!("/usr/pack/repo/{}/tarballs/bash.pkg.tar.xz")).expect("Failed to open tar...");
|
||||
let mut archive = File::open(format!("/usr/pack/repo/{}/tarballs/{}", vec[1], pkgname)).expect("Failed to open tar...");
|
||||
let mut tar = Vec::new();
|
||||
archive.read_to_end(&mut tar).expect("Failed to read tar...");
|
||||
|
||||
|
|
Loading…
Reference in a new issue