]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: fix EvalSymlinks to return ENOTDIR on plan9
authorKir Kolyshkin <kolyshkin@gmail.com>
Wed, 3 Sep 2025 19:48:44 +0000 (12:48 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 17 Sep 2025 15:47:59 +0000 (08:47 -0700)
CL 155597 added a test to check EvalSymlinks returns ENOTDIR
for existing path which ends with a slash.

CL 404954 added a separate evalSymlinks implementation for plan9,
which has a kludge to ensure the ENOTDIR is returned in the above case.

Apparently the added kludge is not working now (and maybe never worked),
as seen in [1]:

=== RUN   TestIssue29372
    path_test.go:1730: test#0: want "not a directory", got "stat /tmp/TestIssue293724085649913/001/file.txt/: not a directory: '/tmp/TestIssue293724085649913/001/file.txt/'"
--- FAIL: TestIssue29372 (0.00s)

This happens because on plan9 errors are strings and they contain the
file name after the error text, and the check assumes the "not a
directory" text is at the end of the message.

The fix is to check whether the error is somewhere in the error text,
not ends with it (as it is done in other plan9 code, for example, see
checkErrMessageContent added in CL 163058).

This should fix the above test failure.

PS perhaps the kludge should be moved up the call chain to os.Stat/Lstat?

[1]: https://ci.chromium.org/ui/p/golang/builders/try/gotip-plan9-amd64/b8704772617873749345/test-results?q=ExactID%3Apath%2Ffilepath.TestIssue29372+VHash%3Aa63f5798e9f8f502
Change-Id: I6afb68be5f65a28929b2f717247ab34ff3b4a812
Reviewed-on: https://go-review.googlesource.com/c/go/+/700775
Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Richard Miller <millerresearch@gmail.com>
TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
src/path/filepath/symlink_plan9.go

index 820d150d976e192f57ebced74ddf9f08b0f2b657..b29abe1dfd4660afcf32a176bc3657715c69d0a7 100644 (file)
@@ -16,8 +16,8 @@ func evalSymlinks(path string) (string, error) {
                // Check validity of path
                _, err := os.Lstat(path)
                if err != nil {
-                       // Return the same error value as on other operating systems
-                       if strings.HasSuffix(err.Error(), "not a directory") {
+                       // Return the same error value as on other operating systems.
+                       if strings.Contains(err.Error(), "not a directory") {
                                err = syscall.ENOTDIR
                        }
                        return "", err