golang.org/x/build@v0.0.0-20240506185731-218518f32b70/maintner/internal/robustio/robustio.go (about) 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 // 16 // This package is a reduced copy of cmd/go/internal/robustio. 17 // TODO(#36163): Switch maintner to use file-locking instead of 18 // (or in addition to) atomic renames. 19 package robustio 20 21 // Rename is like os.Rename, but on Windows retries errors that may occur if the 22 // file is concurrently read or overwritten. 23 // 24 // (See golang.org/issue/31247 and golang.org/issue/32188.) 25 func Rename(oldpath, newpath string) error { 26 return rename(oldpath, newpath) 27 } 28 29 // ReadFile is like os.ReadFile, but on Windows retries errors that may 30 // occur if the file is concurrently replaced. 31 // 32 // (See golang.org/issue/31247 and golang.org/issue/32188.) 33 func ReadFile(filename string) ([]byte, error) { 34 return readFile(filename) 35 } 36 37 // RemoveAll is like os.RemoveAll, but on Windows retries errors that may occur 38 // if an executable file in the directory has recently been executed. 39 // 40 // (See golang.org/issue/19491.) 41 func RemoveAll(path string) error { 42 return removeAll(path) 43 } 44 45 // IsEphemeralError reports whether err is one of the errors that the functions 46 // in this package attempt to mitigate. 47 // 48 // Errors considered ephemeral include: 49 // - syscall.ERROR_ACCESS_DENIED 50 // - syscall.ERROR_FILE_NOT_FOUND 51 // - internal/syscall/windows.ERROR_SHARING_VIOLATION 52 // 53 // This set may be expanded in the future; programs must not rely on the 54 // non-ephemerality of any given error. 55 func IsEphemeralError(err error) bool { 56 return isEphemeralError(err) 57 }