mirror of
https://github.com/qwjyh/xdbm
synced 2024-11-22 06:40:12 +09:00
fix: windows path canonicalization
use these - expand_tilde - dunce::canonicalize
This commit is contained in:
parent
26fbea5d3a
commit
4f0d725b52
4 changed files with 29 additions and 6 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -331,6 +331,12 @@ version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dunce"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dyn-clone"
|
name = "dyn-clone"
|
||||||
version = "1.0.17"
|
version = "1.0.17"
|
||||||
|
@ -1433,6 +1439,7 @@ dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"clap-verbosity-flag",
|
"clap-verbosity-flag",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"dunce",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"git2",
|
"git2",
|
||||||
"inquire",
|
"inquire",
|
||||||
|
|
|
@ -15,6 +15,7 @@ env_logger = "0.10.0"
|
||||||
inquire = "0.6.2"
|
inquire = "0.6.2"
|
||||||
git2 = "0.17.2"
|
git2 = "0.17.2"
|
||||||
dirs = "5.0"
|
dirs = "5.0"
|
||||||
|
dunce = "1.0.4"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_yaml = "0.9"
|
serde_yaml = "0.9"
|
||||||
byte-unit = "4.0.19"
|
byte-unit = "4.0.19"
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
io::{self, stdout, Write},
|
io::{self, stdout, Write},
|
||||||
path::PathBuf,
|
path::{PathBuf, self},
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result, Ok};
|
||||||
|
use dunce::canonicalize;
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
add_and_commit,
|
add_and_commit,
|
||||||
backups::{
|
backups::{
|
||||||
self, Backup, BackupCommand, BackupCommandExt, BackupTarget, Backups, ExternallyInvoked,
|
self, Backup, BackupCommand, BackupCommandExt, BackupLog, BackupResult, BackupTarget,
|
||||||
|
Backups, ExternallyInvoked,
|
||||||
},
|
},
|
||||||
cmd_args::BackupAddCommands,
|
cmd_args::BackupAddCommands,
|
||||||
devices::{self, Device},
|
devices::{self, Device},
|
||||||
|
@ -28,6 +30,10 @@ pub(crate) fn cmd_backup_add(
|
||||||
config_dir: &PathBuf,
|
config_dir: &PathBuf,
|
||||||
storages: &Storages,
|
storages: &Storages,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
trace!("Canonicalize path: {:?}", src);
|
||||||
|
let src = canonicalize(util::expand_tilde(src)?)?;
|
||||||
|
trace!("Canonicalize path: {:?}", dest);
|
||||||
|
let dest = canonicalize(util::expand_tilde(dest)?)?;
|
||||||
let device = devices::get_device(&config_dir)?;
|
let device = devices::get_device(&config_dir)?;
|
||||||
let new_backup = new_backup(name, src, dest, cmd, &device, storages)?;
|
let new_backup = new_backup(name, src, dest, cmd, &device, storages)?;
|
||||||
let new_backup_name = new_backup.name().clone();
|
let new_backup_name = new_backup.name().clone();
|
||||||
|
|
|
@ -7,6 +7,7 @@ use std::{
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use byte_unit::Byte;
|
use byte_unit::Byte;
|
||||||
|
use dunce::canonicalize;
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use inquire::{Confirm, CustomType, Text};
|
use inquire::{Confirm, CustomType, Text};
|
||||||
use unicode_width::{self, UnicodeWidthStr};
|
use unicode_width::{self, UnicodeWidthStr};
|
||||||
|
@ -21,6 +22,7 @@ use crate::{
|
||||||
physical_drive_partition::{self, PhysicalDrivePartition},
|
physical_drive_partition::{self, PhysicalDrivePartition},
|
||||||
Storage, StorageExt, StorageType, Storages,
|
Storage, StorageExt, StorageType, Storages,
|
||||||
},
|
},
|
||||||
|
util,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn cmd_storage_add(
|
pub(crate) fn cmd_storage_add(
|
||||||
|
@ -46,7 +48,11 @@ pub(crate) fn cmd_storage_add(
|
||||||
let storage = if use_sysinfo {
|
let storage = if use_sysinfo {
|
||||||
physical_drive_partition::select_physical_storage(name, device)?
|
physical_drive_partition::select_physical_storage(name, device)?
|
||||||
} else {
|
} else {
|
||||||
manually_construct_physical_drive_partition(name, path.unwrap(), &device)?
|
manually_construct_physical_drive_partition(
|
||||||
|
name,
|
||||||
|
canonicalize(util::expand_tilde(path.unwrap()))?,
|
||||||
|
&device,
|
||||||
|
)?
|
||||||
};
|
};
|
||||||
println!("storage: {}: {:?}", storage.name(), storage);
|
println!("storage: {}: {:?}", storage.name(), storage);
|
||||||
Storage::PhysicalStorage(storage)
|
Storage::PhysicalStorage(storage)
|
||||||
|
@ -70,7 +76,8 @@ pub(crate) fn cmd_storage_add(
|
||||||
}
|
}
|
||||||
trace!("SubDirectory arguments: path: {:?}", path);
|
trace!("SubDirectory arguments: path: {:?}", path);
|
||||||
// Nightly feature std::path::absolute
|
// Nightly feature std::path::absolute
|
||||||
let path = path.canonicalize()?;
|
trace!("Canonicalize path: {:?}", path);
|
||||||
|
let path = canonicalize(util::expand_tilde(path))?;
|
||||||
trace!("canonicalized: path: {:?}", path);
|
trace!("canonicalized: path: {:?}", path);
|
||||||
|
|
||||||
let storage = directory::Directory::try_from_device_path(
|
let storage = directory::Directory::try_from_device_path(
|
||||||
|
@ -91,6 +98,8 @@ pub(crate) fn cmd_storage_add(
|
||||||
name
|
name
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
trace!("Canonicalize path: {:?}", path);
|
||||||
|
let path = canonicalize(util::expand_tilde(path))?;
|
||||||
let storage = storages::online_storage::OnlineStorage::new(
|
let storage = storages::online_storage::OnlineStorage::new(
|
||||||
name, provider, capacity, alias, path, &device,
|
name, provider, capacity, alias, path, &device,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue