feat: add sha256 compression for archives
parent
f5de535313
commit
d36b3bc1b2
|
@ -9,6 +9,7 @@ edition = "2021"
|
|||
axum = "0.6.18"
|
||||
futures = "0.3.28"
|
||||
libarchive = { path = "../libarchive" }
|
||||
sha256 = "1.1.4"
|
||||
tokio = { version = "1.29.1", features = ["full"] }
|
||||
tokio-util = { version = "0.7.8", features = ["io"] }
|
||||
tower = { version = "0.4.13", features = ["make"] }
|
||||
|
|
|
@ -53,7 +53,9 @@ async fn post_package_archive(
|
|||
.await?;
|
||||
}
|
||||
|
||||
let pkg = tokio::task::spawn_blocking(move || package::Package::open(&path)).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR).await?;
|
||||
let pkg = tokio::task::spawn_blocking(move || package::Package::open(&path))
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.await?;
|
||||
|
||||
println!("{:?}", pkg);
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use libarchive::read::{Archive, Builder};
|
||||
use libarchive::{Entry, ReadFilter};
|
||||
use std::fmt;
|
||||
use std::fs;
|
||||
use std::io::{self, BufRead, BufReader, Read};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::fs;
|
||||
|
||||
const IGNORED_FILES: [&str; 5] = [".BUILDINFO", ".INSTALL", ".MTREE", ".PKGINFO", ".CHANGELOG"];
|
||||
|
||||
|
@ -15,8 +15,7 @@ pub struct Package {
|
|||
compression: ReadFilter,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct PkgInfo {
|
||||
name: String,
|
||||
base: String,
|
||||
|
@ -39,6 +38,7 @@ pub struct PkgInfo {
|
|||
optdepends: Vec<String>,
|
||||
makedepends: Vec<String>,
|
||||
checkdepends: Vec<String>,
|
||||
sha256sum: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
|
@ -134,7 +134,10 @@ impl Package {
|
|||
|
||||
let mut ar = builder.open_file(path.as_ref())?;
|
||||
|
||||
let compression = ar.filter(0).ok_or(io::Error::new(io::ErrorKind::Other, "Unknown compression type."))?;
|
||||
let compression = ar.filter(0).ok_or(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"Unknown compression type.",
|
||||
))?;
|
||||
let mut info: Option<PkgInfo> = None;
|
||||
let mut files: Vec<PathBuf> = Vec::new();
|
||||
|
||||
|
@ -154,14 +157,23 @@ impl Package {
|
|||
if let Some(mut info) = info {
|
||||
info.csize = fs::metadata(path.as_ref())?.len();
|
||||
|
||||
Ok(Package{
|
||||
Ok(Package {
|
||||
path: path.as_ref().to_path_buf(),
|
||||
info,
|
||||
compression,
|
||||
files
|
||||
files,
|
||||
})
|
||||
} else {
|
||||
Err(io::Error::new(io::ErrorKind::Other, "No .PKGINFO file found."))
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"No .PKGINFO file found.",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn calculate_checksum(&mut self) -> io::Result<()> {
|
||||
self.info.sha256sum = Some(sha256::try_digest(self.path.as_ref())?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue