mirror of
https://github.com/golang/go
synced 2024-11-17 12:54:47 -07:00
cmd/go/internal/modfetch: retry rename for unzipped directories
No test because this is difficult to reproduce, and such a test would always be flaky. Updates #36568 Change-Id: I8170410a7729ecc6f90baf8005444d6b1241185e Reviewed-on: https://go-review.googlesource.com/c/go/+/220978 Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
ee46f135a9
commit
bb644e7982
@ -22,6 +22,7 @@ import (
|
||||
"cmd/go/internal/lockedfile"
|
||||
"cmd/go/internal/par"
|
||||
"cmd/go/internal/renameio"
|
||||
"cmd/go/internal/robustio"
|
||||
|
||||
"golang.org/x/mod/module"
|
||||
"golang.org/x/mod/sumdb/dirhash"
|
||||
@ -101,6 +102,9 @@ func download(mod module.Version, dir string) (err error) {
|
||||
// signal that it has been extracted successfully, and if someone deletes
|
||||
// the entire directory (e.g. as an attempt to prune out file corruption)
|
||||
// the module cache will still be left in a recoverable state.
|
||||
// We retry failed renames using robustio.Rename on Windows. Programs that
|
||||
// open files in the temporary directory (antivirus, search indexers, etc.)
|
||||
// can cause os.Rename to fail with ERROR_ACCESS_DENIED.
|
||||
if err := os.MkdirAll(parentDir, 0777); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -119,7 +123,7 @@ func download(mod module.Version, dir string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Rename(tmpDir, dir); err != nil {
|
||||
if err := robustio.Rename(tmpDir, dir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user