From 7eb8ae8a9dc3060a0b1cadd14fefaea2fd687ed2 Mon Sep 17 00:00:00 2001 From: kpcyrd <git@rxv.cc> Date: Wed, 8 Dec 2021 16:56:30 +0100 Subject: [PATCH] Allow picking a different sync-method than distro used --- tools/src/args.rs | 2 ++ tools/src/config.rs | 1 + tools/src/main.rs | 11 +++++++++-- tools/src/schedule/archlinux.rs | 2 +- tools/src/schedule/debian.rs | 14 +++++++------- tools/src/schedule/mod.rs | 1 + 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tools/src/args.rs b/tools/src/args.rs index 221e0b6..3f18b6d 100644 --- a/tools/src/args.rs +++ b/tools/src/args.rs @@ -91,6 +91,8 @@ pub struct PkgsSync { pub pkgs: Vec<Pattern>, #[structopt(long="exclude")] pub excludes: Vec<Pattern>, + #[structopt(long)] + pub sync_method: Option<String>, } #[derive(Debug, StructOpt)] diff --git a/tools/src/config.rs b/tools/src/config.rs index 4f70d1b..1be5fa1 100644 --- a/tools/src/config.rs +++ b/tools/src/config.rs @@ -23,6 +23,7 @@ impl SyncConfigFile { #[derive(Debug, Deserialize)] pub struct SyncProfile { pub distro: String, + pub sync_method: Option<String>, pub suite: String, #[serde(default)] pub releases: Vec<String>, diff --git a/tools/src/main.rs b/tools/src/main.rs index 797d260..c195c96 100644 --- a/tools/src/main.rs +++ b/tools/src/main.rs @@ -36,11 +36,17 @@ fn print_json<S: Serialize>(x: &S) -> Result<()> { } pub async fn sync(client: &Client, sync: PkgsSync) -> Result<()> { - let mut pkgs = match sync.distro.as_str() { + let method = if let Some(method) = &sync.sync_method { + method.as_str() + } else { + sync.distro.as_str() + }; + + let mut pkgs = match method { "archlinux" => schedule::archlinux::sync(&sync).await?, "debian" => schedule::debian::sync(&sync).await?, "tails" => schedule::tails::sync(&sync).await?, - unknown => bail!("No integrated sync for {:?}, use sync-stdin instead", unknown), + unknown => bail!("No integrated sync for {:?}, use --sync-method or `pkgs sync-stdin` instead", unknown), }; pkgs.sort_by(|a, b| a.name.cmp(&b.name)); @@ -130,6 +136,7 @@ async fn main() -> Result<()> { sync(client.with_auth_cookie()?, PkgsSync { distro: profile.distro, + sync_method: profile.sync_method, suite: profile.suite, releases: profile.releases, architectures: profile.architectures, diff --git a/tools/src/schedule/archlinux.rs b/tools/src/schedule/archlinux.rs index d0d009d..17cb69f 100644 --- a/tools/src/schedule/archlinux.rs +++ b/tools/src/schedule/archlinux.rs @@ -161,7 +161,7 @@ pub async fn sync(sync: &PkgsSync) -> Result<Vec<PkgGroup>> { let mut group = PkgGroup::new( pkg.base.clone(), pkg.version, - "archlinux".to_string(), + sync.distro.to_string(), sync.suite.to_string(), pkg.architecture, None, diff --git a/tools/src/schedule/debian.rs b/tools/src/schedule/debian.rs index 4f3c572..d75bcd6 100644 --- a/tools/src/schedule/debian.rs +++ b/tools/src/schedule/debian.rs @@ -251,13 +251,13 @@ impl SyncState { SyncState::default() } - fn ensure_group_exists(&mut self, src: &DebianSourcePkg, suite: String, arch: &str) { + fn ensure_group_exists(&mut self, src: &DebianSourcePkg, distro: String, suite: String, arch: &str) { // TODO: creating a new group isn't always needed let buildinfo_url = src.buildinfo_url(arch); let new_group = PkgGroup::new( src.base.clone(), src.version.clone(), - "debian".to_string(), + distro, suite, arch.to_string(), Some(buildinfo_url), @@ -276,8 +276,8 @@ impl SyncState { } } - fn get_mut_group(&mut self, src: &DebianSourcePkg, suite: String, arch: &str) -> &mut PkgGroup { - self.ensure_group_exists(src, suite, arch); + fn get_mut_group(&mut self, src: &DebianSourcePkg, distro: String, suite: String, arch: &str) -> &mut PkgGroup { + self.ensure_group_exists(src, distro, suite, arch); // ensure_group_exists ensures the group exists let list = self.groups.get_mut(&src.base).unwrap(); @@ -292,8 +292,8 @@ impl SyncState { unreachable!() } - pub fn push(&mut self, src: &DebianSourcePkg, bin: DebianBinPkg, source: &str, suite: String) { - let group = self.get_mut_group(src, suite, &bin.architecture); + pub fn push(&mut self, src: &DebianSourcePkg, bin: DebianBinPkg, source: &str, distro: String, suite: String) { + let group = self.get_mut_group(src, distro, suite, &bin.architecture); let url = format!("{}/{}/{}_{}_{}.deb", source, src.directory, @@ -359,7 +359,7 @@ pub async fn sync(sync: &PkgsSync) -> Result<Vec<PkgGroup>> { let src = sources.get(&pkg)?; debug!("Matched binary package to source package: {:?} {:?}", src.base, src.version); - out.push(src, pkg, &sync.source, sync.suite.clone()); + out.push(src, pkg, &sync.source, sync.distro.clone(), sync.suite.clone()); } } } diff --git a/tools/src/schedule/mod.rs b/tools/src/schedule/mod.rs index 50a9bf5..974d4dd 100644 --- a/tools/src/schedule/mod.rs +++ b/tools/src/schedule/mod.rs @@ -68,6 +68,7 @@ mod tests { fn gen_filter(f: Filter) -> PkgsSync { PkgsSync { distro: "archlinux".to_string(), + sync_method: None, suite: "community".to_string(), architectures: vec!["x86_64".to_string()], source: "https://ftp.halifax.rwth-aachen.de/archlinux/$repo/os/$arch".to_string(), -- GitLab