feat: add sha256 compression for archives
parent
f5de535313
commit
d36b3bc1b2
|
@ -9,6 +9,7 @@ edition = "2021"
|
||||||
axum = "0.6.18"
|
axum = "0.6.18"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
libarchive = { path = "../libarchive" }
|
libarchive = { path = "../libarchive" }
|
||||||
|
sha256 = "1.1.4"
|
||||||
tokio = { version = "1.29.1", features = ["full"] }
|
tokio = { version = "1.29.1", features = ["full"] }
|
||||||
tokio-util = { version = "0.7.8", features = ["io"] }
|
tokio-util = { version = "0.7.8", features = ["io"] }
|
||||||
tower = { version = "0.4.13", features = ["make"] }
|
tower = { version = "0.4.13", features = ["make"] }
|
||||||
|
|
|
@ -53,7 +53,9 @@ async fn post_package_archive(
|
||||||
.await?;
|
.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);
|
println!("{:?}", pkg);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use libarchive::read::{Archive, Builder};
|
use libarchive::read::{Archive, Builder};
|
||||||
use libarchive::{Entry, ReadFilter};
|
use libarchive::{Entry, ReadFilter};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::fs;
|
||||||
use std::io::{self, BufRead, BufReader, Read};
|
use std::io::{self, BufRead, BufReader, Read};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
const IGNORED_FILES: [&str; 5] = [".BUILDINFO", ".INSTALL", ".MTREE", ".PKGINFO", ".CHANGELOG"];
|
const IGNORED_FILES: [&str; 5] = [".BUILDINFO", ".INSTALL", ".MTREE", ".PKGINFO", ".CHANGELOG"];
|
||||||
|
|
||||||
|
@ -15,8 +15,7 @@ pub struct Package {
|
||||||
compression: ReadFilter,
|
compression: ReadFilter,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
#[derive(Default)]
|
|
||||||
pub struct PkgInfo {
|
pub struct PkgInfo {
|
||||||
name: String,
|
name: String,
|
||||||
base: String,
|
base: String,
|
||||||
|
@ -39,6 +38,7 @@ pub struct PkgInfo {
|
||||||
optdepends: Vec<String>,
|
optdepends: Vec<String>,
|
||||||
makedepends: Vec<String>,
|
makedepends: Vec<String>,
|
||||||
checkdepends: Vec<String>,
|
checkdepends: Vec<String>,
|
||||||
|
sha256sum: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
@ -134,7 +134,10 @@ impl Package {
|
||||||
|
|
||||||
let mut ar = builder.open_file(path.as_ref())?;
|
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 info: Option<PkgInfo> = None;
|
||||||
let mut files: Vec<PathBuf> = Vec::new();
|
let mut files: Vec<PathBuf> = Vec::new();
|
||||||
|
|
||||||
|
@ -158,10 +161,19 @@ impl Package {
|
||||||
path: path.as_ref().to_path_buf(),
|
path: path.as_ref().to_path_buf(),
|
||||||
info,
|
info,
|
||||||
compression,
|
compression,
|
||||||
files
|
files,
|
||||||
})
|
})
|
||||||
} else {
|
} 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