better treatment when working in symlinked paths
This commit is contained in:
parent
fe2c39e74c
commit
c8f70b03e8
2 changed files with 23 additions and 10 deletions
6
flake.lock
generated
6
flake.lock
generated
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1715774670,
|
"lastModified": 1727089097,
|
||||||
"narHash": "sha256-iJYnKMtLi5u6hZhJm94cRNSDG5Rz6ZzIkGbhPFtDRm0=",
|
"narHash": "sha256-ZMHMThPsthhUREwDebXw7GX45bJnBCVbfnH1g5iuSPc=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "b3fcfcfabd01b947a1e4f36622bbffa3985bdac6",
|
"rev": "568bfef547c14ca438c56a0bece08b8bb2b71a9c",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
27
src/main.rs
27
src/main.rs
|
@ -4,14 +4,24 @@ mod args;
|
||||||
use crate::args::Cli;
|
use crate::args::Cli;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::path;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
use std::env;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
// FIXME: use abs path api once stable, see https://github.com/rust-lang/rust/issues/92750
|
|
||||||
let mut directory =
|
let mut directory = path::absolute(cli.search_root.clone()).expect("Encountered error while parsing search root");
|
||||||
fs::canonicalize(cli.search_root).expect("Encountered error while parsing search root");
|
|
||||||
|
// resolution of the . path is always canonical, which is an issue here. This tests whether pwd ebv var contains a valid path, and if so prefers that.
|
||||||
|
let pwd = env::var("PWD");
|
||||||
|
let canonical_dir = fs::canonicalize(cli.search_root.clone()).expect("Encountered error while parsing search root");
|
||||||
|
let test_dir = pwd.as_deref().map(path::Path::new);
|
||||||
|
if cli.search_root == path::Path::new(".") && test_dir.clone().map(fs::canonicalize).is_ok_and(|r| r.is_ok_and(|p| canonical_dir == p)) {
|
||||||
|
directory = test_dir.map(PathBuf::from).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
loop {
|
loop {
|
||||||
|
@ -21,10 +31,13 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
for file in files {
|
for file in files {
|
||||||
let file_name = format!(
|
let file_name = file
|
||||||
"{}",
|
.as_ref()
|
||||||
file.as_ref().unwrap().file_name().into_string().unwrap()
|
.unwrap()
|
||||||
);
|
.file_name()
|
||||||
|
.into_string()
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
if (!cli.exact && file_name.contains(&cli.search.to_string()))
|
if (!cli.exact && file_name.contains(&cli.search.to_string()))
|
||||||
|| file_name == cli.search.to_string()
|
|| file_name == cli.search.to_string()
|
||||||
|
|
Loading…
Add table
Reference in a new issue