feat(server): support uploading packages of arch "any"
parent
c2f35aebac
commit
d446e39253
|
@ -68,19 +68,24 @@ impl FileWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(&mut self) {
|
pub fn close(&mut self) -> crate::Result<()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::archive_write_close(self.handle_mut());
|
match ffi::archive_write_close(self.handle_mut()) {
|
||||||
}
|
ffi::ARCHIVE_OK => {
|
||||||
|
self.closed = true;
|
||||||
|
|
||||||
self.closed = true;
|
Ok(())
|
||||||
|
}
|
||||||
|
_ => Err(ArchiveError::from(self as &dyn Handle)),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for FileWriter {
|
impl Drop for FileWriter {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if !self.closed {
|
if !self.closed {
|
||||||
self.close();
|
let _ = self.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -32,7 +32,7 @@ async fn main() {
|
||||||
repo_dir: "./data/repos".into(),
|
repo_dir: "./data/repos".into(),
|
||||||
pkg_dir: "./data/pkgs".into(),
|
pkg_dir: "./data/pkgs".into(),
|
||||||
};
|
};
|
||||||
let repo_manager = RepoGroupManager::new("./data/repos", "./data/pkgs");
|
let repo_manager = RepoGroupManager::new("./data/repos", "./data/pkgs", "x86_64");
|
||||||
|
|
||||||
let global = Global {
|
let global = Global {
|
||||||
config,
|
config,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use super::package::Package;
|
use super::package::Package;
|
||||||
use libarchive::write::{Builder, WriteEntry};
|
use libarchive::write::{Builder, WriteEntry};
|
||||||
use libarchive::{Entry, WriteFilter, WriteFormat};
|
use libarchive::{Entry, WriteFilter, WriteFormat};
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
@ -9,13 +10,19 @@ use std::path::{Path, PathBuf};
|
||||||
pub struct RepoGroupManager {
|
pub struct RepoGroupManager {
|
||||||
repo_dir: PathBuf,
|
repo_dir: PathBuf,
|
||||||
pkg_dir: PathBuf,
|
pkg_dir: PathBuf,
|
||||||
|
default_arch: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RepoGroupManager {
|
impl RepoGroupManager {
|
||||||
pub fn new<P1: AsRef<Path>, P2: AsRef<Path>>(repo_dir: P1, pkg_dir: P2) -> Self {
|
pub fn new<P1: AsRef<Path>, P2: AsRef<Path>>(
|
||||||
|
repo_dir: P1,
|
||||||
|
pkg_dir: P2,
|
||||||
|
default_arch: &str,
|
||||||
|
) -> Self {
|
||||||
RepoGroupManager {
|
RepoGroupManager {
|
||||||
repo_dir: repo_dir.as_ref().to_path_buf(),
|
repo_dir: repo_dir.as_ref().to_path_buf(),
|
||||||
pkg_dir: pkg_dir.as_ref().to_path_buf(),
|
pkg_dir: pkg_dir.as_ref().to_path_buf(),
|
||||||
|
default_arch: String::from(default_arch),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +68,7 @@ impl RepoGroupManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
ar_db.close().and(ar_files.close()).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_pkg_from_arch_repo(
|
pub fn remove_pkg_from_arch_repo(
|
||||||
|
@ -139,14 +146,31 @@ impl RepoGroupManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a package to the given repo, returning to what architectures the package was added.
|
/// Add a package to the given repo, returning to what architectures the package was added.
|
||||||
pub fn add_pkg_in_repo(&mut self, repo: &str, pkg: &Package) -> io::Result<Vec<String>> {
|
pub fn add_pkg_in_repo(&mut self, repo: &str, pkg: &Package) -> io::Result<HashSet<String>> {
|
||||||
|
let mut arch_repos: HashSet<String> = HashSet::new();
|
||||||
|
|
||||||
if pkg.info.arch != "any" {
|
if pkg.info.arch != "any" {
|
||||||
self.add_pkg_in_arch_repo(repo, &pkg.info.arch, pkg)?;
|
self.add_pkg_in_arch_repo(repo, &pkg.info.arch, pkg)?;
|
||||||
|
arch_repos.insert(pkg.info.arch.clone());
|
||||||
|
}
|
||||||
|
// Packages of arch "any" are added to every existing arch
|
||||||
|
else {
|
||||||
|
arch_repos.insert(self.default_arch.clone());
|
||||||
|
|
||||||
return Ok(vec![String::from(&pkg.info.arch)]);
|
let repo_dir = self.repo_dir.join(repo);
|
||||||
|
|
||||||
|
if repo_dir.exists() {
|
||||||
|
for entry in repo_dir.read_dir()? {
|
||||||
|
arch_repos.insert(entry?.file_name().to_string_lossy().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for arch in arch_repos.iter() {
|
||||||
|
self.add_pkg_in_arch_repo(repo, &arch, pkg)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
todo!()
|
Ok(arch_repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_pkg_in_arch_repo(
|
pub fn add_pkg_in_arch_repo(
|
||||||
|
|
Loading…
Reference in New Issue