]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfetch: retry rename for unzipped directories
authorJay Conrod <jayconrod@google.com>
Tue, 25 Feb 2020 19:54:18 +0000 (14:54 -0500)
committerJay Conrod <jayconrod@google.com>
Wed, 26 Feb 2020 15:38:51 +0000 (15:38 +0000)
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>
src/cmd/go/internal/modfetch/fetch.go

index 54fbd92b43ec146987910e51ae5db66672abc508..e2c463a6855b5d44cc2e306e3d686cb6ca7ce228 100644 (file)
@@ -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
        }