mirror of
https://github.com/qwjyh/xdbm
synced 2025-01-19 02:33:14 +09:00
fixup! replace raw HashMap with Storages
This commit is contained in:
parent
8eb7d1179d
commit
e3675632c1
2 changed files with 21 additions and 32 deletions
|
@ -37,7 +37,7 @@ pub(crate) fn cmd_storage_add(
|
||||||
trace!("found storages: {:?}", storages);
|
trace!("found storages: {:?}", storages);
|
||||||
|
|
||||||
let device = devices::get_device(&config_dir)?;
|
let device = devices::get_device(&config_dir)?;
|
||||||
let (key, storage) = match storage_type {
|
let storage = match storage_type {
|
||||||
StorageType::P => {
|
StorageType::P => {
|
||||||
let use_sysinfo = {
|
let use_sysinfo = {
|
||||||
let options = vec![
|
let options = vec![
|
||||||
|
@ -55,7 +55,7 @@ pub(crate) fn cmd_storage_add(
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let (key, storage) = if use_sysinfo {
|
let storage = if use_sysinfo {
|
||||||
// select storage
|
// select storage
|
||||||
physical_drive_partition::select_physical_storage(device, &storages)?
|
physical_drive_partition::select_physical_storage(device, &storages)?
|
||||||
} else {
|
} else {
|
||||||
|
@ -89,21 +89,18 @@ pub(crate) fn cmd_storage_add(
|
||||||
.prompt()?,
|
.prompt()?,
|
||||||
);
|
);
|
||||||
let local_info = local_info::LocalInfo::new("".to_string(), mount_path);
|
let local_info = local_info::LocalInfo::new("".to_string(), mount_path);
|
||||||
(
|
physical_drive_partition::PhysicalDrivePartition::new(
|
||||||
name.clone(),
|
name,
|
||||||
physical_drive_partition::PhysicalDrivePartition::new(
|
kind,
|
||||||
name,
|
capacity,
|
||||||
kind,
|
fs,
|
||||||
capacity,
|
is_removable,
|
||||||
fs,
|
local_info,
|
||||||
is_removable,
|
&device,
|
||||||
local_info,
|
|
||||||
&device,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
println!("storage: {}: {:?}", key, storage);
|
println!("storage: {}: {:?}", storage.name(), storage);
|
||||||
(key, Storage::PhysicalStorage(storage))
|
Storage::PhysicalStorage(storage)
|
||||||
}
|
}
|
||||||
StorageType::S => {
|
StorageType::S => {
|
||||||
if storages.list.is_empty() {
|
if storages.list.is_empty() {
|
||||||
|
@ -128,13 +125,9 @@ pub(crate) fn cmd_storage_add(
|
||||||
let key_name = ask_unique_name(&storages, "sub-directory".to_string())?;
|
let key_name = ask_unique_name(&storages, "sub-directory".to_string())?;
|
||||||
let notes = Text::new("Notes for this sub-directory:").prompt()?;
|
let notes = Text::new("Notes for this sub-directory:").prompt()?;
|
||||||
let storage = directory::Directory::try_from_device_path(
|
let storage = directory::Directory::try_from_device_path(
|
||||||
key_name.clone(),
|
key_name, path, notes, &device, &storages,
|
||||||
path,
|
|
||||||
notes,
|
|
||||||
&device,
|
|
||||||
&storages,
|
|
||||||
)?;
|
)?;
|
||||||
(key_name, Storage::SubDirectory(storage))
|
Storage::SubDirectory(storage)
|
||||||
}
|
}
|
||||||
StorageType::O => {
|
StorageType::O => {
|
||||||
let path = path.unwrap_or_else(|| {
|
let path = path.unwrap_or_else(|| {
|
||||||
|
@ -167,18 +160,14 @@ pub(crate) fn cmd_storage_add(
|
||||||
.prompt()
|
.prompt()
|
||||||
.context("Failed to get provider")?;
|
.context("Failed to get provider")?;
|
||||||
let storage = storages::online_storage::OnlineStorage::new(
|
let storage = storages::online_storage::OnlineStorage::new(
|
||||||
name.clone(),
|
name, provider, capacity, alias, path, &device,
|
||||||
provider,
|
|
||||||
capacity,
|
|
||||||
alias,
|
|
||||||
path,
|
|
||||||
&device,
|
|
||||||
);
|
);
|
||||||
(name, Storage::Online(storage))
|
Storage::Online(storage)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// add to storages
|
// add to storages
|
||||||
|
let new_storage_name = storage.name().clone();
|
||||||
storages.add(storage)?;
|
storages.add(storage)?;
|
||||||
trace!("updated storages: {:?}", storages);
|
trace!("updated storages: {:?}", storages);
|
||||||
|
|
||||||
|
@ -189,7 +178,7 @@ pub(crate) fn cmd_storage_add(
|
||||||
add_and_commit(
|
add_and_commit(
|
||||||
&repo,
|
&repo,
|
||||||
&Path::new(storages::STORAGESFILE),
|
&Path::new(storages::STORAGESFILE),
|
||||||
&format!("Add new storage(physical drive): {}", key),
|
&format!("Add new storage(physical drive): {}", new_storage_name),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
println!("Added new storage.");
|
println!("Added new storage.");
|
||||||
|
|
|
@ -193,7 +193,7 @@ impl fmt::Display for PhysicalDrivePartition {
|
||||||
pub fn select_physical_storage(
|
pub fn select_physical_storage(
|
||||||
device: Device,
|
device: Device,
|
||||||
storages: &Storages,
|
storages: &Storages,
|
||||||
) -> Result<(String, PhysicalDrivePartition)> {
|
) -> Result<PhysicalDrivePartition> {
|
||||||
trace!("select_physical_storage");
|
trace!("select_physical_storage");
|
||||||
// get disk info fron sysinfo
|
// get disk info fron sysinfo
|
||||||
let sys_disks =
|
let sys_disks =
|
||||||
|
@ -217,8 +217,8 @@ pub fn select_physical_storage(
|
||||||
println!("The name {} is already used.", disk_name);
|
println!("The name {} is already used.", disk_name);
|
||||||
}
|
}
|
||||||
trace!("selected name: {}", disk_name);
|
trace!("selected name: {}", disk_name);
|
||||||
let storage = PhysicalDrivePartition::try_from_sysinfo_disk(&disk, disk_name.clone(), device)?;
|
let storage = PhysicalDrivePartition::try_from_sysinfo_disk(&disk, disk_name, device)?;
|
||||||
Ok((disk_name, storage))
|
Ok(storage)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_sysinfo_disk(sysinfo: &sysinfo::System) -> Result<&Disk> {
|
pub fn select_sysinfo_disk(sysinfo: &sysinfo::System) -> Result<&Disk> {
|
||||||
|
|
Loading…
Reference in a new issue