lint with clippy

fix problems reported by clippy excepts about unused functions
This commit is contained in:
qwjyh 2024-03-18 08:36:07 +09:00
parent 01f959b666
commit bac829c1f1
12 changed files with 296 additions and 313 deletions

View file

@ -52,7 +52,7 @@ impl Directory {
device: &devices::Device,
storages: &Storages,
) -> Result<Directory> {
let (parent, diff_path) = util::min_parent_storage(&path, storages, &device)
let (parent, diff_path) = util::min_parent_storage(&path, storages, device)
.context("Failed to compare diff of paths")?;
trace!("Selected parent: {}", parent.name());
let local_info = LocalInfo::new(alias, path);
@ -78,9 +78,9 @@ impl Directory {
/// Resolve mount path of directory with current device.
fn mount_path(&self, device: &devices::Device, storages: &Storages) -> Result<path::PathBuf> {
let parent_mount_path = self
.parent(&storages)
.parent(storages)
.context("Can't find parent storage")?
.mount_path(&device)?;
.mount_path(device)?;
Ok(parent_mount_path.join(self.relative_path.clone()))
}
}
@ -181,7 +181,7 @@ mod test {
);
let mut storages = Storages::new();
storages
.add(storages::Storage::PhysicalStorage(physical))
.add(storages::Storage::Physical(physical))
.unwrap();
storages.add(Storage::SubDirectory(directory)).unwrap();
// assert_eq!(directory.name(), "test_name");

View file

@ -5,9 +5,8 @@ use crate::devices::Device;
use crate::storages::{Storage, StorageExt, Storages};
use anyhow::{anyhow, Context, Result};
use byte_unit::Byte;
use inquire::Text;
use serde::{Deserialize, Serialize};
use std::path;
use std::path::{self, Path};
use std::{collections::HashMap, fmt};
use sysinfo::{Disk, DiskExt, SystemExt};
@ -61,7 +60,7 @@ impl PhysicalDrivePartition {
let fs = std::str::from_utf8(fs)?;
let local_info = LocalInfo::new(alias, disk.mount_point().to_path_buf());
Ok(PhysicalDrivePartition {
name: name,
name,
kind: format!("{:?}", disk.kind()),
capacity: disk.total_space(),
fs: fs.to_string(),
@ -71,12 +70,8 @@ impl PhysicalDrivePartition {
})
}
pub fn bind_device(
&mut self,
disk: &sysinfo::Disk,
config_dir: &std::path::PathBuf,
) -> Result<()> {
let device = devices::get_device(&config_dir)?;
pub fn bind_device(&mut self, disk: &sysinfo::Disk, config_dir: &Path) -> Result<()> {
let device = devices::get_device(config_dir)?;
let alias = match disk.name().to_str() {
Some(s) => s.to_string(),
None => return Err(anyhow!("Failed to convert storage name to valid str.")),
@ -101,33 +96,6 @@ impl PhysicalDrivePartition {
}
}
#[cfg(test)]
mod test {
use crate::{
devices::Device,
storages::{local_info::LocalInfo, StorageExt},
};
use std::path::PathBuf;
use super::PhysicalDrivePartition;
#[test]
fn test_new() {
let localinfo = LocalInfo::new("alias".to_string(), PathBuf::from("/mnt/sample"));
let storage = PhysicalDrivePartition::new(
"name".to_string(),
"SSD".to_string(),
100,
"ext_4".to_string(),
true,
localinfo,
&Device::new("test_device".to_string()),
);
assert_eq!(storage.name(), "name");
assert_eq!(storage.capacity(), Some(100));
}
}
impl StorageExt for PhysicalDrivePartition {
fn name(&self) -> &String {
&self.name
@ -203,7 +171,7 @@ pub fn select_physical_storage(
trace!("{:?}", disk)
}
let disk = select_sysinfo_disk(&sys_disks)?;
let storage = PhysicalDrivePartition::try_from_sysinfo_disk(&disk, disk_name, device)?;
let storage = PhysicalDrivePartition::try_from_sysinfo_disk(disk, disk_name, device)?;
Ok(storage)
}
@ -213,10 +181,7 @@ fn select_sysinfo_disk(sysinfo: &sysinfo::System) -> Result<&Disk> {
.iter()
.enumerate()
.map(|(i, disk)| {
let name = match disk.name().to_str() {
Some(s) => s,
None => "",
};
let name = disk.name().to_str().unwrap_or("");
let fs: &str = std::str::from_utf8(disk.file_system()).unwrap_or("unknown");
let kind = format!("{:?}", disk.kind());
let mount_path = disk.mount_point();
@ -246,3 +211,30 @@ fn select_sysinfo_disk(sysinfo: &sysinfo::System) -> Result<&Disk> {
trace!("selected disk: {:?}", disk);
Ok(disk)
}
#[cfg(test)]
mod test {
use crate::{
devices::Device,
storages::{local_info::LocalInfo, StorageExt},
};
use std::path::PathBuf;
use super::PhysicalDrivePartition;
#[test]
fn test_new() {
let localinfo = LocalInfo::new("alias".to_string(), PathBuf::from("/mnt/sample"));
let storage = PhysicalDrivePartition::new(
"name".to_string(),
"SSD".to_string(),
100,
"ext_4".to_string(),
true,
localinfo,
&Device::new("test_device".to_string()),
);
assert_eq!(storage.name(), "name");
assert_eq!(storage.capacity(), Some(100));
}
}