From 5303301d3dd53e7c7a11b6c97635c2b08d5bd104 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 9 Jan 2017 19:25:58 -0700 Subject: [PATCH] Download packages from repo --- .gitignore | 1 + Cargo.toml | 1 + src/bin/installer.rs | 2 ++ src/install/mod.rs | 26 +++++++++++++++----------- src/lib.rs | 2 ++ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 7661fb4fad..7ce871f5aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ Cargo.lock +pkg sysroot target diff --git a/Cargo.toml b/Cargo.toml index 7e1e2ca24b..ce3e8c2c4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ path = "src/lib.rs" [dependencies] liner = "0.1" +pkgutils = { git = "https://github.com/redox-os/pkgutils.git" } rand = "0.3" serde = "0.8" serde_derive = "0.8" diff --git a/src/bin/installer.rs b/src/bin/installer.rs index 10fc634626..525312e4f6 100644 --- a/src/bin/installer.rs +++ b/src/bin/installer.rs @@ -1,3 +1,5 @@ +#![deny(warnings)] + extern crate redox_installer; extern crate serde; extern crate toml; diff --git a/src/install/mod.rs b/src/install/mod.rs index 0307d08610..f87f600701 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -1,4 +1,5 @@ extern crate liner; +extern crate pkgutils; extern crate rand; extern crate tar; extern crate termion; @@ -11,7 +12,7 @@ use self::termion::input::TermRead; use std::{env, fs}; use std::io::{self, Read, Write}; use std::os::unix::fs::OpenOptionsExt; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::str::FromStr; use config::Config; @@ -147,19 +148,22 @@ pub fn install(config: Config) -> Result<(), String> { }}; } - macro_rules! pkg { - ($path:expr) => {{ - let path = PathBuf::from($path); - println!("Extract package {}", path.display()); - let file = fs::File::open(&path).map_err(|err| format!("failed to open {}: {}", path.display(), err))?; - extract_inner(&mut Archive::new(file), &sysroot).map_err(|err| format!("failed to extract {}: {}", path.display(), err))?; - }}; - } - dir!(""); for (packagename, _package) in config.packages { - pkg!(&format!("../cookbook/repo/x86_64-unknown-redox/{}.tar", packagename)); + let remote_path = format!("{}/{}.tar", pkgutils::REPO_REMOTE, $name); + let local_path = format!("pkg/{}.tar", $name); + if let Some(parent) = Path::new(&local_path).parent() { + println!("Create package repository {}", parent.display()); + fs::create_dir_all(parent).map_err(|err| format!("failed to create package repository {}: {}", parent.display(), err))?; + } + println!("Download package {} to {}", remote_path, local_path); + pkgutils::download(&remote_path, &local_path).map_err(|err| format!("failed to download {} to {}: {}", remote_path, local_path, err))?; + + let path = Path::new(&local_path); + println!("Extract package {}", path.display()); + let file = fs::File::open(&path).map_err(|err| format!("failed to open {}: {}", path.display(), err))?; + extract_inner(&mut Archive::new(file), &sysroot).map_err(|err| format!("failed to extract {}: {}", path.display(), err))?; } for file in config.files { diff --git a/src/lib.rs b/src/lib.rs index 2d6a50608d..3fe6a21d2e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(warnings)] + #[macro_use] extern crate serde_derive;