mirror of
https://github.com/qwjyh/xdbm
synced 2025-07-12 17:49:19 +09:00
online storage & fix directory parent find & and so on
This commit is contained in:
parent
83233740aa
commit
b54cbf00f0
5 changed files with 99 additions and 36 deletions
|
@ -2,13 +2,7 @@
|
|||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::{self, write},
|
||||
hash::Hash,
|
||||
path,
|
||||
rc::Rc,
|
||||
};
|
||||
use std::{collections::HashMap, fmt, path};
|
||||
|
||||
use crate::devices;
|
||||
|
||||
|
@ -31,7 +25,7 @@ impl Directory {
|
|||
/// - `notes`: supplimental notes.
|
||||
fn new(
|
||||
name: String,
|
||||
parent: String, // todo implement serialize
|
||||
parent: String,
|
||||
relative_path: path::PathBuf,
|
||||
notes: String,
|
||||
local_info: HashMap<String, LocalInfo>,
|
||||
|
@ -58,7 +52,11 @@ impl Directory {
|
|||
.filter_map(|(k, v)| {
|
||||
let diff = pathdiff::diff_paths(&path, v.mount_path(&device, &storages).unwrap())?;
|
||||
trace!("Pathdiff: {:?}", diff);
|
||||
Some((k, diff))
|
||||
if diff.components().any(|c| c == path::Component::ParentDir) {
|
||||
None
|
||||
} else {
|
||||
Some((k, diff))
|
||||
}
|
||||
})
|
||||
.min_by_key(|(_k, v)| {
|
||||
let diff_paths: Vec<path::Component<'_>> = v.components().collect();
|
||||
|
@ -106,6 +104,16 @@ 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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue