2016-06-28 15:24:25 +08:00
|
|
|
package directory
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/containers/image/types"
|
2016-07-12 02:44:11 +08:00
|
|
|
"github.com/docker/docker/reference"
|
2016-06-28 15:24:25 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type dirImageSource struct {
|
|
|
|
|
dir string
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-04 17:32:26 +08:00
|
|
|
// NewImageSource returns an ImageSource reading from an existing directory.
|
|
|
|
|
func NewImageSource(dir string) types.ImageSource {
|
2016-06-28 15:24:25 +08:00
|
|
|
return &dirImageSource{dir}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-12 02:44:11 +08:00
|
|
|
// IntendedDockerReference returns the Docker reference for this image, _as specified by the user_
|
|
|
|
|
// (not as the image itself, or its underlying storage, claims). Should be fully expanded, i.e. !reference.IsNameOnly.
|
|
|
|
|
// This can be used e.g. to determine which public keys are trusted for this image.
|
|
|
|
|
// May be nil if unknown.
|
|
|
|
|
func (s *dirImageSource) IntendedDockerReference() reference.Named {
|
|
|
|
|
return nil
|
2016-06-28 15:24:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// it's up to the caller to determine the MIME type of the returned manifest's bytes
|
|
|
|
|
func (s *dirImageSource) GetManifest(_ []string) ([]byte, string, error) {
|
|
|
|
|
m, err := ioutil.ReadFile(manifestPath(s.dir))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, "", err
|
|
|
|
|
}
|
|
|
|
|
return m, "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *dirImageSource) GetBlob(digest string) (io.ReadCloser, int64, error) {
|
|
|
|
|
r, err := os.Open(layerPath(s.dir, digest))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, 0, nil
|
|
|
|
|
}
|
|
|
|
|
fi, err := os.Stat(layerPath(s.dir, digest))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, 0, nil
|
|
|
|
|
}
|
|
|
|
|
return r, fi.Size(), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *dirImageSource) GetSignatures() ([][]byte, error) {
|
|
|
|
|
signatures := [][]byte{}
|
|
|
|
|
for i := 0; ; i++ {
|
|
|
|
|
signature, err := ioutil.ReadFile(signaturePath(s.dir, i))
|
|
|
|
|
if err != nil {
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
signatures = append(signatures, signature)
|
|
|
|
|
}
|
|
|
|
|
return signatures, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *dirImageSource) Delete() error {
|
|
|
|
|
return fmt.Errorf("directory#dirImageSource.Delete() not implmented")
|
|
|
|
|
}
|