mirror of
https://github.com/qwjyh/xdbm
synced 2025-06-26 17:59:20 +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
|
@ -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();
|
||||
|
@ -124,7 +130,7 @@ mod test {
|
|||
.join("mnt")
|
||||
.join("different"),
|
||||
&device,
|
||||
));
|
||||
));
|
||||
let mut storages = Storages::new();
|
||||
storages.add(storage1)?;
|
||||
storages.add(storage2)?;
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue