all: move from os.IsFoo to errors.Is(err, ErrFoo)
Этот коммит содержится в:
		
							родитель
							
								
									edbbca5614
								
							
						
					
					
						коммит
						a2704f1435
					
				
					 9 изменённых файлов: 27 добавлений и 13 удалений
				
			
		|  | @ -14,6 +14,7 @@ import ( | |||
| 	"fmt" | ||||
| 	"go/types" | ||||
| 	"hash/crc32" | ||||
| 	"io/fs" | ||||
| 	"math/bits" | ||||
| 	"os" | ||||
| 	"os/exec" | ||||
|  | @ -147,7 +148,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil | |||
| 		libcDependencies = append(libcDependencies, libcJob) | ||||
| 	case "wasi-libc": | ||||
| 		path := filepath.Join(root, "lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a") | ||||
| 		if _, err := os.Stat(path); os.IsNotExist(err) { | ||||
| 		if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) { | ||||
| 			return errors.New("could not find wasi-libc, perhaps you need to run `make wasi-libc`?") | ||||
| 		} | ||||
| 		libcDependencies = append(libcDependencies, dummyCompileJob(path)) | ||||
|  |  | |||
|  | @ -10,6 +10,7 @@ import ( | |||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"io/fs" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"sort" | ||||
|  | @ -107,11 +108,11 @@ func compileAndCacheCFile(abspath, tmpdir string, cflags []string, thinlto bool, | |||
| 		if err == nil { | ||||
| 			if _, err := os.Stat(outpath); err == nil { | ||||
| 				return outpath, nil | ||||
| 			} else if !os.IsNotExist(err) { | ||||
| 			} else if !errors.Is(err, fs.ErrNotExist) { | ||||
| 				return "", err | ||||
| 			} | ||||
| 		} | ||||
| 	} else if !os.IsNotExist(err) { | ||||
| 	} else if !errors.Is(err, fs.ErrNotExist) { | ||||
| 		// expected either nil or IsNotExist | ||||
| 		return "", err | ||||
| 	} | ||||
|  |  | |||
|  | @ -1,6 +1,8 @@ | |||
| package builder | ||||
| 
 | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"io/fs" | ||||
| 	"io/ioutil" | ||||
| 	"os" | ||||
| 	"os/exec" | ||||
|  | @ -17,13 +19,13 @@ import ( | |||
| func getClangHeaderPath(TINYGOROOT string) string { | ||||
| 	// Check whether we're running from the source directory. | ||||
| 	path := filepath.Join(TINYGOROOT, "llvm-project", "clang", "lib", "Headers") | ||||
| 	if _, err := os.Stat(path); !os.IsNotExist(err) { | ||||
| 	if _, err := os.Stat(path); !errors.Is(err, fs.ErrNotExist) { | ||||
| 		return path | ||||
| 	} | ||||
| 
 | ||||
| 	// Check whether we're running from the installation directory. | ||||
| 	path = filepath.Join(TINYGOROOT, "lib", "clang", "include") | ||||
| 	if _, err := os.Stat(path); !os.IsNotExist(err) { | ||||
| 	if _, err := os.Stat(path); !errors.Is(err, fs.ErrNotExist) { | ||||
| 		return path | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,8 @@ | |||
| package builder | ||||
| 
 | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"io/fs" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"runtime" | ||||
|  | @ -109,10 +111,10 @@ func (l *Library) load(config *compileopts.Config, tmpdir string) (job *compileJ | |||
| 			err = os.Rename(temporaryHeaderPath, headerPath) | ||||
| 			if err != nil { | ||||
| 				switch { | ||||
| 				case os.IsExist(err): | ||||
| 				case errors.Is(err, fs.ErrExist): | ||||
| 					// Another invocation of TinyGo also seems to have already created the headers. | ||||
| 
 | ||||
| 				case runtime.GOOS == "windows" && os.IsPermission(err): | ||||
| 				case runtime.GOOS == "windows" && errors.Is(err, fs.ErrPermission): | ||||
| 					// On Windows, a rename with a destination directory that already | ||||
| 					// exists does not result in an IsExist error, but rather in an | ||||
| 					// access denied error. To be sure, check for this case by checking | ||||
|  |  | |||
|  | @ -6,6 +6,7 @@ import ( | |||
| 	"bytes" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"io/fs" | ||||
| 	"os" | ||||
| 	"os/exec" | ||||
| 	"os/user" | ||||
|  | @ -122,7 +123,7 @@ func findWasmOpt() string { | |||
| 		} | ||||
| 
 | ||||
| 		_, err := os.Stat(path) | ||||
| 		if err != nil && os.IsNotExist(err) { | ||||
| 		if err != nil && errors.Is(err, fs.ErrNotExist) { | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
|  |  | |||
|  | @ -17,6 +17,7 @@ import ( | |||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"io" | ||||
| 	"io/fs" | ||||
| 	"io/ioutil" | ||||
| 	"os" | ||||
| 	"os/exec" | ||||
|  | @ -122,13 +123,13 @@ func GetCachedGoroot(config *compileopts.Config) (string, error) { | |||
| 	// Rename the new merged gorooot into place. | ||||
| 	err = os.Rename(tmpgoroot, cachedgoroot) | ||||
| 	if err != nil { | ||||
| 		if os.IsExist(err) { | ||||
| 		if errors.Is(err, fs.ErrExist) { | ||||
| 			// Another invocation of TinyGo also seems to have created a GOROOT. | ||||
| 			// Use that one instead. Our new GOROOT will be automatically | ||||
| 			// deleted by the defer above. | ||||
| 			return cachedgoroot, nil | ||||
| 		} | ||||
| 		if runtime.GOOS == "windows" && os.IsPermission(err) { | ||||
| 		if runtime.GOOS == "windows" && errors.Is(err, fs.ErrPermission) { | ||||
| 			// On Windows, a rename with a destination directory that already | ||||
| 			// exists does not result in an IsExist error, but rather in an | ||||
| 			// access denied error. To be sure, check for this case by checking | ||||
|  |  | |||
|  | @ -10,8 +10,10 @@ package testing | |||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"errors" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"io/fs" | ||||
| 	"os" | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | @ -277,7 +279,7 @@ func (c *common) TempDir() string { | |||
| 		nonExistent = true | ||||
| 	} else { | ||||
| 		_, err := os.Stat(c.tempDir) | ||||
| 		nonExistent = os.IsNotExist(err) | ||||
| 		nonExistent = errors.Is(err, fs.ErrNotExist) | ||||
| 		if err != nil && !nonExistent { | ||||
| 			c.Fatalf("TempDir: %v", err) | ||||
| 		} | ||||
|  |  | |||
							
								
								
									
										4
									
								
								testdata/filesystem.go
									
										
									
									
										предоставленный
									
									
								
							
							
						
						
									
										4
									
								
								testdata/filesystem.go
									
										
									
									
										предоставленный
									
									
								
							|  | @ -1,13 +1,15 @@ | |||
| package main | ||||
| 
 | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"io" | ||||
| 	"io/fs" | ||||
| 	"os" | ||||
| ) | ||||
| 
 | ||||
| func main() { | ||||
| 	_, err := os.Open("non-exist") | ||||
| 	if !os.IsNotExist(err) { | ||||
| 	if !errors.Is(err, fs.ErrNotExist) { | ||||
| 		panic("should be non exist error") | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -3,8 +3,10 @@ package main | |||
| import ( | ||||
| 	"bufio" | ||||
| 	"encoding/xml" | ||||
| 	"errors" | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"io/fs" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"regexp" | ||||
|  | @ -1402,7 +1404,7 @@ __isr_vector: | |||
| } | ||||
| 
 | ||||
| func generate(indir, outdir, sourceURL, interruptSystem string) error { | ||||
| 	if _, err := os.Stat(indir); os.IsNotExist(err) { | ||||
| 	if _, err := os.Stat(indir); errors.Is(err, fs.ErrNotExist) { | ||||
| 		fmt.Fprintln(os.Stderr, "cannot find input directory:", indir) | ||||
| 		os.Exit(1) | ||||
| 	} | ||||
|  |  | |||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 Damian Gryski
						Damian Gryski