Skip to content
Snippets Groups Projects
Unverified Commit bb56cee6 authored by Ian Douglas Scott's avatar Ian Douglas Scott
Browse files

Let pkgutils handle downloading and extracting package

parent 4e9d22ad
No related branches found
No related tags found
1 merge request!2Use install methods from pkgutils, and allow installing directly from cookbook with --cookbook=path
...@@ -16,7 +16,6 @@ pkgutils = { git = "https://github.com/redox-os/pkgutils.git" } ...@@ -16,7 +16,6 @@ pkgutils = { git = "https://github.com/redox-os/pkgutils.git" }
rand = "0.3" rand = "0.3"
serde = "0.8" serde = "0.8"
serde_derive = "0.8" serde_derive = "0.8"
tar = { git = "https://github.com/redox-os/tar-rs.git" }
termion = "1.1" termion = "1.1"
toml = { version = "0.2", default-features = false, features = ["serde"] } toml = { version = "0.2", default-features = false, features = ["serde"] }
userutils = { git = "https://github.com/redox-os/userutils.git" } userutils = { git = "https://github.com/redox-os/userutils.git" }
extern crate liner; extern crate liner;
extern crate pkgutils; extern crate pkgutils;
extern crate rand; extern crate rand;
extern crate tar;
extern crate termion; extern crate termion;
extern crate userutils; extern crate userutils;
use self::rand::Rng; use self::rand::Rng;
use self::tar::{Archive, EntryType};
use self::termion::input::TermRead; use self::termion::input::TermRead;
use self::pkgutils::Repo;
use std::{env, fs}; use std::{env, fs};
use std::io::{self, Read, Write}; use std::io::{self, Write};
use std::os::unix::fs::OpenOptionsExt;
use std::path::Path;
use std::str::FromStr; use std::str::FromStr;
use config::Config; use config::Config;
const REMOTE: &'static str = "https://static.redox-os.org/pkg";
const TARGET: &'static str = "x86_64-unknown-redox";
fn unwrap_or_prompt<T: FromStr>(option: Option<T>, context: &mut liner::Context, prompt: &str) -> Result<T, String> { fn unwrap_or_prompt<T: FromStr>(option: Option<T>, context: &mut liner::Context, prompt: &str) -> Result<T, String> {
match option { match option {
None => { None => {
...@@ -63,46 +63,6 @@ fn prompt_password(prompt: &str, confirm_prompt: &str) -> Result<String, String> ...@@ -63,46 +63,6 @@ fn prompt_password(prompt: &str, confirm_prompt: &str) -> Result<String, String>
} }
} }
fn extract_inner<T: Read>(ar: &mut Archive<T>, root: &Path) -> io::Result<()> {
for entry_result in try!(ar.entries()) {
let mut entry = try!(entry_result);
match entry.header().entry_type() {
EntryType::Regular => {
let mut file = {
let mut path = root.to_path_buf();
path.push(try!(entry.path()));
if let Some(parent) = path.parent() {
println!("Extract file parent {}", parent.display());
try!(fs::create_dir_all(parent));
}
println!("Extract file {}", path.display());
try!(
fs::OpenOptions::new()
.read(true)
.write(true)
.truncate(true)
.create(true)
.mode(entry.header().mode().unwrap_or(644))
.open(path)
)
};
try!(io::copy(&mut entry, &mut file));
},
EntryType::Directory => {
let mut path = root.to_path_buf();
path.push(try!(entry.path()));
println!("Extract directory {}", path.display());
try!(fs::create_dir_all(path));
},
other => {
panic!("Unsupported entry type {:?}", other);
}
}
}
Ok(())
}
pub fn install(config: Config) -> Result<(), String> { pub fn install(config: Config) -> Result<(), String> {
println!("Install {:#?}", config); println!("Install {:#?}", config);
...@@ -155,20 +115,13 @@ pub fn install(config: Config) -> Result<(), String> { ...@@ -155,20 +115,13 @@ pub fn install(config: Config) -> Result<(), String> {
dir!(""); dir!("");
for (packagename, _package) in config.packages { let mut repo = Repo::new(TARGET);
let remote_path = format!("{}/{}/{}.tar", "https://static.redox-os.org/pkg", "x86_64-unknown-redox", packagename); repo.add_remote(REMOTE);
let local_path = format!("pkg/{}.tar", packagename); repo.set_dest(sysroot.to_str().unwrap());
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); for (packagename, _package) in config.packages {
println!("Extract package {}", path.display()); println!("Installing package {}", packagename);
let file = fs::File::open(&path).map_err(|err| format!("failed to open {}: {}", path.display(), err))?; repo.install(&packagename).unwrap();
extract_inner(&mut Archive::new(file), &sysroot).map_err(|err| format!("failed to extract {}: {}", path.display(), err))?;
} }
for file in config.files { for file in config.files {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment