mirror of
https://github.com/qwjyh/xdbm
synced 2025-07-07 07:09:19 +09:00
add for online, refactored bind
This commit is contained in:
parent
017e34d392
commit
5f81eccd2d
7 changed files with 175 additions and 57 deletions
|
@ -104,16 +104,6 @@ impl Directory {
|
|||
let parent_mount_path = parent.mount_path(&device, &storages)?;
|
||||
Ok(parent_mount_path.join(self.relative_path.clone()))
|
||||
}
|
||||
|
||||
fn bind_device(&mut self, alias: String, device: &devices::Device, storages: &HashMap<String, Storage>) -> Result<()> {
|
||||
let mount_path = self.mount_path(&device, &storages)?;
|
||||
let new_local_info = LocalInfo::new(alias, mount_path);
|
||||
match self.local_info.insert(device.name(), new_local_info) {
|
||||
Some(v) => println!("Value updated. old val is: {:?}", v),
|
||||
None => println!("inserted new val"),
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl StorageExt for Directory {
|
||||
|
@ -121,8 +111,8 @@ impl StorageExt for Directory {
|
|||
&self.name
|
||||
}
|
||||
|
||||
fn has_alias(&self, device: &devices::Device) -> bool {
|
||||
self.local_info.get(&device.name()).is_some()
|
||||
fn local_info(&self, device: &devices::Device) -> Option<&LocalInfo> {
|
||||
self.local_info.get(&device.name())
|
||||
}
|
||||
|
||||
fn mount_path(
|
||||
|
@ -132,6 +122,21 @@ impl StorageExt for Directory {
|
|||
) -> Result<path::PathBuf> {
|
||||
Ok(self.mount_path(device, storages)?)
|
||||
}
|
||||
|
||||
/// This method doesn't use `mount_path`.
|
||||
fn bound_on_device(
|
||||
&mut self,
|
||||
alias: String,
|
||||
mount_point: path::PathBuf,
|
||||
device: &devices::Device,
|
||||
) -> Result<()> {
|
||||
let new_local_info = LocalInfo::new(alias, mount_point);
|
||||
match self.local_info.insert(device.name(), new_local_info) {
|
||||
Some(v) => println!("Value updated. old val is: {:?}", v),
|
||||
None => println!("inserted new val"),
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Directory {
|
||||
|
|
|
@ -18,6 +18,10 @@ impl LocalInfo {
|
|||
LocalInfo { alias, mount_path }
|
||||
}
|
||||
|
||||
pub fn alias(&self) -> String {
|
||||
self.alias.clone() // ?
|
||||
}
|
||||
|
||||
pub fn mount_path(&self) -> path::PathBuf {
|
||||
self.mount_path.clone()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Online storage which is not a children of any physical drive.
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::{Context, Result};
|
||||
use byte_unit::Byte;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
@ -9,6 +9,7 @@ use std::path;
|
|||
|
||||
use crate::devices;
|
||||
|
||||
use super::local_info;
|
||||
use super::local_info::LocalInfo;
|
||||
use super::StorageExt;
|
||||
|
||||
|
@ -16,13 +17,26 @@ use super::StorageExt;
|
|||
pub struct OnlineStorage {
|
||||
name: String,
|
||||
provider: String,
|
||||
capacity: u8,
|
||||
capacity: u64,
|
||||
local_info: HashMap<String, LocalInfo>,
|
||||
}
|
||||
|
||||
impl OnlineStorage {
|
||||
fn new(name: String, provider: String, capacity: u8, path: path::PathBuf, device: &devices::Device) -> OnlineStorage {
|
||||
todo!()
|
||||
pub fn new(
|
||||
name: String,
|
||||
provider: String,
|
||||
capacity: u64,
|
||||
alias: String,
|
||||
path: path::PathBuf,
|
||||
device: &devices::Device,
|
||||
) -> OnlineStorage {
|
||||
let local_info = local_info::LocalInfo::new(alias, path);
|
||||
OnlineStorage {
|
||||
name,
|
||||
provider,
|
||||
capacity,
|
||||
local_info: HashMap::from([(device.name(), local_info)]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,8 +45,8 @@ impl StorageExt for OnlineStorage {
|
|||
&self.name
|
||||
}
|
||||
|
||||
fn has_alias(&self, device: &devices::Device) -> bool {
|
||||
self.local_info.get(&device.name()).is_some()
|
||||
fn local_info(&self, device: &devices::Device) -> Option<&LocalInfo> {
|
||||
self.local_info.get(&device.name())
|
||||
}
|
||||
|
||||
fn mount_path(
|
||||
|
@ -46,6 +60,22 @@ impl StorageExt for OnlineStorage {
|
|||
.context(format!("LocalInfo for storage: {} not found", &self.name()))?
|
||||
.mount_path())
|
||||
}
|
||||
|
||||
fn bound_on_device(
|
||||
&mut self,
|
||||
alias: String,
|
||||
mount_point: path::PathBuf,
|
||||
device: &devices::Device,
|
||||
) -> Result<()> {
|
||||
match self
|
||||
.local_info
|
||||
.insert(device.name(), LocalInfo::new(alias, mount_point))
|
||||
{
|
||||
Some(old) => info!("Value replaced. Old value: {:?}", old),
|
||||
None => info!("New value inserted."),
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for OnlineStorage {
|
||||
|
|
|
@ -36,7 +36,7 @@ impl PhysicalDrivePartition {
|
|||
fs: String,
|
||||
is_removable: bool,
|
||||
local_info: LocalInfo,
|
||||
device: &Device
|
||||
device: &Device,
|
||||
) -> PhysicalDrivePartition {
|
||||
PhysicalDrivePartition {
|
||||
name,
|
||||
|
@ -101,8 +101,8 @@ impl StorageExt for PhysicalDrivePartition {
|
|||
&self.name
|
||||
}
|
||||
|
||||
fn has_alias(&self, device: &devices::Device) -> bool {
|
||||
self.local_info.get(&device.name()).is_some()
|
||||
fn local_info(&self, device: &devices::Device) -> Option<&local_info::LocalInfo> {
|
||||
self.local_info.get(&device.name())
|
||||
}
|
||||
|
||||
fn mount_path(
|
||||
|
@ -116,6 +116,22 @@ impl StorageExt for PhysicalDrivePartition {
|
|||
.context(format!("LocalInfo for storage: {} not found", &self.name()))?
|
||||
.mount_path())
|
||||
}
|
||||
|
||||
fn bound_on_device(
|
||||
&mut self,
|
||||
alias: String,
|
||||
mount_point: path::PathBuf,
|
||||
device: &devices::Device,
|
||||
) -> Result<()> {
|
||||
match self
|
||||
.local_info
|
||||
.insert(device.name(), LocalInfo::new(alias, mount_point))
|
||||
{
|
||||
Some(old) => info!("Value replaced. Old value: {:?}", old),
|
||||
None => info!("New value inserted."),
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for PhysicalDrivePartition {
|
||||
|
@ -141,7 +157,7 @@ pub fn select_physical_storage(
|
|||
) -> Result<(String, PhysicalDrivePartition)> {
|
||||
trace!("select_physical_storage");
|
||||
// get disk info fron sysinfo
|
||||
let mut sys_disks =
|
||||
let sys_disks =
|
||||
sysinfo::System::new_with_specifics(sysinfo::RefreshKind::new().with_disks_list());
|
||||
trace!("refresh");
|
||||
// sys_disks.refresh_disks_list();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue