diff options
author | Kyohei Uto <im@kyoheiu.dev> | 2024-03-03 11:56:14 +0900 |
---|---|---|
committer | Kyohei Uto <im@kyoheiu.dev> | 2024-03-03 11:56:14 +0900 |
commit | a2f6e1c467d93bc7207836800eaa8401ed4d834b (patch) | |
tree | 341958f226ec934ffdb52f6a5dcb82e94c629269 | |
parent | 1b7a4ca832900c664ee553d91cb9dda89b539372 (diff) |
Remove canonicalize for OS compartibilityfix/symlink
-rw-r--r-- | Cargo.lock | 10 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/run.rs | 24 |
3 files changed, 25 insertions, 10 deletions
@@ -346,6 +346,7 @@ dependencies = [ "lzma-rs", "natord", "nix", + "normpath", "rayon", "serde", "serde_yaml", @@ -642,6 +643,15 @@ dependencies = [ ] [[package]] +name = "normpath" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5831952a9476f2fed74b77d74182fa5ddc4d21c72ec45a333b250e3ed0272804" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -35,6 +35,7 @@ lzma-rs = "0.3.0" zstd = "0.12.4" unicode-width = "0.1.10" git2 = {version = "0.18.0", default-features = false } +normpath = "1.2.0" [dev-dependencies] bwrap = { version = "1.3.0", features = ["use_std"] } @@ -13,6 +13,7 @@ use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifier use crossterm::execute; use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen}; use log::{error, info}; +use normpath::PathExt; use std::env; use std::io::{stdout, Write}; use std::panic; @@ -118,12 +119,14 @@ pub fn run(arg: PathBuf, log: bool) -> Result<(), FxError> { let mut state = State::new(&session_path)?; state.trash_dir = trash_dir_path; state.lwd_file = lwd_file_path; - state.current_dir = if cfg!(not(windows)) { - // If executed this on windows, "//?" will be inserted at the beginning of the path. - arg.canonicalize()? - } else { - arg - }; + let normalized_arg = arg.normalize(); + if normalized_arg.is_err() { + return Err(FxError::Arg(format!( + "Invalid path: {}\n`fx -h` shows help.", + &arg.display() + ))); + } + state.current_dir = normalized_arg.unwrap().into_path_buf(); state.jumplist.add(&state.current_dir); state.is_ro = match has_write_permission(&state.current_dir) { Ok(b) => !b, @@ -2240,12 +2243,13 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { } else if commands.len() == 2 && command == "cd" { if let Ok(target) = std::path::Path::new(commands[1]) - .canonicalize() + .normalize() { if target.exists() { - if let Err(e) = - state.chdir(&target, Move::Jump) - { + if let Err(e) = state.chdir( + &target.into_path_buf(), + Move::Jump, + ) { print_warning(e, state.layout.y); } break 'command; |