From 4d94207488d7405ba2eb1eea76b4d7e083e7f905 Mon Sep 17 00:00:00 2001 From: Jacob Kozol Date: Sun, 27 Oct 2019 17:48:52 +0100 Subject: [PATCH] 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. --- internal/store/store.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/store/store.go b/internal/store/store.go index ac210b224..99fb93b42 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -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 } }