Repository: sharkdp/fd (language: rust)

Issue:
`--real-path`
The option `--absolute-path` creates "messy" results when used with relative dirs. As such I would propose another option similar to the bash command `realpath`.


Discussion / hints:
Thank you for the feedback. Could you please give a (reproducible) example and what you would expect?
Oh, you probably refer to something like this:
```
> fd mod .. -a
/home/shark/Dropbox/Informatik/rust/fd/src/../src/exec/mod.rs
/home/shark/Dropbox/Informatik/rust/fd/src/../src/fshelper/mod.rs
/home/shark/Dropbox/Informatik/rust/fd/src/../src/lscolors/mod.rs
/home/shark/Dropbox/Informatik/rust/fd/src/../tests/testenv/mod.rs
```

This actually seems like a bug. The paths should be normalized.

Fix patch:
diff --git a/src/main.rs b/src/main.rs
index d04173522..65815d065 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -73,7 +73,12 @@ fn main() {
     if matches.is_present("absolute-path") {
         dir_vec = dir_vec
             .iter()
-            .map(|path_buffer| fshelper::absolute_path(path_buffer).unwrap())
+            .map(|path_buffer| {
+                path_buffer
+                    .canonicalize()
+                    .and_then(|pb| fshelper::absolute_path(pb.as_path()))
+                    .unwrap()
+            })
             .collect();
     }
 


Test patch:
diff --git a/tests/tests.rs b/tests/tests.rs
index 692b07360..fc720806f 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -532,6 +532,26 @@ fn test_implicit_absolute_path() {
     );
 }
 
+/// Absolute paths should be normalized
+#[test]
+fn test_normalized_absolute_path() {
+    let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
+
+    te.assert_output_subdirectory(
+        "one",
+        &["--absolute-path", "foo", ".."],
+        &format!(
+            "{abs_path}/a.foo
+            {abs_path}/one/b.foo
+            {abs_path}/one/two/c.foo
+            {abs_path}/one/two/C.Foo2
+            {abs_path}/one/two/three/d.foo
+            {abs_path}/one/two/three/directory_foo",
+            abs_path = &abs_path
+        ),
+    );
+}
+
 /// File type filter (--type)
 #[test]
 fn test_type() {
@@ -653,10 +673,10 @@ fn test_extension() {
     te4.assert_output(&["--hidden", "--extension", ".hidden"], "test.hidden");
 }
 
-/// Symlinks misc
+/// Symlink as search directory
 #[test]
-fn test_symlink() {
-    let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
+fn test_symlink_as_root() {
+    let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
 
     // From: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html
     // The getcwd() function shall place an absolute pathname of the current working directory in
@@ -690,20 +710,29 @@ fn test_symlink() {
             dir = &parent_parent
         ),
     );
+}
+
+#[test]
+fn test_symlink_and_absolute_path() {
+    let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
 
     te.assert_output_subdirectory(
         "symlink",
         &["--absolute-path"],
         &format!(
-            "{abs_path}/{dir}/c.foo
-            {abs_path}/{dir}/C.Foo2
-            {abs_path}/{dir}/three
-            {abs_path}/{dir}/three/d.foo
-            {abs_path}/{dir}/three/directory_foo",
-            dir = if cfg!(windows) { "symlink" } else { "one/two" },
+            "{abs_path}/one/two/c.foo
+            {abs_path}/one/two/C.Foo2
+            {abs_path}/one/two/three
+            {abs_path}/one/two/three/d.foo
+            {abs_path}/one/two/three/directory_foo",
             abs_path = &abs_path
         ),
     );
+}
+
+#[test]
+fn test_symlink_as_absolute_root() {
+    let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
 
     te.assert_output(
         &["", &format!("{abs_path}/symlink", abs_path = abs_path)],
@@ -716,7 +745,11 @@ fn test_symlink() {
             abs_path = &abs_path
         ),
     );
+}
 
+#[test]
+fn test_symlink_and_full_path() {
+    let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
     let root = te.system_root();
     let prefix = escape(&root.to_string_lossy());
 
@@ -728,14 +761,19 @@ fn test_symlink() {
             &format!("^{prefix}.*three", prefix = prefix),
         ],
         &format!(
-            "{abs_path}/{dir}/three
-            {abs_path}/{dir}/three/d.foo
-            {abs_path}/{dir}/three/directory_foo",
-            dir = if cfg!(windows) { "symlink" } else { "one/two" },
+            "{abs_path}/one/two/three
+            {abs_path}/one/two/three/d.foo
+            {abs_path}/one/two/three/directory_foo",
             abs_path = &abs_path
         ),
     );
+}
 
+#[test]
+fn test_symlink_and_full_path_abs_path() {
+    let (te, abs_path) = get_test_env_with_abs_path(DEFAULT_DIRS, DEFAULT_FILES);
+    let root = te.system_root();
+    let prefix = escape(&root.to_string_lossy());
     te.assert_output(
         &[
             "--full-path",