Commit 365a1877 authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go/internal/modcmd: check for errors in Download

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: default avatarRuss Cox <rsc@golang.org>
parent cdbd4d49
...@@ -128,6 +128,16 @@ func runDownload(cmd *base.Command, args []string) { ...@@ -128,6 +128,16 @@ func runDownload(cmd *base.Command, args []string) {
base.Fatalf("%v", err) base.Fatalf("%v", err)
} }
os.Stdout.Write(append(b, '\n')) 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()
}
} }
...@@ -8,6 +8,12 @@ exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info ...@@ -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.mod
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip 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 # download -json with version should print JSON
go mod download -json 'rsc.io/quote@<=v1.5.0' go mod download -json 'rsc.io/quote@<=v1.5.0'
stdout '^\t"Path": "rsc.io/quote"' stdout '^\t"Path": "rsc.io/quote"'
...@@ -42,6 +48,21 @@ exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod ...@@ -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/cache/download/rsc.io/quote/@v/v1.5.2.zip
exists $GOPATH/pkg/mod/rsc.io/quote@v1.5.2 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 go mod download -json
stdout '^\t"Path": "rsc.io/quote"' stdout '^\t"Path": "rsc.io/quote"'
stdout '^\t"Version": "v1.5.2"' stdout '^\t"Version": "v1.5.2"'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment