Skip to content

Commit 3d8fd71

Browse files
author
Jay Conrod
committed
zip: add CheckFiles, CheckDir, and CheckZip
These functions may be used to check whether the files in an abstract list, a directory, or a module zip file satisfy the module name and size constraints listed in the package documentation. Each function returns a CheckedFiles record that lists valid, omitted, and invalid files, as well as any size-related error for the whole set of files. The omitted and invalid lists have an error for each file, saying why it was omitted or invalid. Create, CreateFromDir, and Unzip are now implemented using these functions (or common code). They now return errors based on CheckedFiles errors. Most error messages won't change, but if multiple files are invalid, they will be all be listed instead of just the first one. Fixes golang/go#36058 Updates golang/go#39091 Change-Id: I9d4d508288bbd821f93423e712232d8a68356529 Reviewed-on: https://go-review.googlesource.com/c/mod/+/235597 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent c0d644d commit 3d8fd71

14 files changed

+870
-244
lines changed

zip/testdata/check_dir/empty.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- want --
2+
valid:
3+
4+
omitted:
5+
6+
invalid:

zip/testdata/check_dir/various.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- want --
2+
valid:
3+
$work/valid.go
4+
5+
omitted:
6+
$work/.hg_archival.txt: file is inserted by 'hg archive' and is always omitted
7+
$work/.git: directory is a version control repository
8+
$work/sub: directory is in another module
9+
$work/vendor/x/y: file is in vendor directory
10+
11+
invalid:
12+
$work/GO.MOD: go.mod files must have lowercase names
13+
$work/invalid.go': malformed file path "invalid.go'": invalid char '\''
14+
-- valid.go --
15+
-- GO.MOD --
16+
-- invalid.go' --
17+
-- vendor/x/y --
18+
-- sub/go.mod --
19+
-- .hg_archival.txt --
20+
-- .git/x --

zip/testdata/check_files/empty.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- want --
2+
valid:
3+
4+
omitted:
5+
6+
invalid:

zip/testdata/check_files/various.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- want --
2+
valid:
3+
valid.go
4+
5+
omitted:
6+
vendor/x/y: file is in vendor directory
7+
sub/go.mod: file is in another module
8+
.hg_archival.txt: file is inserted by 'hg archive' and is always omitted
9+
10+
invalid:
11+
not/../clean: file path is not clean
12+
GO.MOD: go.mod files must have lowercase names
13+
invalid.go': malformed file path "invalid.go'": invalid char '\''
14+
valid.go: multiple entries for file "valid.go"
15+
-- valid.go --
16+
-- not/../clean --
17+
-- GO.MOD --
18+
-- invalid.go' --
19+
-- vendor/x/y --
20+
-- sub/go.mod --
21+
-- .hg_archival.txt --
22+
-- valid.go --
23+
duplicate
24+
-- valid.go --
25+
another duplicate

zip/testdata/check_zip/empty.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
path=example.com/empty
2+
version=v1.0.0
3+
-- want --
4+
valid:
5+
6+
omitted:
7+
8+
invalid:

zip/testdata/check_zip/various.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
path=example.com/various
2+
version=v1.0.0
3+
-- want --
4+
valid:
5+
example.com/[email protected]/valid.go
6+
7+
omitted:
8+
9+
invalid:
10+
noprefix: path does not have prefix "example.com/[email protected]/"
11+
example.com/[email protected]/not/../clean: file path is not clean
12+
example.com/[email protected]/invalid.go': malformed file path "invalid.go'": invalid char '\''
13+
example.com/[email protected]/GO.MOD: go.mod files must have lowercase names
14+
example.com/[email protected]/valid.go: multiple entries for file "valid.go"
15+
-- noprefix --
16+
-- example.com/[email protected]/valid.go --
17+
-- example.com/[email protected]/not/../clean --
18+
-- example.com/[email protected]/invalid.go' --
19+
-- example.com/[email protected]/GO.MOD --
20+
-- example.com/[email protected]/valid.go --
21+
duplicate
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
path=example.com/m
22
version=v1.0.0
3-
wantErr=found file named GO.MOD, want all lower-case go.mod
3+
wantErr=GO.MOD: go.mod files must have lowercase names
44
-- GO.MOD --
55
module example.com/m
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
path=example.com/m
22
version=v1.0.0
3-
wantErr=found file named GO.MOD, want all lower-case go.mod
3+
wantErr=GO.MOD: go.mod files must have lowercase names
44
-- GO.MOD --
55
module example.com/m

zip/testdata/unzip/bad_gomod_case.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
path=example.com/m
22
version=v1.0.0
3-
wantErr=found file named example.com/[email protected]/GO.MOD, want all lower-case go.mod
3+
wantErr=go.mod files must have lowercase names
44
-- example.com/[email protected]/GO.MOD --
55
module example.com/m

zip/testdata/unzip/bad_submodule.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
path=example.com/m
22
version=v1.0.0
3-
wantErr=found go.mod file not in module root directory
3+
wantErr=go.mod file not in module root directory
44
-- example.com/[email protected]/go.mod --
55
module example.com/m
66

zip/testdata/unzip/cap_go_mod_not_submodule.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
path=example.com/m
22
version=v1.0.0
3-
wantErr=found go.mod file not in module root directory
3+
wantErr=go.mod file not in module root directory
44
-- example.com/[email protected]/a.go --
55
package a
66
-- example.com/[email protected]/b/GO.MOD --

zip/testdata/unzip/prefix_only.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
path=example.com/m
22
version=v1.0.0
3-
wantErr=unexpected file name example.com/[email protected]
3+
wantErr=example.com/[email protected]: path does not have prefix "example.com/[email protected]/"
44
-- example.com/[email protected] --
55
-- example.com/[email protected]/go.mod --
66
module example.com/m

0 commit comments

Comments
 (0)