@@ -85,11 +85,11 @@ func (db *SmartDB) writeZipFile(zipFile *zip.File) error {
8585 return err
8686}
8787
88- func (db * SmartDB ) populateFromZip () error {
88+ func (db * SmartDB ) populateFromZip () ( * time. Time , error ) {
8989 err := os .MkdirAll (db .cachePath (), 0744 )
9090
9191 if err != nil {
92- return err
92+ return nil , err
9393 }
9494
9595 zdb := & ZipDB {
@@ -102,12 +102,12 @@ func (db *SmartDB) populateFromZip() error {
102102 body , err := zdb .fetchZip ()
103103
104104 if err != nil {
105- return err
105+ return nil , err
106106 }
107107
108108 zipReader , err := zip .NewReader (bytes .NewReader (body ), int64 (len (body )))
109109 if err != nil {
110- return fmt .Errorf ("could not read OSV database archive: %w" , err )
110+ return nil , fmt .Errorf ("could not read OSV database archive: %w" , err )
111111 }
112112
113113 // Read each file from the archive and write it to the db directory
@@ -123,11 +123,17 @@ func (db *SmartDB) populateFromZip() error {
123123 err = db .writeZipFile (zipFile )
124124
125125 if err != nil {
126- return err
126+ return nil , err
127127 }
128128 }
129129
130- return nil
130+ tim , err := time .Parse (http .TimeFormat , zdb .UpdatedAt )
131+
132+ if err != nil {
133+ return nil , err
134+ }
135+
136+ return & tim , nil
131137}
132138
133139type modifiedIDRow struct {
@@ -262,18 +268,17 @@ func (db *SmartDB) load() error {
262268
263269 // (re)initialize the database using the zip file
264270 if err != nil {
265- err = db .populateFromZip ()
271+ newLastModified , err : = db .populateFromZip ()
266272
267273 if err != nil {
268274 return err
269275 }
270276
271- // update the last modified time to now
272- lastModified = time .Now ()
277+ lastModified = * newLastModified
273278 }
274279
275280 // update any advisories that have changed since the last modified timestamp
276- err = db .updateModifiedAdvisories (lastModified )
281+ err = db .updateModifiedAdvisories (time . Now () )
277282 if err != nil {
278283 return err
279284 }
0 commit comments