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:
parent
320eaf4b0c
commit
4d94207488
1 changed files with 8 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue