Skip to content

Commit 99dcb01

Browse files
author
zhouhao
committed
Modify the automatic determination of the Config type
Signed-off-by: zhouhao <[email protected]>
1 parent 0a1e5dc commit 99dcb01

File tree

1 file changed

+2
-39
lines changed

1 file changed

+2
-39
lines changed

image/autodetect.go

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
package image
1616

1717
import (
18-
"encoding/json"
1918
"io"
2019
"io/ioutil"
2120
"net/http"
22-
"os"
2321

2422
"github.com/opencontainers/image-spec/schema"
2523
"github.com/pkg/errors"
@@ -67,46 +65,11 @@ func Autodetect(path string) (string, error) {
6765
return TypeImage, nil
6866

6967
case "text/plain; charset=utf-8":
70-
// might be a JSON file, will be handled below
68+
// might be a JSON file
69+
return schema.Autodect(f)
7170

7271
default:
7372
return "", errors.New("unknown file type")
7473
}
7574

76-
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
77-
return "", errors.Wrap(err, "unable to seek")
78-
}
79-
80-
header := struct {
81-
SchemaVersion int `json:"schemaVersion"`
82-
MediaType string `json:"mediaType"`
83-
Config interface{} `json:"config"`
84-
}{}
85-
86-
if err := json.NewDecoder(f).Decode(&header); err != nil {
87-
if _, errSeek := f.Seek(0, os.SEEK_SET); errSeek != nil {
88-
return "", errors.Wrap(err, "unable to seek")
89-
}
90-
91-
e := errors.Wrap(
92-
schema.WrapSyntaxError(f, err),
93-
"unable to parse JSON",
94-
)
95-
96-
return "", e
97-
}
98-
99-
switch {
100-
case header.MediaType == string(schema.MediaTypeManifest):
101-
return TypeManifest, nil
102-
103-
case header.MediaType == string(schema.MediaTypeManifestList):
104-
return TypeManifestList, nil
105-
106-
case header.MediaType == "" && header.SchemaVersion == 0 && header.Config != nil:
107-
// config files don't have mediaType/schemaVersion header
108-
return TypeConfig, nil
109-
}
110-
111-
return "", errors.New("unknown media type")
11275
}

0 commit comments

Comments
 (0)