Skip to content

Commit a7bea19

Browse files
committed
clippy (client)
1 parent e80131c commit a7bea19

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

client/src/main.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ fn default_blacklist() -> Vec<Str> {
113113
"rocblas",
114114
];
115115

116-
let mut v: Vec<_> = bad_compress
117-
.into_iter()
118-
.chain(too_big.into_iter())
119-
.map(Str::from)
120-
.collect();
116+
let mut v: Vec<_> = bad_compress.into_iter().chain(too_big).map(Str::from).collect();
121117
v.sort();
122118
v
123119
}
@@ -298,17 +294,18 @@ async fn do_upgrade(
298294

299295
let localset = tokio::task::LocalSet::new();
300296
let mut set = JoinSet::new();
301-
for (url, newpkg, oldpkg, oldfile, dec_size) in upgrade_candidates {
297+
for (url, delta, oldfile, dec_size) in upgrade_candidates {
298+
let (oldpkg, newpkg) = delta.get_both();
302299
let get_delta_f = get_delta(
303300
global.clone(),
304301
newpkg.clone(),
305302
oldpkg.clone(),
306303
oldfile,
307-
dec_size.clone(),
304+
dec_size,
308305
delta_cache.clone(),
309306
server.clone(),
310307
);
311-
let get_sig_f = get_signature(url.into(), global.client.clone(), delta_cache.clone(), newpkg.clone());
308+
let get_sig_f = get_signature(url, global.client.clone(), delta_cache.clone(), newpkg.clone());
312309

313310
set.spawn_local_on(
314311
async move {
@@ -331,7 +328,7 @@ async fn do_upgrade(
331328
let boring_dl = util::do_boring_download(global.clone(), url.clone(), delta_cache.clone());
332329
let name = url.path_segments().and_then(Iterator::last).context("malformed url")?;
333330
let pkg = Package::try_from(name).unwrap();
334-
let get_sig_f = get_signature(url.as_str().into(), global.client.clone(), delta_cache.clone(), pkg);
331+
let get_sig_f = get_signature(url, global.client.clone(), delta_cache.clone(), pkg);
335332
dlset.spawn_local_on(
336333
async move {
337334
let (f, s) = tokio::join!(boring_dl, get_sig_f);
@@ -368,7 +365,9 @@ async fn do_upgrade(
368365
deltasize += d;
369366
newsize += n;
370367
if let Some(c) = c {
371-
comptime.as_mut().map(|sum: &mut Duration| *sum += c);
368+
if let Some(comptime) = &mut comptime {
369+
*comptime += c
370+
}
372371
}
373372
}
374373
}
@@ -495,7 +494,7 @@ async fn get_delta(
495494
Ok((deltasize, newsize, comptime))
496495
}
497496

498-
async fn get_signature(url: Str, client: Client, delta_cache: PathBuf, newpkg: Package) -> Result<(), anyhow::Error> {
497+
async fn get_signature(url: Url, client: Client, delta_cache: PathBuf, newpkg: Package) -> Result<(), anyhow::Error> {
499498
let mut sigfile = delta_cache.clone();
500499
sigfile.push(format!("{newpkg}.sig"));
501500
let mut sigfile = match tokio::fs::OpenOptions::new()
@@ -519,11 +518,11 @@ async fn get_signature(url: Str, client: Client, delta_cache: PathBuf, newpkg: P
519518
}
520519

521520
trait ResultSwap<T, E> {
522-
fn swap(self: Self) -> Result<E, T>;
521+
fn swap(self) -> Result<E, T>;
523522
}
524523

525524
impl<T, E> ResultSwap<T, E> for Result<T, E> {
526-
fn swap(self: Self) -> Result<E, T> {
525+
fn swap(self) -> Result<E, T> {
527526
match self {
528527
Ok(t) => Err(t),
529528
Err(e) => Ok(e),
@@ -548,7 +547,12 @@ fn gen_delta(orig: &Path, new: &Path, patch: &Path) -> Result<(), std::io::Error
548547
let newb_len = newb.len();
549548
let mut newb = Cursor::new(newb);
550549

551-
let patch = OpenOptions::new().write(true).create(true).open(patch).unwrap();
550+
let patch = OpenOptions::new()
551+
.write(true)
552+
.create(true)
553+
.truncate(true)
554+
.open(patch)
555+
.unwrap();
552556
let mut patch = zstd::Encoder::new(patch, 22)?;
553557

554558
let before = memory_stats::memory_stats().unwrap().physical_mem;
@@ -641,7 +645,7 @@ fn apply_patch(orig: &[u8], patch: &Path, new: &Path, pb: ProgressBar) -> anyhow
641645

642646
// gotta drain stdout into file while at the same time writing into stdin
643647
// otherwise the internal buffer of stdin/out is full and it deadlocks
644-
let mut new_f = OpenOptions::new().write(true).create(true).open(new)?;
648+
let mut new_f = OpenOptions::new().write(true).create(true).truncate(false).open(new)?;
645649
let handle = std::thread::spawn(move || -> std::io::Result<()> {
646650
std::io::copy(&mut stdout, &mut new_f)?;
647651
Ok(())

client/src/util.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{collections::HashMap, io::Read, path::PathBuf};
22

33
use anyhow::{Context, bail};
44
use bytesize::ByteSize;
5-
use common::Package;
5+
use common::{Delta, Package};
66
use http::StatusCode;
77
use indicatif::{ProgressBar, ProgressStyle};
88
use itertools::Itertools;
@@ -63,11 +63,13 @@ pub(crate) async fn do_boring_download(
6363
Ok(size)
6464
}
6565

66+
type DeltaUpgradeCandidate = (Url, Delta, Mmap, u64);
67+
6668
pub(crate) fn find_deltaupgrade_candidates(
6769
_global: &crate::GlobalState,
6870
blacklist: &[Str],
6971
_fuz: bool,
70-
) -> Result<(Vec<(String, Package, Package, Mmap, u64)>, Vec<Url>), anyhow::Error> {
72+
) -> Result<(Vec<DeltaUpgradeCandidate>, Vec<Url>), anyhow::Error> {
7173
let upgrades = libalpm_rs::upgrade_urls(&["core", "extra", "multilib"]);
7274

7375
let mut direct_downloads = Vec::new();
@@ -81,7 +83,7 @@ pub(crate) fn find_deltaupgrade_candidates(
8183
}
8284
let i = old.i.borrow();
8385
let old_name = old.name.r(&i);
84-
if (&blacklist).into_iter().any(|e| **e == *old_name) {
86+
if blacklist.iter().any(|e| **e == *old_name) {
8587
info!("{old_name} is blacklisted, skipping");
8688
continue;
8789
}
@@ -116,20 +118,20 @@ pub(crate) fn find_deltaupgrade_candidates(
116118
let new_filename = new.filename.unwrap().r(&i);
117119
let newpkg = Package::try_from(new_filename)?;
118120

119-
deltas.push((url, newpkg, oldpkg, oldfile, (dec_size as u64)));
121+
deltas.push((Url::parse(&url)?, Delta::try_from((oldpkg, newpkg))?, oldfile, dec_size));
120122
}
121123
Err(e) => {
122124
if e.kind() == std::io::ErrorKind::NotFound {
123125
debug!("direct download {old_name}-{old_version}");
124126
//TODO: re-add fuzzy logic
125127
direct_downloads.push(Url::parse(&url)?);
126128
} else {
127-
return Err(e)?;
129+
Err(e)?;
128130
}
129131
}
130132
}
131133
}
132-
return Ok((deltas, direct_downloads));
134+
Ok((deltas, direct_downloads))
133135
}
134136

135137
pub async fn sync_db(global: crate::GlobalState, server: Url, name: Str) -> anyhow::Result<()> {
@@ -245,11 +247,11 @@ pub(crate) fn calc_stats(count: usize) -> std::io::Result<()> {
245247
let filename: String = filename.into_string().unwrap();
246248
if filename.ends_with(".delta") {
247249
let (_old, new) = filename.rsplit_once(":to:").unwrap();
248-
let pkg = Package::try_from(&*new).unwrap();
250+
let pkg = Package::try_from(new).unwrap();
249251
let (name, version, arch, trailer) = pkg.destructure();
250252
assert_eq!(&*trailer, "delta");
251253
let len = line.metadata()?.len();
252-
deltas.insert((name.into(), version.into(), arch.into()), len);
254+
deltas.insert((name, version, arch), len);
253255
} else if filename.ends_with(".pkg.tar.zst") {
254256
let (name, version, arch, _trailer) = Package::try_from(filename.as_str())
255257
.expect("weird pkg file name")
@@ -278,10 +280,9 @@ pub(crate) fn calc_stats(count: usize) -> std::io::Result<()> {
278280
}
279281
let mut unmatched = 0;
280282
for ((name, version, arch), len) in pkgs.drain() {
281-
if log::log_enabled!(log::Level::Trace) {
282-
if !deltas.contains_key(&(name.clone(), version.clone(), arch.clone())) {
283-
trace!("pkg: {name} {version} {arch} unmatched");
284-
}
283+
if log::log_enabled!(log::Level::Trace) && !deltas.contains_key(&(name.clone(), version.clone(), arch.clone()))
284+
{
285+
trace!("pkg: {name} {version} {arch} unmatched");
285286
}
286287
if let Some(((name, _version, _arch), dlen)) = deltas.remove_entry(&(name, version, arch)) {
287288
pairs

0 commit comments

Comments
 (0)