Skip to content

Commit

Permalink
Merge pull request #109 from kpcyrd/sync-method
Browse files Browse the repository at this point in the history
Allow picking a different sync-method than distro used
  • Loading branch information
kpcyrd authored Dec 8, 2021
2 parents a3436d2 + 7eb8ae8 commit 9b58682
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions tools/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions tools/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
11 changes: 9 additions & 2 deletions tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tools/src/schedule/archlinux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions tools/src/schedule/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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();
Expand All @@ -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,
Expand Down Expand Up @@ -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());
}
}
}
Expand Down
1 change: 1 addition & 0 deletions tools/src/schedule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 9b58682

Please sign in to comment.