@@ -102,7 +102,9 @@ func New(config *config.UpdaterConfig) (*Updater, error) {
102102// Downloads, verifies, and loads metadata for the top-level roles in the
103103// specified order (root -> timestamp -> snapshot -> targets) implementing
104104// all the checks required in the TUF client workflow.
105- // A Refresh() can be done only once during the lifetime of an Updater.
105+ // Refresh() can be called multiple times during the lifetime of an Updater
106+ // to ensure that the metadata is up-to-date. Each call will reload the
107+ // timestamp, snapshot, and targets metadata while preserving the root metadata.
106108// If Refresh() has not been explicitly called before the first
107109// GetTargetInfo() call, it will be done implicitly at that time.
108110// The metadata for delegated roles is not updated by Refresh():
@@ -135,6 +137,9 @@ func (update *Updater) onlineRefresh() error {
135137 if err != nil {
136138 return err
137139 }
140+ // Remove the targets entry to allow re-loading during multiple Refresh() calls
141+ // while still preventing redundant loads during GetTargetInfo()
142+ delete (update .trusted .Targets , metadata .TARGETS )
138143 _ , err = update .loadTargets (metadata .TARGETS , metadata .ROOT )
139144 if err != nil {
140145 return err
@@ -313,12 +318,16 @@ func (update *Updater) loadTimestamp() error {
313318 if errors .Is (err , & metadata.ErrRepository {}) {
314319 // local timestamp is not valid, proceed downloading from remote; note that this error type includes several other subset errors
315320 log .Info ("Local timestamp is not valid" )
321+ } else if errors .Is (err , & metadata.ErrEqualVersionNumber {}) {
322+ // local timestamp version equals current trusted version, proceed to check remote for updates
323+ log .Info ("Local timestamp version equals trusted version" )
316324 } else {
317325 // another error
318326 return err
319327 }
328+ } else {
329+ log .Info ("Local timestamp is valid" )
320330 }
321- log .Info ("Local timestamp is valid" )
322331 // all okay, local timestamp exists and it is valid, nevertheless proceed with downloading from remote
323332 }
324333 // load from remote (whether local load succeeded or not)
@@ -368,12 +377,12 @@ func (update *Updater) loadSnapshot() error {
368377 }
369378 } else {
370379 // this means snapshot verification/loading succeeded
371- log .Info ("Local snapshot is valid: not downloading new one " )
372- return nil
380+ log .Info ("Local snapshot is valid" )
381+ // Continue to check remote for potential updates
373382 }
374383 }
375- // local snapshot does not exist or is invalid, update from remote
376- log .Info ("Failed to load local snapshot" )
384+ // check remote for updates (whether local load succeeded or not)
385+ log .Info ("Checking remote for snapshot updates " )
377386 if update .trusted .Timestamp == nil {
378387 return fmt .Errorf ("trusted timestamp not set" )
379388 }
@@ -422,7 +431,7 @@ func (update *Updater) loadTargets(roleName, parentName string) (*metadata.Metad
422431 log .Info ("Local role does not exist" , "role" , roleName )
423432 } else {
424433 // successfully read a local targets metadata, so let's try to verify and load it to the trusted metadata set
425- delegatedTargets , err := update .trusted .UpdateDelegatedTargets (data , roleName , parentName )
434+ _ , err := update .trusted .UpdateDelegatedTargets (data , roleName , parentName )
426435 if err != nil {
427436 // this means targets verification/loading failed
428437 if errors .Is (err , & metadata.ErrRepository {}) {
@@ -434,12 +443,12 @@ func (update *Updater) loadTargets(roleName, parentName string) (*metadata.Metad
434443 }
435444 } else {
436445 // this means targets verification/loading succeeded
437- log .Info ("Local role is valid: not downloading new one " , "role" , roleName )
438- return delegatedTargets , nil
446+ log .Info ("Local role is valid" , "role" , roleName )
447+ // Continue to check remote for potential updates
439448 }
440449 }
441- // local "roleName" does not exist or is invalid, update from remote
442- log .Info ("Failed to load local role" , "role" , roleName )
450+ // check remote for updates (whether local load succeeded or not)
451+ log .Info ("Checking remote for role updates " , "role" , roleName )
443452 if update .trusted .Snapshot == nil {
444453 return nil , fmt .Errorf ("trusted snapshot not set" )
445454 }
0 commit comments