25 lines
824 B
Rust
25 lines
824 B
Rust
use crate::zdiff::Zdiff;
|
|
use crate::zpatch;
|
|
use std::fs;
|
|
use std::io::Write;
|
|
use std::path::Path;
|
|
|
|
pub async fn create_tmp_dir(dir_name: String) -> Result<String, std::io::Error> {
|
|
let name = format!("{}.tmp", dir_name);
|
|
fs::remove_dir_all(name.clone()).map_err(|_| std::io::ErrorKind::NotFound)?;
|
|
fs::DirBuilder::new().create(name.clone())?;
|
|
Ok(name)
|
|
}
|
|
|
|
pub async fn extract_files(zdiff: &Zdiff, filename: &String) -> Result<String, std::io::Error> {
|
|
let tmp_dir_name = create_tmp_dir(filename.to_string()).await?;
|
|
let path = Path::new(&tmp_dir_name);
|
|
fs::remove_dir_all(path)?;
|
|
for (f, c) in zdiff.content.iter() {
|
|
let filepath = path.join(f);
|
|
fs::create_dir_all(filepath.parent().unwrap())?;
|
|
fs::File::create(&filepath)?.write_all(c)?;
|
|
}
|
|
Ok(tmp_dir_name)
|
|
}
|