]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: move fetch to import.go
authorJay Conrod <jayconrod@google.com>
Thu, 15 Oct 2020 19:53:09 +0000 (15:53 -0400)
committerJay Conrod <jayconrod@google.com>
Fri, 16 Oct 2020 14:02:35 +0000 (14:02 +0000)
From a comment in CL 262341. It makes more sense in import.go than in
mvs.go.

Change-Id: If4dfa1091077e110c5041bc849d99bc0be2bd8e2
Reviewed-on: https://go-review.googlesource.com/c/go/+/262780
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/modload/import.go
src/cmd/go/internal/modload/mvs.go

index 76fe6745d93ffa50aa3875e714c05b09328cf41c..8641cfec0824f8f48d680c92b4f69cd19dc9b1ad 100644 (file)
@@ -451,3 +451,42 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile
 
        return dir, res.haveGoFiles, res.err
 }
+
+// fetch downloads the given module (or its replacement)
+// and returns its location.
+//
+// The isLocal return value reports whether the replacement,
+// if any, is local to the filesystem.
+func fetch(ctx context.Context, mod module.Version) (dir string, isLocal bool, err error) {
+       if mod == Target {
+               return ModRoot(), true, nil
+       }
+       if r := Replacement(mod); r.Path != "" {
+               if r.Version == "" {
+                       dir = r.Path
+                       if !filepath.IsAbs(dir) {
+                               dir = filepath.Join(ModRoot(), dir)
+                       }
+                       // Ensure that the replacement directory actually exists:
+                       // dirInModule does not report errors for missing modules,
+                       // so if we don't report the error now, later failures will be
+                       // very mysterious.
+                       if _, err := os.Stat(dir); err != nil {
+                               if os.IsNotExist(err) {
+                                       // Semantically the module version itself “exists” — we just don't
+                                       // have its source code. Remove the equivalence to os.ErrNotExist,
+                                       // and make the message more concise while we're at it.
+                                       err = fmt.Errorf("replacement directory %s does not exist", r.Path)
+                               } else {
+                                       err = fmt.Errorf("replacement directory %s: %w", r.Path, err)
+                               }
+                               return dir, true, module.VersionError(mod, err)
+                       }
+                       return dir, true, nil
+               }
+               mod = r
+       }
+
+       dir, err = modfetch.Download(ctx, mod)
+       return dir, false, err
+}
index 65329524f9658dd0818a83aa51a1a06d8124f69c..76a1d8a12ae350d9bee39361a0452a3e8808e9f3 100644 (file)
@@ -7,9 +7,6 @@ package modload
 import (
        "context"
        "errors"
-       "fmt"
-       "os"
-       "path/filepath"
        "sort"
 
        "cmd/go/internal/modfetch"
@@ -125,42 +122,3 @@ func (*mvsReqs) next(m module.Version) (module.Version, error) {
        }
        return module.Version{Path: m.Path, Version: "none"}, nil
 }
-
-// fetch downloads the given module (or its replacement)
-// and returns its location.
-//
-// The isLocal return value reports whether the replacement,
-// if any, is local to the filesystem.
-func fetch(ctx context.Context, mod module.Version) (dir string, isLocal bool, err error) {
-       if mod == Target {
-               return ModRoot(), true, nil
-       }
-       if r := Replacement(mod); r.Path != "" {
-               if r.Version == "" {
-                       dir = r.Path
-                       if !filepath.IsAbs(dir) {
-                               dir = filepath.Join(ModRoot(), dir)
-                       }
-                       // Ensure that the replacement directory actually exists:
-                       // dirInModule does not report errors for missing modules,
-                       // so if we don't report the error now, later failures will be
-                       // very mysterious.
-                       if _, err := os.Stat(dir); err != nil {
-                               if os.IsNotExist(err) {
-                                       // Semantically the module version itself “exists” — we just don't
-                                       // have its source code. Remove the equivalence to os.ErrNotExist,
-                                       // and make the message more concise while we're at it.
-                                       err = fmt.Errorf("replacement directory %s does not exist", r.Path)
-                               } else {
-                                       err = fmt.Errorf("replacement directory %s: %w", r.Path, err)
-                               }
-                               return dir, true, module.VersionError(mod, err)
-                       }
-                       return dir, true, nil
-               }
-               mod = r
-       }
-
-       dir, err = modfetch.Download(ctx, mod)
-       return dir, false, err
-}