diff options
author | koverstreet <kent.overstreet@gmail.com> | 2024-06-10 18:30:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-10 18:30:00 -0400 |
commit | e743caf71cb1e4e78c80e991139a6f18c6f5ed0c (patch) | |
tree | a2ce7512175341fda216258a21f99a264aad8d74 | |
parent | c2354f0326f5ad7fa5fd4d759f923f43daf9890a (diff) | |
parent | c20f323fdb672592b7bb5103f44cd7b7ec492025 (diff) |
Merge pull request #294 from tmuehlbacher/subvol-fix
fix(subvol): canonicalize requires path to exist
-rw-r--r-- | src/commands/subvolume.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/commands/subvolume.rs b/src/commands/subvolume.rs index 64743115..b059ff4a 100644 --- a/src/commands/subvolume.rs +++ b/src/commands/subvolume.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{env, path::PathBuf}; use bch_bindgen::c::BCH_SUBVOL_SNAPSHOT_RO; use clap::{Parser, Subcommand}; @@ -42,9 +42,13 @@ pub fn subvolume(argv: Vec<String>) -> i32 { match cli.subcommands { Subcommands::Create { targets } => { for target in targets { - let target = target - .canonicalize() - .expect("unable to canonicalize a target path"); + let target = if target.is_absolute() { + target + } else { + env::current_dir() + .map(|p| p.join(target)) + .expect("unable to get current directory") + }; if let Some(dirname) = target.parent() { let fs = unsafe { BcachefsHandle::open(dirname) }; @@ -56,7 +60,7 @@ pub fn subvolume(argv: Vec<String>) -> i32 { Subcommands::Delete { target } => { let target = target .canonicalize() - .expect("unable to canonicalize a target path"); + .expect("subvolume path does not exist or can not be canonicalized"); if let Some(dirname) = target.parent() { let fs = unsafe { BcachefsHandle::open(dirname) }; |