update
This commit is contained in:
parent
221b2a82e7
commit
2ed9cd25a3
7 changed files with 126 additions and 7 deletions
47
src/pkg.rs
47
src/pkg.rs
|
@ -37,15 +37,15 @@ impl Repository {
|
|||
|
||||
pub fn get_pkg(&self, arch: &str, pkg_name: &str) -> Option<Package> {
|
||||
let pkg = if pkg_name.ends_with(".pkg.tar.zst") {
|
||||
Package::new(&self.name, arch, pkg_name.trim_end_matches(".pkg.tar.zst"))
|
||||
Package::find(&self.name, arch, pkg_name.trim_end_matches(".pkg.tar.zst"))
|
||||
} else if pkg_name.ends_with(".pkg.tar.zst.sig") {
|
||||
Package::new(
|
||||
Package::find(
|
||||
&self.name,
|
||||
arch,
|
||||
pkg_name.trim_end_matches(".pkg.tar.zst.sig"),
|
||||
)
|
||||
} else {
|
||||
Package::new(&self.name, arch, pkg_name)
|
||||
Package::find(&self.name, arch, pkg_name)
|
||||
};
|
||||
|
||||
if pkg.exists() {
|
||||
|
@ -65,7 +65,16 @@ pub struct Package {
|
|||
}
|
||||
|
||||
impl Package {
|
||||
pub fn new(repo: &str, arch: &str, pkg_name: &str) -> Self {
|
||||
pub fn new(repo: &str, arch: &str, pkg_name: &str, version: &str) -> Self {
|
||||
Package {
|
||||
repo: repo.to_string(),
|
||||
arch: arch.to_string(),
|
||||
name: pkg_name.to_string(),
|
||||
version: Some(version.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find(repo: &str, arch: &str, pkg_name: &str) -> Self {
|
||||
Package {
|
||||
repo: repo.to_string(),
|
||||
arch: arch.to_string(),
|
||||
|
@ -74,6 +83,27 @@ impl Package {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn save(&self, pkg: Vec<u8>, sig: Option<Vec<u8>>) {
|
||||
let pkg_file = self.base_path().join(&self.file_name());
|
||||
let sig_file = self.base_path().join(format!("{}.sig", self.file_name()));
|
||||
|
||||
std::fs::write(&pkg_file, pkg).unwrap();
|
||||
if let Some(sig) = sig {
|
||||
std::fs::write(sig_file, sig).unwrap();
|
||||
}
|
||||
|
||||
let db_file = PathBuf::from("./data")
|
||||
.join(&self.repo)
|
||||
.join(&self.arch)
|
||||
.join(format!("{}.db.tar.gz", self.repo));
|
||||
|
||||
run_command(vec![
|
||||
"repo-add",
|
||||
db_file.to_str().unwrap(),
|
||||
pkg_file.to_str().unwrap(),
|
||||
]);
|
||||
}
|
||||
|
||||
fn base_path(&self) -> PathBuf {
|
||||
Path::new("./data").join(&self.repo).join(&self.arch)
|
||||
}
|
||||
|
@ -152,3 +182,12 @@ impl Package {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_command(cmd: Vec<&str>) {
|
||||
std::process::Command::new(cmd.first().unwrap())
|
||||
.args(cmd.into_iter().skip(1).collect::<Vec<&str>>())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait()
|
||||
.unwrap();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue