Skip to content

Commit 47c3e7d

Browse files
authored
Merge pull request #200 from kpcyrd/misc-fixes
Fix minor bugs and clippy warnings
2 parents a31cae9 + 1ec0a34 commit 47c3e7d

File tree

7 files changed

+74
-82
lines changed

7 files changed

+74
-82
lines changed

contrib/systemd/[email protected]

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Description=rebuilderd-worker: rebuild packages
44
[Service]
55
Restart=always
66
RestartSec=0
7+
Environment="REBUILDERD_WORKER_CONFIG=/etc/rebuilderd-worker.conf"
78
ExecStart=/usr/bin/rebuilderd-worker -n %i connect
89
CPUSchedulingPolicy=idle
910
IOSchedulingClass=3

daemon/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub fn setup_auth_cookie() -> Result<String> {
9191
.mode(0o640)
9292
.write(true)
9393
.create(true)
94+
.truncate(true)
9495
.open(cookie_path)
9596
.context("Failed to open auth cookie file")?;
9697
file.write_all(format!("{}\n", cookie).as_bytes())?;

tools/src/args.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::{ArgAction, CommandFactory, Parser};
22
use clap_complete::Shell;
33
use glob::Pattern;
4-
use rebuilderd_common::api::v1::BuildStatus;
4+
use rebuilderd_common::api::v1::ArtifactStatus;
55
use rebuilderd_common::errors::*;
66
use std::io;
77
use std::path::PathBuf;
@@ -67,10 +67,7 @@ pub struct PkgsSyncProfile {
6767
}
6868

6969
#[derive(Debug, Parser)]
70-
pub struct PkgsSyncStdin {
71-
pub distro: String,
72-
pub suite: String,
73-
}
70+
pub struct PkgsSyncStdin {}
7471

7572
#[derive(Debug, Parser)]
7673
pub struct PkgsSync {
@@ -110,7 +107,7 @@ pub struct PkgsFilter {
110107
pub name: Option<String>,
111108
/// Filter packages matching this status
112109
#[arg(long)]
113-
pub status: Option<BuildStatus>,
110+
pub status: Option<ArtifactStatus>,
114111
/// Filter packages matching this distro
115112
#[arg(long)]
116113
pub distro: Option<String>,

tools/src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub async fn sync(client: &Client, sync: PkgsSync) -> Result<()> {
6767
print_json(&reports)?;
6868
} else {
6969
for report in reports {
70-
submit_package_report(&client, &report).await?;
70+
submit_package_report(client, &report).await?;
7171
}
7272
}
7373

@@ -201,7 +201,7 @@ async fn main() -> Result<()> {
201201
)
202202
.await?;
203203
}
204-
SubCommand::Pkgs(Pkgs::SyncStdin(sync)) => {
204+
SubCommand::Pkgs(Pkgs::SyncStdin(_sync)) => {
205205
let mut stdin = tokio::io::stdin();
206206
let mut buf = Vec::new();
207207
stdin.read_to_end(&mut buf).await?;
@@ -233,7 +233,7 @@ async fn main() -> Result<()> {
233233
};
234234

235235
loop {
236-
let results = client
236+
let mut results = client
237237
.get_binary_packages(Some(&page), Some(&origin_filter), Some(&identity_filter))
238238
.await?;
239239

@@ -243,6 +243,15 @@ async fn main() -> Result<()> {
243243
break;
244244
}
245245

246+
// Filter the list by status so it's applied to the json output as well
247+
if let Some(status) = &ls.filter.status {
248+
results.records.retain(|pkg| {
249+
// If our filter is "UNKWN", match packages with status == null
250+
pkg.status == ls.filter.status
251+
|| (*status == ArtifactStatus::Unknown && pkg.status.is_none())
252+
});
253+
}
254+
246255
if ls.json {
247256
print_json(&results.records)?;
248257
} else {

tools/src/schedule/debian.rs

Lines changed: 47 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -298,19 +298,23 @@ impl SyncState {
298298
fn get_mut_group(
299299
&mut self,
300300
src: &DebianSourcePkg,
301-
release: &String,
302-
component: &String,
303-
architecture: &String,
301+
release: &str,
302+
component: &str,
303+
architecture: &str,
304304
) -> &mut SourcePackageReport {
305-
let key = (release.clone(), component.clone(), architecture.clone());
305+
let key = (
306+
release.to_string(),
307+
component.to_string(),
308+
architecture.to_string(),
309+
);
306310
let report = self
307311
.reports
308312
.entry(key.clone())
309313
.or_insert_with(|| PackageReport {
310314
distribution: "debian".to_string(),
311-
release: Some(release.clone()),
312-
component: Some(component.clone()),
313-
architecture: architecture.clone(),
315+
release: Some(release.to_string()),
316+
component: Some(component.to_string()),
317+
architecture: architecture.to_string(),
314318
packages: Vec::new(),
315319
});
316320

@@ -339,8 +343,8 @@ impl SyncState {
339343
src: &DebianSourcePkg,
340344
bin: DebianBinPkg,
341345
source: &str,
342-
release: &String,
343-
component: &String,
346+
release: &str,
347+
component: &str,
344348
) {
345349
let group = self.get_mut_group(src, release, component, &bin.architecture);
346350
let url = format!("{}/{}", source, bin.filename);
@@ -360,8 +364,8 @@ impl SyncState {
360364
&mut self,
361365
pkg: DebianBinPkg,
362366
sources: &SourcePkgBucket,
363-
release: &String,
364-
component: &String,
367+
release: &str,
368+
component: &str,
365369
sync: &PkgsSync,
366370
) -> Result<()> {
367371
// Debian combines arch:all and arch:any packages.
@@ -392,8 +396,8 @@ impl SyncState {
392396
&mut self,
393397
bytes: &[u8],
394398
sources: &SourcePkgBucket,
395-
release: &String,
396-
component: &String,
399+
release: &str,
400+
component: &str,
397401
sync: &PkgsSync,
398402
) -> Result<()> {
399403
for pkg in extract_pkgs_compressed::<DebianBinPkg>(bytes)? {
@@ -406,8 +410,8 @@ impl SyncState {
406410
&mut self,
407411
bytes: &[u8],
408412
sources: &SourcePkgBucket,
409-
release: &String,
410-
component: &String,
413+
release: &str,
414+
component: &str,
411415
sync: &PkgsSync,
412416
) -> Result<()> {
413417
for pkg in extract_pkgs_uncompressed::<DebianBinPkg, _>(bytes)? {
@@ -689,13 +693,7 @@ Section: misc
689693
uploaders: vec![],
690694
};
691695
let mut state = SyncState::new();
692-
state.push(
693-
&src,
694-
bin,
695-
"https://deb.debian.org/debian",
696-
&"sid".to_string(),
697-
&"main".to_string(),
698-
);
696+
state.push(&src, bin, "https://deb.debian.org/debian", "sid", "main");
699697

700698
let mut reports = HashMap::new();
701699
reports.insert(("sid".to_string(), "main".to_string(), "all".to_string()), PackageReport {
@@ -804,8 +802,8 @@ Section: misc
804802
&src_pkgs[0],
805803
bin,
806804
"https://deb.debian.org/debian",
807-
&"sid".to_string(),
808-
&"main".to_string(),
805+
"sid",
806+
"main",
809807
);
810808
}
811809

@@ -1136,13 +1134,7 @@ Section: mail
11361134
let mut state = SyncState::new();
11371135
for bin in bin_pkgs {
11381136
let src = sources.get(&bin).unwrap();
1139-
state.push(
1140-
&src,
1141-
bin,
1142-
"https://deb.debian.org/debian",
1143-
&"sid".to_string(),
1144-
&"main".to_string(),
1145-
);
1137+
state.push(&src, bin, "https://deb.debian.org/debian", "sid", "main");
11461138
}
11471139

11481140
let mut reports = HashMap::new();
@@ -1495,22 +1487,10 @@ SHA256: cc2081a6b2f6dcb82039b5097405b5836017a7bfc54a78eba36b656549e17c92
14951487

14961488
// add the package list twice, to simulate importing sid and testing
14971489
state
1498-
.import_uncompressed_binary_package_file(
1499-
&bytes[..],
1500-
&sources,
1501-
&"sid".to_string(),
1502-
&"main".to_string(),
1503-
&sync,
1504-
)
1490+
.import_uncompressed_binary_package_file(&bytes[..], &sources, "sid", "main", &sync)
15051491
.unwrap();
15061492
state
1507-
.import_uncompressed_binary_package_file(
1508-
&bytes[..],
1509-
&sources,
1510-
&"testing".to_string(),
1511-
&"main".to_string(),
1512-
&sync,
1513-
)
1493+
.import_uncompressed_binary_package_file(&bytes[..], &sources, "testing", "main", &sync)
15141494
.unwrap();
15151495

15161496
let mut reports = HashMap::new();
@@ -1578,9 +1558,9 @@ SHA256: cc2081a6b2f6dcb82039b5097405b5836017a7bfc54a78eba36b656549e17c92
15781558
sync_method: None,
15791559
};
15801560

1581-
for (source, binary) in [
1582-
// sid
1583-
(&b"Package: novnc
1561+
// sid
1562+
let (source, binary) = (
1563+
&b"Package: novnc
15841564
Binary: novnc, python3-novnc
15851565
Version: 1:1.6.0-1
15861566
Maintainer: Debian OpenStack <[email protected]>
@@ -1670,15 +1650,18 @@ Size: 12664
16701650
MD5sum: e088e49616de39f4cfa162959335340e
16711651
SHA256: 89c378d37058ea2a6c5d4bb2c1d47c4810f7504bde9e4d8142ac9781ce9df002
16721652
1673-
"[..]), ] {
1674-
let mut sources = SourcePkgBucket::new();
1675-
sources.import_uncompressed_source_package_file(&source[..]).unwrap();
1676-
state.import_uncompressed_binary_package_file(&binary[..], &sources, &"sid".to_string(), &"main".to_string(), &sync).unwrap();
1677-
}
1653+
"[..]);
1654+
let mut sources = SourcePkgBucket::new();
1655+
sources
1656+
.import_uncompressed_source_package_file(source)
1657+
.unwrap();
1658+
state
1659+
.import_uncompressed_binary_package_file(binary, &sources, "sid", "main", &sync)
1660+
.unwrap();
16781661

1679-
for (source, binary) in [
1680-
// testing
1681-
(b"Package: novnc
1662+
// testing
1663+
let (source, binary) = (
1664+
b"Package: novnc
16821665
Binary: novnc, python3-novnc
16831666
Version: 1:1.6.0-1
16841667
Maintainer: Debian OpenStack <[email protected]>
@@ -1741,12 +1724,14 @@ Size: 12664
17411724
MD5sum: e088e49616de39f4cfa162959335340e
17421725
SHA256: 89c378d37058ea2a6c5d4bb2c1d47c4810f7504bde9e4d8142ac9781ce9df002
17431726
1744-
")
1745-
] {
1746-
let mut sources = SourcePkgBucket::new();
1747-
sources.import_uncompressed_source_package_file(&source[..]).unwrap();
1748-
state.import_uncompressed_binary_package_file(binary, &sources, &"testing".to_string(), &"main".to_string(), &sync).unwrap();
1749-
}
1727+
");
1728+
let mut sources = SourcePkgBucket::new();
1729+
sources
1730+
.import_uncompressed_source_package_file(&source[..])
1731+
.unwrap();
1732+
state
1733+
.import_uncompressed_binary_package_file(binary, &sources, "testing", "main", &sync)
1734+
.unwrap();
17501735

17511736
let mut reports = HashMap::new();
17521737

tools/src/schedule/tails.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub async fn sync(http: &http::Client, sync: &PkgsSync) -> Result<Vec<PackageRep
1818
url.path_segments_mut()
1919
.map_err(|_| anyhow!("cannot be base"))?
2020
.pop_if_empty()
21-
.push(&release);
21+
.push(release);
2222

2323
info!("Downloading directory list from {}", url);
2424
let directory_list = http
@@ -40,7 +40,7 @@ pub async fn sync(http: &http::Client, sync: &PkgsSync) -> Result<Vec<PackageRep
4040
info!("Detecting tails versions");
4141

4242
let prefix = format!("tails-{architecture}");
43-
let re = Regex::new(&*(prefix + r"-([0-9a-z~\.]+)/")).unwrap();
43+
let re = Regex::new(&(prefix + r"-([0-9a-z~\.]+)/")).unwrap();
4444
let cap = re
4545
.captures_iter(&directory_list)
4646
.next()

worker/src/main.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ async fn main() -> Result<()> {
202202
}
203203

204204
if let Some(name) = &args.name {
205-
setup::run(&name).context("Failed to setup worker")?;
205+
setup::run(name).context("Failed to setup worker")?;
206206
}
207207
let profile = auth::load()?;
208208

@@ -226,13 +226,12 @@ async fn main() -> Result<()> {
226226
cookie,
227227
)?;
228228

229-
if config.signup_secret.is_some() {
230-
client
231-
.register_worker(RegisterWorkerRequest {
232-
name: args.name.unwrap_or("worker".to_string()),
233-
})
234-
.await?;
235-
}
229+
client
230+
.register_worker(RegisterWorkerRequest {
231+
name: args.name.unwrap_or("worker".to_string()),
232+
})
233+
.await
234+
.context("Failed to register worker with rebuilderd daemon")?;
236235

237236
run_worker_loop(&client, &profile.privkey, &config).await?;
238237
}
@@ -283,7 +282,7 @@ async fn main() -> Result<()> {
283282
} else {
284283
error!("Package failed to verify");
285284
if let Some(diffoscope) = res.diffoscope {
286-
io::stdout().write_all(&*diffoscope).ok();
285+
io::stdout().write_all(&diffoscope).ok();
287286
}
288287
}
289288
}

0 commit comments

Comments
 (0)