@@ -13,6 +13,7 @@ import (
13
13
"path"
14
14
"path/filepath"
15
15
"strings"
16
+ "time"
16
17
17
18
"github.com/cheggaaa/pb/v3"
18
19
"github.com/containerd/continuity/fs"
@@ -44,7 +45,7 @@ const (
44
45
type Result struct {
45
46
Status Status
46
47
CachePath string // "/Users/foo/Library/Caches/lima/download/by-url-sha256/<SHA256_OF_URL>/data"
47
- LastModified string
48
+ LastModified time. Time
48
49
ContentType string
49
50
ValidatedDigest bool
50
51
}
@@ -134,6 +135,24 @@ func readFile(path string) string {
134
135
return string (b )
135
136
}
136
137
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
+
137
156
// Download downloads the remote resource into the local path.
138
157
//
139
158
// 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,
228
247
res := & Result {
229
248
Status : StatusUsedCache ,
230
249
CachePath : shadData ,
231
- LastModified : readFile (shadTime ),
250
+ LastModified : readTime (shadTime ),
232
251
ContentType : readFile (shadType ),
233
252
ValidatedDigest : o .expectedDigest != "" ,
234
253
}
@@ -259,7 +278,7 @@ func Download(ctx context.Context, local, remote string, opts ...Opt) (*Result,
259
278
res := & Result {
260
279
Status : StatusDownloaded ,
261
280
CachePath : shadData ,
262
- LastModified : readFile (shadTime ),
281
+ LastModified : readTime (shadTime ),
263
282
ContentType : readFile (shadType ),
264
283
ValidatedDigest : o .expectedDigest != "" ,
265
284
}
@@ -309,7 +328,7 @@ func Cached(remote string, opts ...Opt) (*Result, error) {
309
328
res := & Result {
310
329
Status : StatusUsedCache ,
311
330
CachePath : shadData ,
312
- LastModified : readFile (shadTime ),
331
+ LastModified : readTime (shadTime ),
313
332
ContentType : readFile (shadType ),
314
333
ValidatedDigest : o .expectedDigest != "" ,
315
334
}
0 commit comments