store: update Image to include size

Alongside File, Name, and Mime type, each Image in the store will
contain the image size. This will default to 0 unless the compose's
status is FINISHED. Then, it  will be the length in bytes of the file.
This commit is contained in:
Jacob Kozol 2019-10-27 17:48:52 +01:00 committed by Tom Gundersen
parent 320eaf4b0c
commit 4d94207488

View file

@ -55,6 +55,7 @@ type Image struct {
File *os.File
Name string
Mime string
Size int64
}
type NotFoundError struct {
@ -448,10 +449,17 @@ func (s *Store) GetImage(composeID uuid.UUID) (*Image, error) {
case *target.LocalTargetOptions:
file, err := os.Open(options.Location + "/" + name)
if err == nil {
fileStat, err := file.Stat()
if err != nil {
return nil, &NotFoundError{"image info could not be found"}
}
size := fileStat.Size()
return &Image{
File: file,
Name: name,
Mime: mime,
Size: size,
}, nil
}
}