forked from brl/citadel-tools
decompress images in parallel by spawning a thread for each one
This commit is contained in:
parent
0b2480f849
commit
55b08fb683
@ -8,11 +8,13 @@ mod disks;
|
|||||||
use std::result;
|
use std::result;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::thread;
|
|
||||||
use std::time;
|
use std::time;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
use std::thread::{self,JoinHandle};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
|
use libcitadel::ResourceImage;
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T,Error>;
|
pub type Result<T> = result::Result<T,Error>;
|
||||||
|
|
||||||
@ -48,14 +50,15 @@ fn live_setup() -> Result<()> {
|
|||||||
if !Path::new("/etc/initrd-release").exists() {
|
if !Path::new("/etc/initrd-release").exists() {
|
||||||
bail!("Not running in initramfs, cannot do live-setup");
|
bail!("Not running in initramfs, cannot do live-setup");
|
||||||
}
|
}
|
||||||
let installer = installer::Installer::new();
|
let installer = installer::Installer::new_livesetup();
|
||||||
installer.live_setup()
|
installer.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_artifacts() -> Result<()> {
|
fn copy_artifacts() -> Result<()> {
|
||||||
|
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
if try_copy_artifacts()? {
|
if try_copy_artifacts()? {
|
||||||
|
decompress_images()?;
|
||||||
return Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
// Try again after waiting for more devices to be discovered
|
// Try again after waiting for more devices to be discovered
|
||||||
@ -131,6 +134,30 @@ fn deploy_syslinux_artifacts() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn decompress_images() -> Result<()> {
|
||||||
|
println!("decompressing images");
|
||||||
|
let mut threads = Vec::new();
|
||||||
|
for entry in fs::read_dir("/run/images")? {
|
||||||
|
let entry = entry?;
|
||||||
|
if entry.path().extension() == Some(OsStr::new("img")) {
|
||||||
|
if let Ok(image) = ResourceImage::from_path(&entry.path()) {
|
||||||
|
threads.push(decompress_one_image(image));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for t in threads {
|
||||||
|
t.join().unwrap()?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn decompress_one_image(image: ResourceImage) -> JoinHandle<Result<()>> {
|
||||||
|
thread::spawn(move ||{
|
||||||
|
image.decompress()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn cli_install() -> Result<()> {
|
fn cli_install() -> Result<()> {
|
||||||
let ok = cli::run_cli_install()?;
|
let ok = cli::run_cli_install()?;
|
||||||
if !ok {
|
if !ok {
|
||||||
|
Loading…
Reference in New Issue
Block a user