fix: windows path canonicalization

use these
- expand_tilde
- dunce::canonicalize
This commit is contained in:
qwjyh 2024-03-15 20:54:26 +09:00
parent 26fbea5d3a
commit 4f0d725b52
4 changed files with 29 additions and 6 deletions

7
Cargo.lock generated
View file

@ -331,6 +331,12 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "dunce"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b"
[[package]]
name = "dyn-clone"
version = "1.0.17"
@ -1433,6 +1439,7 @@ dependencies = [
"clap",
"clap-verbosity-flag",
"dirs",
"dunce",
"env_logger",
"git2",
"inquire",

View file

@ -15,6 +15,7 @@ env_logger = "0.10.0"
inquire = "0.6.2"
git2 = "0.17.2"
dirs = "5.0"
dunce = "1.0.4"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
byte-unit = "4.0.19"

View file

@ -1,17 +1,19 @@
use std::{
collections::HashMap,
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 unicode_width::UnicodeWidthStr;
use crate::{
add_and_commit,
backups::{
self, Backup, BackupCommand, BackupCommandExt, BackupTarget, Backups, ExternallyInvoked,
self, Backup, BackupCommand, BackupCommandExt, BackupLog, BackupResult, BackupTarget,
Backups, ExternallyInvoked,
},
cmd_args::BackupAddCommands,
devices::{self, Device},
@ -28,6 +30,10 @@ pub(crate) fn cmd_backup_add(
config_dir: &PathBuf,
storages: &Storages,
) -> 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 new_backup = new_backup(name, src, dest, cmd, &device, storages)?;
let new_backup_name = new_backup.name().clone();

View file

@ -7,6 +7,7 @@ use std::{
use anyhow::{anyhow, Context, Result};
use byte_unit::Byte;
use dunce::canonicalize;
use git2::Repository;
use inquire::{Confirm, CustomType, Text};
use unicode_width::{self, UnicodeWidthStr};
@ -21,6 +22,7 @@ use crate::{
physical_drive_partition::{self, PhysicalDrivePartition},
Storage, StorageExt, StorageType, Storages,
},
util,
};
pub(crate) fn cmd_storage_add(
@ -46,7 +48,11 @@ pub(crate) fn cmd_storage_add(
let storage = if use_sysinfo {
physical_drive_partition::select_physical_storage(name, device)?
} 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);
Storage::PhysicalStorage(storage)
@ -70,7 +76,8 @@ pub(crate) fn cmd_storage_add(
}
trace!("SubDirectory arguments: path: {:?}", path);
// Nightly feature std::path::absolute
let path = path.canonicalize()?;
trace!("Canonicalize path: {:?}", path);
let path = canonicalize(util::expand_tilde(path))?;
trace!("canonicalized: path: {:?}", path);
let storage = directory::Directory::try_from_device_path(
@ -91,6 +98,8 @@ pub(crate) fn cmd_storage_add(
name
));
}
trace!("Canonicalize path: {:?}", path);
let path = canonicalize(util::expand_tilde(path))?;
let storage = storages::online_storage::OnlineStorage::new(
name, provider, capacity, alias, path, &device,
);