From 0e8bd6b4c734008329d942304d7239cbd6d91779 Mon Sep 17 00:00:00 2001 From: qwjyh Date: Sun, 17 Mar 2024 02:47:34 +0900 Subject: [PATCH] remove unnecessary arguments for StorageExt::mount_path --- src/backups.rs | 2 +- src/cmd_storage.rs | 2 +- src/storages.rs | 10 +++++----- src/storages/directory.rs | 14 +++++--------- src/storages/online_storage.rs | 1 - src/storages/physical_drive_partition.rs | 2 +- src/util.rs | 2 +- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/backups.rs b/src/backups.rs index a660110..68f37ea 100644 --- a/src/backups.rs +++ b/src/backups.rs @@ -43,7 +43,7 @@ impl BackupTarget { pub fn path(&self, storages: &Storages, device: &Device) -> Result { let parent = storages.get(&self.storage).unwrap(); - let parent_path = parent.mount_path(device, storages)?; + let parent_path = parent.mount_path(device)?; Ok(parent_path.join(self.path.clone())) } } diff --git a/src/cmd_storage.rs b/src/cmd_storage.rs index 8380d91..e8c4fa4 100644 --- a/src/cmd_storage.rs +++ b/src/cmd_storage.rs @@ -213,7 +213,7 @@ fn write_storages_list( } else { " " }; - let path = storage.mount_path(&device, &storages).map_or_else( + let path = storage.mount_path(&device).map_or_else( |e| { info!("Not found: {}", e); "".to_string() diff --git a/src/storages.rs b/src/storages.rs index 4371a23..d4a0793 100644 --- a/src/storages.rs +++ b/src/storages.rs @@ -68,11 +68,11 @@ impl StorageExt for Storage { } } - fn mount_path(&self, device: &devices::Device, storages: &Storages) -> Result { + fn mount_path(&self, device: &devices::Device) -> Result { match self { - Self::PhysicalStorage(s) => s.mount_path(&device, &storages), - Self::SubDirectory(s) => s.mount_path(&device, &storages), - Self::Online(s) => s.mount_path(&device, &storages), + Self::PhysicalStorage(s) => s.mount_path(&device), + Self::SubDirectory(s) => s.mount_path(&device), + Self::Online(s) => s.mount_path(&device), } } @@ -135,7 +135,7 @@ pub trait StorageExt { /// Get mount path of `self` on `device`. /// `storages` is a `HashMap` with key of storage name and value of the storage. - fn mount_path(&self, device: &devices::Device, storages: &Storages) -> Result; + fn mount_path(&self, device: &devices::Device) -> Result; /// Add local info of `device` to `self`. fn bound_on_device( diff --git a/src/storages/directory.rs b/src/storages/directory.rs index ebeaeee..5178c14 100644 --- a/src/storages/directory.rs +++ b/src/storages/directory.rs @@ -1,12 +1,8 @@ //! Manipulate subdirectories of other storages, including directories. -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result}; use serde::{Deserialize, Serialize}; -use std::{ - collections::HashMap, - fmt::{self, format}, - path, -}; +use std::{collections::HashMap, fmt, path}; use crate::devices; use crate::util; @@ -84,7 +80,7 @@ impl Directory { let parent_mount_path = self .parent(&storages) .context("Can't find parent storage")? - .mount_path(&device, &storages)?; + .mount_path(&device)?; Ok(parent_mount_path.join(self.relative_path.clone())) } } @@ -102,7 +98,7 @@ impl StorageExt for Directory { self.local_infos.get(&device.name()) } - fn mount_path(&self, device: &devices::Device, storages: &Storages) -> Result { + fn mount_path(&self, device: &devices::Device) -> Result { Ok(self .local_infos .get(&device.name()) @@ -197,7 +193,7 @@ mod test { storages .get(&"test_name".to_string()) .unwrap() - .mount_path(&device, &storages) + .mount_path(&device) .unwrap(), PathBuf::from("/mnt/sample/subdir") ); diff --git a/src/storages/online_storage.rs b/src/storages/online_storage.rs index 392252b..746e669 100644 --- a/src/storages/online_storage.rs +++ b/src/storages/online_storage.rs @@ -63,7 +63,6 @@ impl StorageExt for OnlineStorage { fn mount_path( &self, device: &devices::Device, - _storages: &Storages, ) -> Result { Ok(self .local_infos diff --git a/src/storages/physical_drive_partition.rs b/src/storages/physical_drive_partition.rs index d8b9846..e410d3f 100644 --- a/src/storages/physical_drive_partition.rs +++ b/src/storages/physical_drive_partition.rs @@ -141,7 +141,7 @@ impl StorageExt for PhysicalDrivePartition { self.local_infos.get(&device.name()) } - fn mount_path(&self, device: &devices::Device, _: &Storages) -> Result { + fn mount_path(&self, device: &devices::Device) -> Result { Ok(self .local_infos .get(&device.name()) diff --git a/src/util.rs b/src/util.rs index 3a40f8d..90ead30 100644 --- a/src/util.rs +++ b/src/util.rs @@ -17,7 +17,7 @@ pub fn min_parent_storage<'a>( .list .iter() .filter_map(|(k, storage)| { - let storage_path = match storage.mount_path(device, storages) { + let storage_path = match storage.mount_path(device) { Ok(path) => path, Err(_) => return None, };