Skip to content

Commit

Permalink
autodetect.go:Increase the judgment criteria for the ImageLayout file…
Browse files Browse the repository at this point in the history
… type

Signed-off-by: zhouhao <[email protected]>
  • Loading branch information
zhouhao committed Nov 30, 2016
1 parent 27d5fd6 commit cb75f90
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions image/autodetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ package image

import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"

"github.com/opencontainers/image-spec/schema"
"github.com/pkg/errors"
Expand All @@ -34,6 +36,13 @@ const (
TypeConfig = "config"
)

// Layoutfile realize the image files that are included in the image layout type
var Layoutfile = []string{
"blobs",
"oci-layout",
"refs",
}

// Autodetect detects the validation type for the given path
// or an error if the validation type could not be resolved.
func Autodetect(path string) (string, error) {
Expand All @@ -43,6 +52,25 @@ func Autodetect(path string) (string, error) {
}

if fi.IsDir() {
for _, file := range Layoutfile {
mpath := filepath.Join(path, file)
mfi, erro := os.Stat(mpath)
if os.IsNotExist(erro) {
return "", fmt.Errorf("%s not exit in ImageLayout", file)
}

if file == Layoutfile[0] || file == Layoutfile[2] {
if !(mfi.IsDir()) {
return "", fmt.Errorf("%s must be a directory", file)
}
}

if file == Layoutfile[1] {
if _, err := os.Open(mpath); err != nil {
return "", errors.Wrap(err, "oci-layout must be a file")
}
}
}
return TypeImageLayout, nil
}

Expand Down

0 comments on commit cb75f90

Please sign in to comment.