-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathpack.rs
63 lines (54 loc) · 1.81 KB
/
pack.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use std::io::{stderr, Write};
use std::path::Path;
use unshare::{Command, Stdio};
use crate::capsule::packages as capsule;
use crate::options::pack::Options;
use crate::process_util::{convert_status, cmd_show, cmd_err};
use crate::wrapper::Wrapper;
use super::setup;
pub fn pack_image_cmd(wrapper: &Wrapper, cmdline: Vec<String>)
-> Result<i32, String>
{
let options = match Options::parse(&cmdline) {
Ok(x) => x,
Err(code) => return Ok(code),
};
setup::setup_base_filesystem(
wrapper.project_root, wrapper.ext_settings)?;
let mut capsule_features = vec!();
let container_ver = wrapper.root.as_ref().unwrap();
let root = Path::new("/vagga/base/.roots")
.join(container_ver)
.join("root");
let mut tar_cmd = Command::new("/vagga/bin/busybox");
tar_cmd.stdin(Stdio::null())
.arg("tar")
.arg("-c");
if let Some(compression_type) = options.compression_type {
tar_cmd.arg(compression_type.get_short_option());
capsule_features.push(compression_type.get_capsule_feature());
}
if let Some(ref f) = options.file {
tar_cmd.arg("-f");
if f.starts_with("/") {
tar_cmd.arg(f);
} else {
tar_cmd.arg(Path::new("/work").join(f));
}
}
tar_cmd
.arg("-C").arg(&root)
.arg(".");
if capsule_features.len() > 0 {
let mut capsule_state = capsule::State::new(&wrapper.settings);
capsule::ensure(&mut capsule_state, &capsule_features)?;
}
if let Some(_) = options.compression_type {
writeln!(&mut stderr(),
"Compressing the image... This may take a few minutes.").ok();
}
info!("Running {}", cmd_show(&tar_cmd));
tar_cmd.status()
.map(convert_status)
.map_err(|e| cmd_err(&tar_cmd, e))
}