]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modcmd: check for errors in Download
authorBryan C. Mills <bcmills@google.com>
Wed, 28 Nov 2018 16:28:47 +0000 (11:28 -0500)
committerBryan C. Mills <bcmills@google.com>
Thu, 29 Nov 2018 18:58:04 +0000 (18:58 +0000)
Also test that Download restores deleted files.

Updates #27783

Change-Id: If50074dbcffd74ff08fbaa9ad8c314cfdce0b02d
Reviewed-on: https://go-review.googlesource.com/c/151559
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/internal/modcmd/download.go
src/cmd/go/testdata/script/mod_download.txt

index 8678caea516735c46df3372bf380d3a1a0095207..bbaba444f507f64c5ca647f559894a08b10eae5d 100644 (file)
@@ -128,6 +128,16 @@ func runDownload(cmd *base.Command, args []string) {
                                base.Fatalf("%v", err)
                        }
                        os.Stdout.Write(append(b, '\n'))
+                       if m.Error != "" {
+                               base.SetExitStatus(1)
+                       }
+               }
+       } else {
+               for _, m := range mods {
+                       if m.Error != "" {
+                               base.Errorf("%s@%s: %s\n", m.Path, m.Version, m.Error)
+                       }
                }
+               base.ExitIfErrors()
        }
 }
index 6be6acb360c9f37a9ced0493f8e8b3d92ec19aaf..22f07c33c7565adf68afc02434b83fa801ecbe3c 100644 (file)
@@ -8,6 +8,12 @@ exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip
 
+# download of an invalid path should report the error
+! go mod download this.domain.is.invalid/somemodule@v1.0.0
+stderr 'this.domain.is.invalid'
+! go mod download -json this.domain.is.invalid/somemodule@v1.0.0
+stdout '"Error": ".*this.domain.is.invalid.*"'
+
 # download -json with version should print JSON
 go mod download -json 'rsc.io/quote@<=v1.5.0'
 stdout '^\t"Path": "rsc.io/quote"'
@@ -42,6 +48,21 @@ exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
 exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
 exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2
 
+# download repopulates deleted files and directories independently.
+rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info
+go mod download
+exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info
+rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
+go mod download
+exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
+rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
+go mod download
+exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
+rm -r $GOPATH/pkg/mod/rsc.io/quote@v1.5.2
+go mod download
+exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2
+
+# download reports the locations of downloaded files
 go mod download -json
 stdout '^\t"Path": "rsc.io/quote"'
 stdout '^\t"Version": "v1.5.2"'