5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2025-02-03 13:47:18 +03:00

clippy fixes

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2022-07-25 15:40:44 +02:00
parent 24fdef9651
commit 3be9106f1c
9 changed files with 47 additions and 52 deletions

View File

@ -337,7 +337,7 @@ impl AclTree {
fn get_node(&self, path: &[&str]) -> Option<&AclTreeNode> { fn get_node(&self, path: &[&str]) -> Option<&AclTreeNode> {
let mut node = &self.root; let mut node = &self.root;
for outer in path { for outer in path {
for comp in outer.split("/") { for comp in outer.split('/') {
node = match node.children.get(comp) { node = match node.children.get(comp) {
Some(n) => n, Some(n) => n,
None => return None, None => return None,
@ -350,7 +350,7 @@ impl AclTree {
fn get_node_mut(&mut self, path: &[&str]) -> Option<&mut AclTreeNode> { fn get_node_mut(&mut self, path: &[&str]) -> Option<&mut AclTreeNode> {
let mut node = &mut self.root; let mut node = &mut self.root;
for outer in path { for outer in path {
for comp in outer.split("/") { for comp in outer.split('/') {
node = match node.children.get_mut(comp) { node = match node.children.get_mut(comp) {
Some(n) => n, Some(n) => n,
None => return None, None => return None,
@ -363,7 +363,7 @@ impl AclTree {
fn get_or_insert_node(&mut self, path: &[&str]) -> &mut AclTreeNode { fn get_or_insert_node(&mut self, path: &[&str]) -> &mut AclTreeNode {
let mut node = &mut self.root; let mut node = &mut self.root;
for outer in path { for outer in path {
for comp in outer.split("/") { for comp in outer.split('/') {
node = node.children.entry(String::from(comp)).or_default(); node = node.children.entry(String::from(comp)).or_default();
} }
} }
@ -666,7 +666,7 @@ impl AclTree {
pub fn get_child_paths(&self, auth_id: &Authid, path: &[&str]) -> Result<Vec<String>, Error> { pub fn get_child_paths(&self, auth_id: &Authid, path: &[&str]) -> Result<Vec<String>, Error> {
let mut res = Vec::new(); let mut res = Vec::new();
if let Some(node) = self.get_node(&path) { if let Some(node) = self.get_node(path) {
let path = path.join("/"); let path = path.join("/");
node.get_child_paths(path, auth_id, &mut res)?; node.get_child_paths(path, auth_id, &mut res)?;
} }

View File

@ -486,7 +486,7 @@ fn backup_worker(
print_ns_and_snapshot(info.backup_dir.backup_ns(), info.backup_dir.as_ref()); print_ns_and_snapshot(info.backup_dir.backup_ns(), info.backup_dir.as_ref());
if pool_writer.contains_snapshot( if pool_writer.contains_snapshot(
datastore_name, datastore_name,
&info.backup_dir.backup_ns(), info.backup_dir.backup_ns(),
info.backup_dir.as_ref(), info.backup_dir.as_ref(),
) { ) {
task_log!(worker, "skip snapshot {}", rel_path); task_log!(worker, "skip snapshot {}", rel_path);
@ -512,7 +512,7 @@ fn backup_worker(
if pool_writer.contains_snapshot( if pool_writer.contains_snapshot(
datastore_name, datastore_name,
&info.backup_dir.backup_ns(), info.backup_dir.backup_ns(),
info.backup_dir.as_ref(), info.backup_dir.as_ref(),
) { ) {
task_log!(worker, "skip snapshot {}", rel_path); task_log!(worker, "skip snapshot {}", rel_path);

View File

@ -88,7 +88,7 @@ impl TryFrom<Vec<String>> for NamespaceMap {
} }
impl NamespaceMap { impl NamespaceMap {
fn used_namespaces<'a>(&self, datastore: &str) -> HashSet<BackupNamespace> { fn used_namespaces(&self, datastore: &str) -> HashSet<BackupNamespace> {
let mut set = HashSet::new(); let mut set = HashSet::new();
if let Some(mapping) = self.map.get(datastore) { if let Some(mapping) = self.map.get(datastore) {
for (ns, _) in mapping.values() { for (ns, _) in mapping.values() {
@ -190,8 +190,8 @@ impl DataStoreMap {
fn target_store(&self, source_datastore: &str) -> Option<Arc<DataStore>> { fn target_store(&self, source_datastore: &str) -> Option<Arc<DataStore>> {
self.map self.map
.get(source_datastore) .get(source_datastore)
.or_else(|| self.default.as_ref()) .or(self.default.as_ref())
.map(|store| Arc::clone(store)) .map(Arc::clone)
} }
fn get_targets( fn get_targets(
@ -397,7 +397,7 @@ pub fn restore(
let email = notify_user let email = notify_user
.as_ref() .as_ref()
.and_then(|userid| lookup_user_email(userid)) .and_then(lookup_user_email)
.or_else(|| lookup_user_email(&auth_id.clone().into())); .or_else(|| lookup_user_email(&auth_id.clone().into()));
task_log!(worker, "Mediaset '{media_set}'"); task_log!(worker, "Mediaset '{media_set}'");
@ -406,7 +406,7 @@ pub fn restore(
let res = if snapshots.is_some() || namespaces { let res = if snapshots.is_some() || namespaces {
restore_list_worker( restore_list_worker(
worker.clone(), worker.clone(),
snapshots.unwrap_or_else(Vec::new), snapshots.unwrap_or_default(),
inventory, inventory,
media_set_uuid, media_set_uuid,
drive_config, drive_config,
@ -521,7 +521,7 @@ fn restore_full_worker(
&mut checked_chunks_map, &mut checked_chunks_map,
restore_owner, restore_owner,
&email, &email,
&auth_id, auth_id,
)?; )?;
} }
@ -589,7 +589,7 @@ fn check_snapshot_restorable(
have_some_permissions = true; have_some_permissions = true;
if datastore.snapshot_path(&ns, &dir).exists() { if datastore.snapshot_path(&ns, dir).exists() {
task_warn!( task_warn!(
worker, worker,
"found snapshot {snapshot} on target datastore/namespace, skipping...", "found snapshot {snapshot} on target datastore/namespace, skipping...",
@ -603,7 +603,7 @@ fn check_snapshot_restorable(
bail!("cannot restore {snapshot} to any target namespace due to permissions"); bail!("cannot restore {snapshot} to any target namespace due to permissions");
} }
return Ok(can_restore_some); Ok(can_restore_some)
} }
fn restore_list_worker( fn restore_list_worker(
@ -670,13 +670,13 @@ fn restore_list_worker(
let (store, snapshot) = store_snapshot.split_at(idx + 1); let (store, snapshot) = store_snapshot.split_at(idx + 1);
let store = &store[..idx]; // remove ':' let store = &store[..idx]; // remove ':'
match parse_ns_and_snapshot(&snapshot) { match parse_ns_and_snapshot(snapshot) {
Ok((ns, dir)) => { Ok((ns, dir)) => {
match check_snapshot_restorable( match check_snapshot_restorable(
&worker, &worker,
&store_map, &store_map,
&store, store,
&snapshot, snapshot,
&ns, &ns,
&dir, &dir,
true, true,
@ -710,7 +710,7 @@ fn restore_list_worker(
None => bail!("unexpected error"), // we already checked those None => bail!("unexpected error"), // we already checked those
}; };
let (media_id, file_num) = let (media_id, file_num) =
if let Some((media_uuid, file_num)) = catalog.lookup_snapshot(store, &snapshot) { if let Some((media_uuid, file_num)) = catalog.lookup_snapshot(store, snapshot) {
let media_id = inventory.lookup_media(media_uuid).unwrap(); let media_id = inventory.lookup_media(media_uuid).unwrap();
(media_id, file_num) (media_id, file_num)
} else { } else {
@ -926,7 +926,7 @@ fn restore_list_worker(
} }
for (datastore, _) in store_map.used_datastores().values() { for (datastore, _) in store_map.used_datastores().values() {
let tmp_path = media_set_tmpdir(&datastore, &media_set_uuid); let tmp_path = media_set_tmpdir(datastore, &media_set_uuid);
match std::fs::remove_dir_all(&tmp_path) { match std::fs::remove_dir_all(&tmp_path) {
Ok(()) => {} Ok(()) => {}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {} Err(err) if err.kind() == std::io::ErrorKind::NotFound => {}
@ -1193,15 +1193,12 @@ fn restore_partial_chunk_archive<'a>(
let verify_and_write_channel = writer_pool.channel(); let verify_and_write_channel = writer_pool.channel();
loop { while let Some((digest, blob)) = decoder.next_chunk()? {
let (digest, blob) = match decoder.next_chunk()? {
Some((digest, blob)) => (digest, blob),
None => break,
};
worker.check_abort()?; worker.check_abort()?;
if chunk_list.remove(&digest) { if chunk_list.remove(&digest) {
verify_and_write_channel.send((blob, digest.clone()))?; verify_and_write_channel.send((blob, digest))?;
count += 1; count += 1;
} }
if chunk_list.is_empty() { if chunk_list.is_empty() {
@ -1326,7 +1323,7 @@ pub fn restore_media(
&mut catalog, &mut catalog,
checked_chunks_map, checked_chunks_map,
verbose, verbose,
&auth_id, auth_id,
)?; )?;
} }
@ -1388,7 +1385,7 @@ fn restore_archive<'a>(
&user_info, &user_info,
&datastore, &datastore,
&backup_ns, &backup_ns,
&auth_id, auth_id,
Some(restore_owner), Some(restore_owner),
)?; )?;
let (owner, _group_lock) = datastore.create_locked_backup_group( let (owner, _group_lock) = datastore.create_locked_backup_group(
@ -1483,7 +1480,7 @@ fn restore_archive<'a>(
.unwrap_or("_unused_") .unwrap_or("_unused_")
.to_string(), .to_string(),
) )
.or_insert(HashSet::new()); .or_default();
let chunks = if let Some(datastore) = datastore { let chunks = if let Some(datastore) = datastore {
restore_chunk_archive( restore_chunk_archive(
@ -1649,8 +1646,8 @@ fn restore_chunk_archive<'a>(
worker.check_abort()?; worker.check_abort()?;
if !checked_chunks.contains(&digest) { if !checked_chunks.contains(&digest) {
verify_and_write_channel.send((blob, digest.clone()))?; verify_and_write_channel.send((blob, digest))?;
checked_chunks.insert(digest.clone()); checked_chunks.insert(digest);
} }
chunks.push(digest); chunks.push(digest);
} }
@ -1884,11 +1881,10 @@ pub fn fast_catalog_restore(
let wanted = media_set let wanted = media_set
.media_list() .media_list()
.iter() .iter()
.find(|e| match e { .any(|e| match e {
None => false, None => false,
Some(uuid) => uuid == catalog_uuid, Some(uuid) => uuid == catalog_uuid,
}) });
.is_some();
if !wanted { if !wanted {
task_log!( task_log!(

View File

@ -135,7 +135,7 @@ pub fn update_online_status(
for mut changer_config in changers { for mut changer_config in changers {
if let Some(changer) = changer { if let Some(changer) = changer {
if changer != &changer_config.name { if changer != changer_config.name {
continue; continue;
} }
found_changer = true; found_changer = true;
@ -158,7 +158,7 @@ pub fn update_online_status(
let vtapes: Vec<VirtualTapeDrive> = config.convert_to_typed_array("virtual")?; let vtapes: Vec<VirtualTapeDrive> = config.convert_to_typed_array("virtual")?;
for mut vtape in vtapes { for mut vtape in vtapes {
if let Some(changer) = changer { if let Some(changer) = changer {
if changer != &vtape.name { if changer != vtape.name {
continue; continue;
} }
found_changer = true; found_changer = true;

View File

@ -49,7 +49,7 @@ pub fn open_lto_tape_drive(config: &LtoTapeDrive) -> Result<LtoTapeHandle, Error
let mut handle = LtoTapeHandle::new(file)?; let mut handle = LtoTapeHandle::new(file)?;
if !handle.sg_tape.test_unit_ready().is_ok() { if handle.sg_tape.test_unit_ready().is_err() {
// for autoloader only, try to reload ejected tapes // for autoloader only, try to reload ejected tapes
if config.changer.is_some() { if config.changer.is_some() {
let _ = handle.sg_tape.load(); // just try, ignore error let _ = handle.sg_tape.load(); // just try, ignore error
@ -302,7 +302,7 @@ impl TapeDriver for LtoTapeHandle {
let mut tape_key = [0u8; 32]; let mut tape_key = [0u8; 32];
let uuid_bytes: [u8; 16] = uuid.as_bytes().clone(); let uuid_bytes: [u8; 16] = *uuid.as_bytes();
openssl::pkcs5::pbkdf2_hmac( openssl::pkcs5::pbkdf2_hmac(
&item.key, &item.key,

View File

@ -198,7 +198,7 @@ impl VirtualTapeHandle {
match status.current_tape { match status.current_tape {
Some(VirtualTapeStatus { ref mut pos, .. }) => { Some(VirtualTapeStatus { ref mut pos, .. }) => {
if count <= *pos { if count <= *pos {
*pos = *pos - count; *pos -= count;
} else { } else {
bail!("backward_space_count_files failed: move before BOT"); bail!("backward_space_count_files failed: move before BOT");
} }

View File

@ -18,6 +18,7 @@ use pbs_api_types::{parse_ns_and_snapshot, print_ns_and_snapshot, BackupDir, Bac
use crate::tape::{file_formats::MediaSetLabel, MediaId}; use crate::tape::{file_formats::MediaSetLabel, MediaId};
#[derive(Default)]
pub struct DatastoreContent { pub struct DatastoreContent {
pub snapshot_index: HashMap<String, u64>, // snapshot => file_nr pub snapshot_index: HashMap<String, u64>, // snapshot => file_nr
pub chunk_index: HashMap<[u8; 32], u64>, // chunk => file_nr pub chunk_index: HashMap<[u8; 32], u64>, // chunk => file_nr
@ -611,7 +612,7 @@ impl MediaCatalog {
self.content self.content
.entry(store.to_string()) .entry(store.to_string())
.or_insert(DatastoreContent::new()); .or_default();
self.current_archive = Some((uuid, file_number, store.to_string())); self.current_archive = Some((uuid, file_number, store.to_string()));
@ -728,7 +729,7 @@ impl MediaCatalog {
let content = self let content = self
.content .content
.entry(store.to_string()) .entry(store.to_string())
.or_insert(DatastoreContent::new()); .or_default();
content.snapshot_index.insert(path, file_number); content.snapshot_index.insert(path, file_number);
@ -858,7 +859,7 @@ impl MediaCatalog {
self.content self.content
.entry(store.to_string()) .entry(store.to_string())
.or_insert(DatastoreContent::new()); .or_default();
self.current_archive = Some((uuid, file_number, store.to_string())); self.current_archive = Some((uuid, file_number, store.to_string()));
} }
@ -895,7 +896,7 @@ impl MediaCatalog {
let content = self let content = self
.content .content
.entry(store.to_string()) .entry(store.to_string())
.or_insert(DatastoreContent::new()); .or_default();
content content
.snapshot_index .snapshot_index
@ -1016,19 +1017,17 @@ impl MediaSetCatalog {
pub fn list_snapshots(&self) -> impl Iterator<Item = (&str, &str)> { pub fn list_snapshots(&self) -> impl Iterator<Item = (&str, &str)> {
self.catalog_list self.catalog_list
.values() .values()
.map(|catalog| { .flat_map(|catalog| {
catalog catalog
.content .content
.iter() .iter()
.map(|(store, content)| { .flat_map(|(store, content)| {
content content
.snapshot_index .snapshot_index
.keys() .keys()
.map(move |key| (store.as_str(), key.as_str())) .map(move |key| (store.as_str(), key.as_str()))
}) })
.flatten()
}) })
.flatten()
} }
} }

View File

@ -432,14 +432,14 @@ impl MediaPool {
res res
}); });
free_media.pop().map(|e| e.clone()) free_media.pop().cloned()
} }
// Get next empty media // Get next empty media
pub fn next_empty_media(&self, media_list: &[BackupMedia]) -> Option<MediaId> { pub fn next_empty_media(&self, media_list: &[BackupMedia]) -> Option<MediaId> {
let mut empty_media = Vec::new(); let mut empty_media = Vec::new();
for media in media_list.into_iter() { for media in media_list.iter() {
if !self.location_is_available(media.location()) { if !self.location_is_available(media.location()) {
continue; continue;
} }
@ -472,7 +472,7 @@ impl MediaPool {
) -> Option<MediaId> { ) -> Option<MediaId> {
let mut expired_media = Vec::new(); let mut expired_media = Vec::new();
for media in media_list.into_iter() { for media in media_list.iter() {
if !self.location_is_available(media.location()) { if !self.location_is_available(media.location()) {
continue; continue;
} }

View File

@ -106,7 +106,7 @@ impl PoolWriter {
pub fn get_used_media_labels(&self) -> Result<Vec<String>, Error> { pub fn get_used_media_labels(&self) -> Result<Vec<String>, Error> {
let mut res = Vec::with_capacity(self.used_tapes.len()); let mut res = Vec::with_capacity(self.used_tapes.len());
for media_uuid in &self.used_tapes { for media_uuid in &self.used_tapes {
let media_info = self.pool.lookup_media(&media_uuid)?; let media_info = self.pool.lookup_media(media_uuid)?;
res.push(media_info.label_text().to_string()); res.push(media_info.label_text().to_string());
} }
@ -271,7 +271,7 @@ impl PoolWriter {
self.catalog_set.lock().unwrap().append_catalog(catalog)?; self.catalog_set.lock().unwrap().append_catalog(catalog)?;
let media_set = media.media_set_label().clone().unwrap(); let media_set = media.media_set_label().unwrap();
let encrypt_fingerprint = media_set let encrypt_fingerprint = media_set
.encryption_key_fingerprint .encryption_key_fingerprint
@ -390,7 +390,7 @@ impl PoolWriter {
fn append_media_set_catalogs(&mut self, worker: &WorkerTask) -> Result<(), Error> { fn append_media_set_catalogs(&mut self, worker: &WorkerTask) -> Result<(), Error> {
let media_set = self.pool.current_media_set(); let media_set = self.pool.current_media_set();
let mut media_list = &media_set.media_list()[..]; let mut media_list = media_set.media_list();
if media_list.len() < 2 { if media_list.len() < 2 {
return Ok(()); return Ok(());
} }