diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-09-06 18:12:46 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-09-06 18:12:46 +0000 |
commit | aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13 (patch) | |
tree | 7e63b06d1eec92beec6997c9d3ab47a5d6a835be /libgo/go/os/removeall_noat.go | |
parent | 920ea3b8ba3164b61ac9490dfdfceb6936eda6dd (diff) | |
download | gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.gz |
libgo: update to Go 1.13beta1 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/193497
From-SVN: r275473
Diffstat (limited to 'libgo/go/os/removeall_noat.go')
-rw-r--r-- | libgo/go/os/removeall_noat.go | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/libgo/go/os/removeall_noat.go b/libgo/go/os/removeall_noat.go index 7d9f73e7123..cf26bdb2161 100644 --- a/libgo/go/os/removeall_noat.go +++ b/libgo/go/os/removeall_noat.go @@ -56,8 +56,30 @@ func removeAll(path string) error { return err } - const request = 1024 - names, err1 := fd.Readdirnames(request) + const reqSize = 1024 + var names []string + var readErr error + + for { + numErr := 0 + names, readErr = fd.Readdirnames(reqSize) + + for _, name := range names { + err1 := RemoveAll(path + string(PathSeparator) + name) + if err == nil { + err = err1 + } + if err1 != nil { + numErr++ + } + } + + // If we can delete any entry, break to start new iteration. + // Otherwise, we discard current names, get next entries and try deleting them. + if numErr != reqSize { + break + } + } // Removing files from the directory may have caused // the OS to reshuffle it. Simply calling Readdirnames @@ -66,19 +88,12 @@ func removeAll(path string) error { // directory. See issue 20841. fd.Close() - for _, name := range names { - err1 := RemoveAll(path + string(PathSeparator) + name) - if err == nil { - err = err1 - } - } - - if err1 == io.EOF { + if readErr == io.EOF { break } // If Readdirnames returned an error, use it. if err == nil { - err = err1 + err = readErr } if len(names) == 0 { break @@ -88,7 +103,7 @@ func removeAll(path string) error { // got fewer than request names from Readdirnames, try // simply removing the directory now. If that // succeeds, we are done. - if len(names) < request { + if len(names) < reqSize { err1 := Remove(path) if err1 == nil || IsNotExist(err1) { return nil @@ -109,6 +124,7 @@ func removeAll(path string) error { // Remove directory. err1 := Remove(path) + err1 = removeAllTestHook(err1) if err1 == nil || IsNotExist(err1) { return nil } |