mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
os.Stat: returned error on nonexistent path did not satisfy IsNotExist
Add direct test for the problem to make the fix commit clearer. Noticed while implementing MkdirTemp on mac; the upstream tests for MkdirTemp fail without this.
This commit is contained in:
@@ -4,6 +4,7 @@ package os_test
|
||||
|
||||
import (
|
||||
. "os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -31,6 +32,16 @@ func TestMkdir(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatBadDir(t *testing.T) {
|
||||
dir := TempDir()
|
||||
badDir := filepath.Join(dir, "not-exist/really-not-exist")
|
||||
_, err := Stat(badDir)
|
||||
// TODO: PathError moved to io/fs in go 1.16; fix next line once we drop go 1.15 support.
|
||||
if pe, ok := err.(*PathError); !ok || !IsNotExist(err) || pe.Path != badDir {
|
||||
t.Errorf("Mkdir error = %#v; want PathError for path %q satisifying IsNotExist", err, badDir)
|
||||
}
|
||||
}
|
||||
|
||||
func writeFile(t *testing.T, fname string, flag int, text string) string {
|
||||
f, err := OpenFile(fname, flag, 0666)
|
||||
if err != nil {
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ func (f *File) Sync() error {
|
||||
func statNolog(name string) (FileInfo, error) {
|
||||
var fs fileStat
|
||||
err := ignoringEINTR(func() error {
|
||||
return syscall.Stat(name, &fs.sys)
|
||||
return handleSyscallError(syscall.Stat(name, &fs.sys))
|
||||
})
|
||||
if err != nil {
|
||||
return nil, &PathError{Op: "stat", Path: name, Err: err}
|
||||
@@ -32,7 +32,7 @@ func statNolog(name string) (FileInfo, error) {
|
||||
func lstatNolog(name string) (FileInfo, error) {
|
||||
var fs fileStat
|
||||
err := ignoringEINTR(func() error {
|
||||
return syscall.Lstat(name, &fs.sys)
|
||||
return handleSyscallError(syscall.Lstat(name, &fs.sys))
|
||||
})
|
||||
if err != nil {
|
||||
return nil, &PathError{Op: "lstat", Path: name, Err: err}
|
||||
|
||||
Reference in New Issue
Block a user