Skip to content

Commit 365a187

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent cdbd4d4 commit 365a187

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/cmd/go/internal/modcmd/download.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ func runDownload(cmd *base.Command, args []string) {
128128
base.Fatalf("%v", err)
129129
}
130130
os.Stdout.Write(append(b, '\n'))
131+
if m.Error != "" {
132+
base.SetExitStatus(1)
133+
}
134+
}
135+
} else {
136+
for _, m := range mods {
137+
if m.Error != "" {
138+
base.Errorf("%s@%s: %s\n", m.Path, m.Version, m.Error)
139+
}
131140
}
141+
base.ExitIfErrors()
132142
}
133143
}

src/cmd/go/testdata/script/mod_download.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info
88
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod
99
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip
1010

11+
# download of an invalid path should report the error
12+
! go mod download this.domain.is.invalid/[email protected]
13+
stderr 'this.domain.is.invalid'
14+
! go mod download -json this.domain.is.invalid/[email protected]
15+
stdout '"Error": ".*this.domain.is.invalid.*"'
16+
1117
# download -json with version should print JSON
1218
go mod download -json 'rsc.io/quote@<=v1.5.0'
1319
stdout '^\t"Path": "rsc.io/quote"'
@@ -42,6 +48,21 @@ exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
4248
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
4349
exists $GOPATH/pkg/mod/rsc.io/[email protected]
4450

51+
# download repopulates deleted files and directories independently.
52+
rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info
53+
go mod download
54+
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.info
55+
rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
56+
go mod download
57+
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.mod
58+
rm $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
59+
go mod download
60+
exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.2.zip
61+
rm -r $GOPATH/pkg/mod/rsc.io/[email protected]
62+
go mod download
63+
exists $GOPATH/pkg/mod/rsc.io/[email protected]
64+
65+
# download reports the locations of downloaded files
4566
go mod download -json
4667
stdout '^\t"Path": "rsc.io/quote"'
4768
stdout '^\t"Version": "v1.5.2"'

0 commit comments

Comments
 (0)