clippy: fix warnings in components/net (#31564)

* clippy: fix some warnings in components/net

* fix: review comments

* fix: tidy
This commit is contained in:
eri 2024-03-10 16:34:16 +01:00 committed by GitHub
parent 099bb0fa19
commit 67b277c992
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 325 additions and 379 deletions

View file

@ -5,7 +5,6 @@
use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::io::{BufRead, BufReader, Read, Seek, SeekFrom};
use std::mem;
use std::ops::Index;
use std::path::{Path, PathBuf};
use std::sync::atomic::{self, AtomicBool, AtomicUsize, Ordering};
@ -103,13 +102,12 @@ impl FileManager {
let store = self.store.clone();
self.thread_pool
.upgrade()
.and_then(|pool| {
.map(|pool| {
pool.spawn(move || {
if let Err(e) = store.try_read_file(&sender, id, origin) {
let _ = sender.send(Err(FileManagerThreadError::BlobURLStoreError(e)));
}
});
Some(())
})
.unwrap_or_else(|| {
warn!("FileManager tried to read a file after CoreResourceManager has exited.");
@ -160,11 +158,10 @@ impl FileManager {
let embedder = self.embedder_proxy.clone();
self.thread_pool
.upgrade()
.and_then(|pool| {
.map(|pool| {
pool.spawn(move || {
store.select_file(filter, sender, origin, opt_test_path, embedder);
});
Some(())
})
.unwrap_or_else(|| {
warn!(
@ -177,11 +174,10 @@ impl FileManager {
let embedder = self.embedder_proxy.clone();
self.thread_pool
.upgrade()
.and_then(|pool| {
.map(|pool| {
pool.spawn(move || {
store.select_files(filter, sender, origin, opt_test_paths, embedder);
});
Some(())
})
.unwrap_or_else(|| {
warn!(
@ -221,7 +217,7 @@ impl FileManager {
let done_sender = done_sender.clone();
self.thread_pool
.upgrade()
.and_then(|pool| {
.map(|pool| {
pool.spawn(move || {
loop {
if cancellation_listener.lock().unwrap().cancelled() {
@ -266,7 +262,7 @@ impl FileManager {
if length == 0 {
let mut body = res_body.lock().unwrap();
let completed_body = match *body {
ResponseBody::Receiving(ref mut body) => mem::replace(body, vec![]),
ResponseBody::Receiving(ref mut body) => std::mem::take(body),
_ => vec![],
};
*body = ResponseBody::Done(completed_body);
@ -276,7 +272,6 @@ impl FileManager {
reader.consume(length);
}
});
Some(())
})
.unwrap_or_else(|| {
warn!("FileManager tried to fetch a file in chunks after CoreResourceManager has exited.");
@ -373,7 +368,7 @@ impl FileManager {
FileImpl::Sliced(parent_id, inner_rel_pos) => {
// Next time we don't need to check validity since
// we have already done that for requesting URL if necessary.
return self.fetch_blob_buf(
self.fetch_blob_buf(
done_sender,
cancellation_listener,
&parent_id,
@ -383,7 +378,7 @@ impl FileManager {
RelativePos::full_range().slice_inner(&inner_rel_pos),
),
response,
);
)
},
}
}
@ -411,7 +406,7 @@ impl FileManagerStore {
origin_in: &FileOrigin,
) -> Result<FileImpl, BlobURLStoreError> {
match self.entries.read().unwrap().get(id) {
Some(ref entry) => {
Some(entry) => {
if *origin_in != *entry.origin {
Err(BlobURLStoreError::InvalidOrigin)
} else {
@ -441,7 +436,7 @@ impl FileManagerStore {
let zero_refs = entry.refs.load(Ordering::Acquire) == 0;
// Check if no other fetch has acquired a token for this file.
let no_outstanding_tokens = entry.outstanding_tokens.len() == 0;
let no_outstanding_tokens = entry.outstanding_tokens.is_empty();
// Check if there is still a blob URL outstanding.
let valid = entry.is_valid_url.load(Ordering::Acquire);
@ -450,7 +445,7 @@ impl FileManagerStore {
let do_remove = zero_refs && no_outstanding_tokens && !valid;
if do_remove {
entries.remove(&file_id);
entries.remove(file_id);
}
}
}
@ -461,7 +456,7 @@ impl FileManagerStore {
let parent_id = match entries.get(file_id) {
Some(entry) => {
if let FileImpl::Sliced(ref parent_id, _) = entry.file_impl {
Some(parent_id.clone())
Some(*parent_id)
} else {
None
}
@ -477,7 +472,7 @@ impl FileManagerStore {
return FileTokenCheck::ShouldFail;
}
let token = Uuid::new_v4();
entry.outstanding_tokens.insert(token.clone());
entry.outstanding_tokens.insert(token);
return FileTokenCheck::Required(token);
}
FileTokenCheck::ShouldFail
@ -585,7 +580,6 @@ impl FileManagerStore {
},
None => {
let _ = sender.send(Err(FileManagerThreadError::UserCancelled));
return;
},
}
}
@ -631,7 +625,6 @@ impl FileManagerStore {
},
None => {
let _ = sender.send(Err(FileManagerThreadError::UserCancelled));
return;
},
}
}
@ -672,7 +665,7 @@ impl FileManagerStore {
id,
FileStoreEntry {
origin: origin.to_string(),
file_impl: file_impl,
file_impl,
refs: AtomicUsize::new(1),
// Invalid here since create_entry is called by file selection
is_valid_url: AtomicBool::new(false),
@ -687,11 +680,11 @@ impl FileManagerStore {
};
Ok(SelectedFile {
id: id,
id,
filename: filename_path.to_path_buf(),
modified: modified_epoch,
size: file_size,
type_string: type_string,
type_string,
})
}
@ -798,13 +791,13 @@ impl FileManagerStore {
let is_valid = entry.is_valid_url.load(Ordering::Acquire);
// Check if no fetch has acquired a token for this file.
let no_outstanding_tokens = entry.outstanding_tokens.len() == 0;
let no_outstanding_tokens = entry.outstanding_tokens.is_empty();
// Can we remove this file?
let do_remove = !is_valid && no_outstanding_tokens;
if let FileImpl::Sliced(ref parent_id, _) = entry.file_impl {
(do_remove, Some(parent_id.clone()))
(do_remove, Some(*parent_id))
} else {
(do_remove, None)
}
@ -867,13 +860,13 @@ impl FileManagerStore {
let zero_refs = entry.refs.load(Ordering::Acquire) == 0;
// Check if no fetch has acquired a token for this file.
let no_outstanding_tokens = entry.outstanding_tokens.len() == 0;
let no_outstanding_tokens = entry.outstanding_tokens.is_empty();
// Can we remove this file?
let do_remove = zero_refs && no_outstanding_tokens;
if let FileImpl::Sliced(ref parent_id, _) = entry.file_impl {
(do_remove, Some(parent_id.clone()), Ok(()))
(do_remove, Some(*parent_id), Ok(()))
} else {
(do_remove, None, Ok(()))
}
@ -913,7 +906,7 @@ fn read_file_in_chunks(
buf.truncate(n);
let blob_buf = BlobBuf {
filename: opt_filename,
type_string: type_string,
type_string,
size: size as u64,
bytes: buf,
};