From 7367e545f2122007765508579d3f9efddd5c9079 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sun, 18 Nov 2018 22:54:34 +0100 Subject: [PATCH] Revert "wrealpath: Fail for file/something" Apparently macOS realpath is broken. This reverts commit ca1c499069fb8ef236c9254e4b91950a1a791b4d. --- src/wutil.cpp | 6 +++--- tests/realpath.err | 1 - tests/realpath.in | 3 --- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/wutil.cpp b/src/wutil.cpp index 69df651b0..f58eb529a 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -414,9 +414,9 @@ maybe_t wrealpath(const wcstring &pathname) { // If there is no "/", this is a file in $PWD, so give the realpath to that. narrow_res = realpath(".", tmpbuf); } else { - // Be sure to include the last "/" to have the penultimate component considered a directory. - // Otherwise "file/something" succeeds. - narrow_res = realpath(narrow_path.substr(0, pathsep_idx + 1).c_str(), tmpbuf); + errno = 0; + // Only call realpath() on the portion up to the last component. + narrow_res = realpath(narrow_path.substr(0, pathsep_idx).c_str(), tmpbuf); } if (!narrow_res) return none(); diff --git a/tests/realpath.err b/tests/realpath.err index 5d953d562..65dd8672e 100644 --- a/tests/realpath.err +++ b/tests/realpath.err @@ -1,3 +1,2 @@ builtin realpath: /this/better/be/an/invalid/path: No such file or directory builtin realpath: .: No such file or directory -builtin realpath: realpath.out/..: Not a directory diff --git a/tests/realpath.in b/tests/realpath.in index 6e7d383ff..fba895f15 100644 --- a/tests/realpath.in +++ b/tests/realpath.in @@ -80,7 +80,4 @@ else echo "unexpected pwd-resolved-to-itself failure: $real_path != $PWD" >&2 end -# Confirm that the penultimate component still needs to be a directory: -builtin realpath realpath.out/.. - exit 0