mirror of
https://github.com/qwjyh/xdbm
synced 2024-11-22 06:40:12 +09:00
fix: storage bind (add writing and commiting)
This commit is contained in:
parent
d7e7665739
commit
78b2d956a7
2 changed files with 77 additions and 64 deletions
27
src/main.rs
27
src/main.rs
|
@ -17,6 +17,7 @@ use git2::{Commit, Oid, Repository};
|
|||
use inquire::{validator::Validation, Text};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_yaml;
|
||||
use std::fmt::format;
|
||||
use std::{env, io::BufReader, path::Path};
|
||||
use std::{
|
||||
ffi::OsString,
|
||||
|
@ -76,6 +77,7 @@ enum StorageCommands {
|
|||
/// List all storages.
|
||||
List {},
|
||||
/// Add new device-specific name to existing storage.
|
||||
/// For physical disk, the name is taken from system info automatically.
|
||||
Bind { storage: String },
|
||||
}
|
||||
|
||||
|
@ -171,13 +173,14 @@ fn main() -> Result<()> {
|
|||
println!("Device added");
|
||||
full_status(&repo)?;
|
||||
}
|
||||
Commands::Storage(storage) => match storage.command {
|
||||
StorageCommands::Add { storage_type } => {
|
||||
trace!("Storage Add {:?}", storage_type);
|
||||
Commands::Storage(storage) => {
|
||||
let repo = Repository::open(&config_dir).context(
|
||||
"Repository doesn't exist. Please run init to initialize the repository.",
|
||||
)?;
|
||||
trace!("repo state: {:?}", repo.state());
|
||||
match storage.command {
|
||||
StorageCommands::Add { storage_type } => {
|
||||
trace!("Storage Add {:?}", storage_type);
|
||||
match storage_type {
|
||||
StorageType::Physical => {
|
||||
// Get storages
|
||||
|
@ -222,7 +225,7 @@ fn main() -> Result<()> {
|
|||
} => {
|
||||
// get storages
|
||||
let mut storages: Vec<Storage> = get_storages(&config_dir)?;
|
||||
{
|
||||
let commit_comment = {
|
||||
// find matching storage
|
||||
let storage = &mut storages
|
||||
.iter_mut()
|
||||
|
@ -232,14 +235,26 @@ fn main() -> Result<()> {
|
|||
let mut sysinfo = sysinfo::System::new_all();
|
||||
sysinfo.refresh_disks();
|
||||
let disk = select_sysinfo_disk(&sysinfo)?;
|
||||
let system_name = disk.name().to_str().context("Failed to convert disk name to valid string")?;
|
||||
// add to storages
|
||||
storage.add_alias(disk, &config_dir)?;
|
||||
trace!("storage: {}", storage);
|
||||
}
|
||||
format!("{} to {}", system_name, storage.name())
|
||||
};
|
||||
trace!("bound new system name to the storage");
|
||||
trace!("storages: {:#?}", storages);
|
||||
|
||||
write_storages(&config_dir, storages)?;
|
||||
// commit
|
||||
add_and_commit(
|
||||
&repo,
|
||||
&Path::new(STORAGESFILE),
|
||||
&format!("Bound new storage name to physical drive ({})", commit_comment),
|
||||
)?;
|
||||
println!("Bound new storage name to physical drive ({})", commit_comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Commands::Path {} => {
|
||||
println!("{}", &config_dir.display());
|
||||
}
|
||||
|
|
|
@ -60,11 +60,10 @@ impl PhysicalDrivePartition {
|
|||
let aliases = &mut self.system_names;
|
||||
trace!("aliases: {:?}", aliases);
|
||||
match aliases.insert(device.name(), alias) {
|
||||
Some(v) => trace!("old val is: {}", v),
|
||||
None => trace!("inserted new val"),
|
||||
Some(v) => println!("Value updated. old val is: {}", v),
|
||||
None => println!("inserted new val"),
|
||||
};
|
||||
trace!("aliases: {:?}", aliases);
|
||||
// self.system_names = aliases;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +72,6 @@ impl StorageExt for PhysicalDrivePartition {
|
|||
fn name(&self) -> &String {
|
||||
&self.name
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl fmt::Display for PhysicalDrivePartition {
|
||||
|
|
Loading…
Reference in a new issue