Skip to content

Commit

Permalink
Remove canonicalize for OS compartibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoheiu committed Mar 3, 2024
1 parent 1b7a4ca commit a2f6e1c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
24 changes: 14 additions & 10 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a2f6e1c

Please sign in to comment.