Skip to content

Commit cc9d9cc

Browse files
author
zhouhao
committed
validate.go: Modify the output mode
Delete stdout and turn it into fmt. Because it was changed in both create and unpack. Keep the code uniform. Signed-off-by: zhouhao <[email protected]>
1 parent 5926358 commit cc9d9cc

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

cmd/oci-image-tool/validate.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package main
1616

1717
import (
1818
"fmt"
19-
"log"
2019
"os"
2120
"strings"
2221

@@ -37,9 +36,8 @@ var validateTypes = []string{
3736
}
3837

3938
type validateCmd struct {
40-
stdout *log.Logger
41-
typ string // the type to validate, can be empty string
42-
refs []string
39+
typ string // the type to validate, can be empty string
40+
refs []string
4341
}
4442

4543
var v validateCmd
@@ -94,17 +92,13 @@ func validatePath(name string) error {
9492
}
9593
}
9694

97-
if v.stdout == nil {
98-
v.stdout = log.New(os.Stdout, "oci-image-tool: ", 0)
99-
}
100-
10195
switch typ {
10296
case image.TypeImageLayout:
103-
return image.ValidateLayout(name, v.refs, v.stdout)
97+
return image.ValidateLayout(name, v.refs)
10498
case image.TypeImageZip:
105-
return image.ValidateZip(name, v.refs, v.stdout)
99+
return image.ValidateZip(name, v.refs)
106100
case image.TypeImage:
107-
return image.ValidateFile(name, v.refs, v.stdout)
101+
return image.ValidateFile(name, v.refs)
108102
}
109103

110104
if len(v.refs) != 0 {

image/image.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"encoding/json"
1919
"fmt"
2020
"io"
21-
"log"
2221
"os"
2322
"path/filepath"
2423
"strings"
@@ -29,42 +28,42 @@ import (
2928

3029
// ValidateLayout walks through the given file tree and validates the manifest
3130
// pointed to by the given refs or returns an error if the validation failed.
32-
func ValidateLayout(src string, refs []string, out *log.Logger) error {
33-
return validate(newPathWalker(src), refs, out)
31+
func ValidateLayout(src string, refs []string) error {
32+
return validate(newPathWalker(src), refs)
3433
}
3534

3635
// ValidateZip walks through the given file tree and validates the manifest
3736
// pointed to by the given refs or returns an error if the validation failed.
38-
func ValidateZip(src string, refs []string, out *log.Logger) error {
39-
return validate(newZipWalker(src), refs, out)
37+
func ValidateZip(src string, refs []string) error {
38+
return validate(newZipWalker(src), refs)
4039
}
4140

4241
// ValidateFile opens the tar file given by the filename, then calls ValidateReader
43-
func ValidateFile(tarFile string, refs []string, out *log.Logger) error {
42+
func ValidateFile(tarFile string, refs []string) error {
4443
f, err := os.Open(tarFile)
4544
if err != nil {
4645
return errors.Wrap(err, "unable to open file")
4746
}
4847
defer f.Close()
4948

50-
return Validate(f, refs, out)
49+
return Validate(f, refs)
5150
}
5251

5352
// Validate walks through a tar stream and validates the manifest.
5453
// * Check that all refs point to extant blobs
5554
// * Checks that all referred blobs are valid
5655
// * Checks that mime-types are correct
5756
// returns error on validation failure
58-
func Validate(r io.ReadSeeker, refs []string, out *log.Logger) error {
59-
return validate(newTarWalker(r), refs, out)
57+
func Validate(r io.ReadSeeker, refs []string) error {
58+
return validate(newTarWalker(r), refs)
6059
}
6160

6261
var validRefMediaTypes = []string{
6362
v1.MediaTypeImageManifest,
6463
v1.MediaTypeImageIndex,
6564
}
6665

67-
func validate(w walker, refs []string, out *log.Logger) error {
66+
func validate(w walker, refs []string) error {
6867
if err := layoutValidate(w); err != nil {
6968
return err
7069
}
@@ -77,7 +76,7 @@ func validate(w walker, refs []string, out *log.Logger) error {
7776
// TODO(runcom): ugly, we'll need a better way and library
7877
// to express log levels.
7978
// see https://github.com/opencontainers/image-spec/issues/288
80-
out.Print("WARNING: no descriptors found")
79+
fmt.Println("WARNING: no descriptors found")
8180
}
8281

8382
if len(refs) == 0 {
@@ -137,9 +136,7 @@ func validate(w walker, refs []string, out *log.Logger) error {
137136
}
138137
}
139138

140-
if out != nil {
141-
out.Printf("reference %q: OK", ref)
142-
}
139+
fmt.Printf("reference %q: OK\n", ref)
143140
}
144141

145142
return nil

image/image_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func TestImageLayout(t *testing.T) {
237237
t.Fatal(err)
238238
}
239239

240-
err = ValidateLayout(root, refTag, nil)
240+
err = ValidateLayout(root, refTag)
241241
if err != nil {
242242
t.Fatal(err)
243243
}

0 commit comments

Comments
 (0)