@@ -13,6 +13,7 @@ import (
1313 "path"
1414 "path/filepath"
1515 "strings"
16+ "time"
1617
1718 "github.com/cheggaaa/pb/v3"
1819 "github.com/containerd/continuity/fs"
@@ -44,7 +45,7 @@ const (
4445type Result struct {
4546 Status Status
4647 CachePath string // "/Users/foo/Library/Caches/lima/download/by-url-sha256/<SHA256_OF_URL>/data"
47- LastModified string
48+ LastModified time. Time
4849 ContentType string
4950 ValidatedDigest bool
5051}
@@ -134,6 +135,24 @@ func readFile(path string) string {
134135 return string (b )
135136}
136137
138+ func readTime (path string ) time.Time {
139+ if path == "" {
140+ return time.Time {}
141+ }
142+ if _ , err := os .Stat (path ); err != nil {
143+ return time.Time {}
144+ }
145+ b , err := os .ReadFile (path )
146+ if err != nil {
147+ return time.Time {}
148+ }
149+ t , err := time .Parse (http .TimeFormat , string (b ))
150+ if err != nil {
151+ return time.Time {}
152+ }
153+ return t
154+ }
155+
137156// Download downloads the remote resource into the local path.
138157//
139158// Download caches the remote resource if WithCache or WithCacheDir option is specified.
@@ -228,7 +247,7 @@ func Download(ctx context.Context, local, remote string, opts ...Opt) (*Result,
228247 res := & Result {
229248 Status : StatusUsedCache ,
230249 CachePath : shadData ,
231- LastModified : readFile (shadTime ),
250+ LastModified : readTime (shadTime ),
232251 ContentType : readFile (shadType ),
233252 ValidatedDigest : o .expectedDigest != "" ,
234253 }
@@ -259,7 +278,7 @@ func Download(ctx context.Context, local, remote string, opts ...Opt) (*Result,
259278 res := & Result {
260279 Status : StatusDownloaded ,
261280 CachePath : shadData ,
262- LastModified : readFile (shadTime ),
281+ LastModified : readTime (shadTime ),
263282 ContentType : readFile (shadType ),
264283 ValidatedDigest : o .expectedDigest != "" ,
265284 }
@@ -309,7 +328,7 @@ func Cached(remote string, opts ...Opt) (*Result, error) {
309328 res := & Result {
310329 Status : StatusUsedCache ,
311330 CachePath : shadData ,
312- LastModified : readFile (shadTime ),
331+ LastModified : readTime (shadTime ),
313332 ContentType : readFile (shadType ),
314333 ValidatedDigest : o .expectedDigest != "" ,
315334 }
0 commit comments