summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyohei Uto <im@kyoheiu.dev>2024-03-03 11:56:14 +0900
committerKyohei Uto <im@kyoheiu.dev>2024-03-03 11:56:14 +0900
commita2f6e1c467d93bc7207836800eaa8401ed4d834b (patch)
tree341958f226ec934ffdb52f6a5dcb82e94c629269
parent1b7a4ca832900c664ee553d91cb9dda89b539372 (diff)
Remove canonicalize for OS compartibilityfix/symlink
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml1
-rw-r--r--src/run.rs24
3 files changed, 25 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b08d2aa..552a402 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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"
diff --git a/Cargo.toml b/Cargo.toml
index 3ccaf0f..87d9034 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"] }
diff --git a/src/run.rs b/src/run.rs
index 05c2ff1..67261b9 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -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;