[pbs-devel] [PATCH backup 2/5] metric_collection: remove redundant map_or
Maximiliano Sandoval
m.sandoval at proxmox.com
Mon Jan 13 14:25:50 CET 2025
Fixes:
warning: this `map_or` is redundant
--> src/server/metric_collection/mod.rs:172:20
|
172 | if config
| ____________________^
173 | | .get_maintenance_mode()
174 | | .map_or(false, |mode| mode.check(Some(Operation::Read)).is_err())
| |_____________________________________________________________________________________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or
= note: `#[warn(clippy::unnecessary_map_or)]` on by default
help: use is_some_and instead
|
172 ~ if config
173 + .get_maintenance_mode().is_some_and(|mode| mode.check(Some(Operation::Read)).is_err())
|
Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
pbs-datastore/src/datastore.rs | 6 +++---
src/api2/admin/datastore.rs | 2 +-
src/api2/config/datastore.rs | 2 +-
src/api2/config/remote.rs | 2 +-
src/bin/proxmox_backup_debug/inspect.rs | 2 +-
src/bin/proxmox_backup_manager/datastore.rs | 2 +-
src/server/metric_collection/mod.rs | 2 +-
7 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
index 0801b4bf..fd3990d6 100644
--- a/pbs-datastore/src/datastore.rs
+++ b/pbs-datastore/src/datastore.rs
@@ -179,9 +179,9 @@ impl Drop for DataStore {
let remove_from_cache = last_task
&& pbs_config::datastore::config()
.and_then(|(s, _)| s.lookup::<DataStoreConfig>("datastore", self.name()))
- .map_or(false, |c| {
+ .is_ok_and(|c| {
c.get_maintenance_mode()
- .map_or(false, |m| m.clear_from_cache())
+ .is_some_and(|m| m.clear_from_cache())
});
if remove_from_cache {
@@ -287,7 +287,7 @@ impl DataStore {
let datastore: DataStoreConfig = config.lookup("datastore", name)?;
if datastore
.get_maintenance_mode()
- .map_or(false, |m| m.clear_from_cache())
+ .is_some_and(|m| m.clear_from_cache())
{
// the datastore drop handler does the checking if tasks are running and clears the
// cache entry, so we just have to trigger it here
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index c611f593..f5d80d61 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -2601,7 +2601,7 @@ fn do_unmount_device(
active_operations = task_tracking::get_active_operations(&datastore.name)?;
}
- if aborted || worker.map_or(false, |w| w.abort_requested()) {
+ if aborted || worker.is_some_and(|w| w.abort_requested()) {
let _ = expect_maintanance_unmounting(&datastore.name)
.inspect_err(|e| warn!("maintenance mode was not as expected: {e}"))
.and_then(|(lock, config)| {
diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs
index df268161..fe3260f6 100644
--- a/src/api2/config/datastore.rs
+++ b/src/api2/config/datastore.rs
@@ -105,7 +105,7 @@ pub(crate) fn do_create_datastore(
for file in dir {
let name = file?.file_name();
let name = name.to_str();
- if !name.map_or(false, |name| name.starts_with('.') || name == "lost+found") {
+ if !name.is_some_and(|name| name.starts_with('.') || name == "lost+found") {
is_empty = false;
break;
}
diff --git a/src/api2/config/remote.rs b/src/api2/config/remote.rs
index 069aef28..7d5173ef 100644
--- a/src/api2/config/remote.rs
+++ b/src/api2/config/remote.rs
@@ -268,7 +268,7 @@ pub fn delete_remote(name: String, digest: Option<String>) -> Result<(), Error>
let job_list: Vec<SyncJobConfig> = sync_jobs.convert_to_typed_array("sync")?;
for job in job_list {
- if job.remote.map_or(false, |id| id == name) {
+ if job.remote.is_some_and(|id| id == name) {
param_bail!(
"name",
"remote '{}' is used by sync job '{}' (datastore '{}')",
diff --git a/src/bin/proxmox_backup_debug/inspect.rs b/src/bin/proxmox_backup_debug/inspect.rs
index 9a75bae1..75a36870 100644
--- a/src/bin/proxmox_backup_debug/inspect.rs
+++ b/src/bin/proxmox_backup_debug/inspect.rs
@@ -429,7 +429,7 @@ fn inspect_device(device: String, param: Value) -> Result<(), Error> {
&& entry
.file_name()
.to_str()
- .map_or(false, |name| name == ".chunks")
+ .is_some_and(|name| name == ".chunks")
{
let store_path = entry
.path()
diff --git a/src/bin/proxmox_backup_manager/datastore.rs b/src/bin/proxmox_backup_manager/datastore.rs
index 0918af3a..1922a55a 100644
--- a/src/bin/proxmox_backup_manager/datastore.rs
+++ b/src/bin/proxmox_backup_manager/datastore.rs
@@ -273,7 +273,7 @@ async fn uuid_mount(param: Value, _rpcenv: &mut dyn RpcEnvironment) -> Result<Va
store
.backing_device
.clone()
- .map_or(false, |device| device.eq(&uuid))
+ .is_some_and(|device| device.eq(&uuid))
})
.collect();
diff --git a/src/server/metric_collection/mod.rs b/src/server/metric_collection/mod.rs
index 2ede8408..daedfb72 100644
--- a/src/server/metric_collection/mod.rs
+++ b/src/server/metric_collection/mod.rs
@@ -171,7 +171,7 @@ fn collect_disk_stats_sync() -> (DiskStat, Vec<DiskStat>) {
for config in datastore_list {
if config
.get_maintenance_mode()
- .map_or(false, |mode| mode.check(Some(Operation::Read)).is_err())
+ .is_some_and(|mode| mode.check(Some(Operation::Read)).is_err())
{
continue;
}
--
2.39.5
More information about the pbs-devel
mailing list