diff options
author | Denis Isidoro <denisidoro@users.noreply.github.com> | 2020-03-11 20:26:00 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-11 20:26:00 -0300 |
commit | 770793317b8db05648bf3e79457fede0cf5540d4 (patch) | |
tree | 5ab383d2919d5433424e86aa94d27e1b4d2a3eff | |
parent | da8dd42269e6be679d2daa64d88e083de16c40eb (diff) |
Handle relative symlinks (#225)v2.0.4
Attempts to solve #224 and #223
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/cheat.rs | 2 | ||||
-rw-r--r-- | src/filesystem.rs | 12 |
4 files changed, 15 insertions, 5 deletions
@@ -89,7 +89,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "navi" -version = "2.0.3" +version = "2.0.4" dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "raw_tty 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1,6 +1,6 @@ [package] name = "navi" -version = "2.0.3" +version = "2.0.4" authors = ["Denis Isidoro <denis_isidoro@live.com>"] edition = "2018" @@ -12,4 +12,4 @@ structopt = "0.3" termion = "1.5.5" raw_tty = "0.1.0" lazy_static = "1.4.0" -terminal_size = "0.1.10"
\ No newline at end of file +terminal_size = "0.1.10" diff --git a/src/cheat.rs b/src/cheat.rs index b5de854..f670214 100644 --- a/src/cheat.rs +++ b/src/cheat.rs @@ -136,7 +136,7 @@ pub fn read_all(config: &Config, stdin: &mut std::process::ChildStdin) -> HashMa let current_exe = filesystem::exe_path_string(); let fallback = format!( - "{path}/cheats:{path}/../cheats:{path}/../libexec/cheats", + "{path}/cheats:{path}/../cheats:{path}/../../cheats:{path}/../libexec/cheats", path = current_exe ); let folders_str = config.path.as_ref().unwrap_or(&fallback); diff --git a/src/filesystem.rs b/src/filesystem.rs index afb0a59..19c7d01 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -14,7 +14,17 @@ where fn follow_symlink(pathbuf: PathBuf) -> PathBuf { let other = fs::read_link(pathbuf.clone()); match other { - Ok(o) => follow_symlink(o), + Ok(o) => { + let o_str = o.as_os_str().to_str().unwrap(); + if o_str.starts_with('.') { + let parent_str = pathbuf.parent().unwrap().as_os_str().to_str().unwrap(); + let path_str = format!("{}/{}", parent_str, o_str); + let p = PathBuf::from(path_str); + follow_symlink(p) + } else { + follow_symlink(o) + } + } Err(_) => pathbuf, } } |