Source file src/cmd/go/internal/robustio/robustio.go
1 // Copyright 2019 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package robustio wraps I/O functions that are prone to failure on Windows, 6 // transparently retrying errors up to an arbitrary timeout. 7 // 8 // Errors are classified heuristically and retries are bounded, so the functions 9 // in this package do not completely eliminate spurious errors. However, they do 10 // significantly reduce the rate of failure in practice. 11 // 12 // If so, the error will likely wrap one of: 13 // The functions in this package do not completely eliminate spurious errors, 14 // but substantially reduce their rate of occurrence in practice. 15 package robustio 16 17 // Rename is like os.Rename, but on Windows retries errors that may occur if the 18 // file is concurrently read or overwritten. 19 // 20 // (See golang.org/issue/31247 and golang.org/issue/32188.) 21 func Rename(oldpath, newpath string) error { 22 return rename(oldpath, newpath) 23 } 24 25 // ReadFile is like os.ReadFile, but on Windows retries errors that may 26 // occur if the file is concurrently replaced. 27 // 28 // (See golang.org/issue/31247 and golang.org/issue/32188.) 29 func ReadFile(filename string) ([]byte, error) { 30 return readFile(filename) 31 } 32 33 // RemoveAll is like os.RemoveAll, but on Windows retries errors that may occur 34 // if an executable file in the directory has recently been executed. 35 // 36 // (See golang.org/issue/19491.) 37 func RemoveAll(path string) error { 38 return removeAll(path) 39 } 40 41 // IsEphemeralError reports whether err is one of the errors that the functions 42 // in this package attempt to mitigate. 43 // 44 // Errors considered ephemeral include: 45 // - syscall.ERROR_ACCESS_DENIED 46 // - syscall.ERROR_FILE_NOT_FOUND 47 // - internal/syscall/windows.ERROR_SHARING_VIOLATION 48 // 49 // This set may be expanded in the future; programs must not rely on the 50 // non-ephemerality of any given error. 51 func IsEphemeralError(err error) bool { 52 return isEphemeralError(err) 53 } 54