Skip to content

Commit

Permalink
Release new version, many codes has been rewrited
Browse files Browse the repository at this point in the history
  • Loading branch information
rikonaka committed Sep 14, 2024
1 parent a4bc73f commit ec727dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ fn install_depends(package_path: &str) -> Result<()> {
pub fn install_deb(aoitfile_name: &str) -> Result<()> {
// aoitfile_name: vim.aoit
// sha256 check
info!("Checking...");
info!("checking...");
let hash_filename = format!("{}.{}", aoitfile_name, DEFAULT_SHA256_SUFFIX);
let hash_str = utils::file_sha256(aoitfile_name)?;
let contents = utils::read_file_bytes(&hash_filename)?;
let contents = String::from_utf8_lossy(&contents).to_string();
if hash_str.trim() != contents.trim() {
error!("Calc hash: {hash_str}, file hash: {contents}");
panic!("Check sha256 failed!");
error!("calc hash: {hash_str}, file hash: {contents}");
panic!("check sha256 failed!");
} else {
info!("Check sha256 success!");
info!("check sha256 success!");
}

// get target dir name
let aoitfile_name_split: Vec<&str> = aoitfile_name.split(".").collect();
let target_dir = if aoitfile_name_split.len() >= 2 {
aoitfile_name_split[0].to_string()
} else {
panic!("Wrong file name, standard files should end with aoit");
panic!("wrong file name, standard files should end with aoit");
};

// decompress 7z package
info!("Decompress aoit...");
info!("decompress aoit...");
// let dest = format!("./{}", target_dir);
utils::create_dir(&target_dir)?;
sevenz_rust::decompress_file(aoitfile_name, &target_dir).expect("complete");
Expand All @@ -59,16 +59,16 @@ pub fn install_deb(aoitfile_name: &str) -> Result<()> {
match serde_config.packages_map.get(&packages_name) {
Some(packages_full_name) => {
let package_path = format!("{}/{}", target_dir, packages_full_name);
info!("Install: {}", packages_full_name);
info!("installing: {}", packages_full_name);
install_depends(&package_path)?;
}
None => warn!("package {packages_name} not found"),
}
}

// delete decompress dir
info!("Removing tmp dir...");
info!("removing tmp dir...");
utils::remove_dir(&target_dir)?;
info!("Done");
info!("done!");
Ok(())
}
18 changes: 9 additions & 9 deletions src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl AptDepends {
}

fn resolve_depends(package_name: &str, packags_vec: &mut Vec<String>) -> Result<Vec<AptDepends>> {
debug!("Resolve package: {package_name}");
debug!("resolve package: {package_name}");
if packags_vec.contains(&package_name.to_string()) {
return Ok(vec![]);
} else {
Expand Down Expand Up @@ -99,24 +99,24 @@ fn download_depends(package_name: &str, target_dir: &str) -> Result<String> {
pub fn pack_deb(package_name: &str) -> Result<()> {
let target_dir = package_name;
match utils::create_dir(&target_dir) {
Ok(_) => info!("Create tmp dir success!"),
Ok(_) => info!("create tmp dir success!"),
Err(e) => {
error!("Create tmp dir failed: {e}!");
error!("create tmp dir failed: {e}!");
return Err(e);
}
}

let (apt_depends, packages_vec) = resolve_depends_root(package_name)?;
if packages_vec.len() == 0 {
error!("The [{}] package does not exist!", package_name);
error!("the [{}] package does not exist!", package_name);
utils::remove_dir(target_dir)?;
return Ok(());
}

let mut packages_map = HashMap::new();
for p in &packages_vec {
let package_full_name = download_depends(p, &target_dir)?;
info!("Downloading package: {p}[{package_full_name}]");
info!("downloading package: {p}[{package_full_name}]");
packages_map.insert(p.to_string(), package_full_name);
}

Expand All @@ -130,20 +130,20 @@ pub fn pack_deb(package_name: &str) -> Result<()> {
utils::move_file_to_dir(&target_dir, DEFAULT_CONFIG_NAME)?;

// compress
info!("Saving...");
info!("saving...");
let dest = format!("{}.{}", package_name, DEFAULT_PACKAGE_SUFFIX);
sevenz_rust::compress_to_path(target_dir, &dest)?;

// sha256 hash
info!("Hashing...");
info!("hashing...");
let hash_str = utils::file_sha256(&dest)?;
let hash_filename = format!("{}.{}", dest, DEFAULT_SHA256_SUFFIX);
let _ = utils::write_to_file(&hash_filename, &hash_str);

// clean dir
info!("Removing tmp dir...");
info!("removing tmp dir...");
utils::remove_dir(target_dir)?;
info!("Done");
info!("done!");

Ok(())
}
Expand Down

0 comments on commit ec727dc

Please sign in to comment.