Simplify updateCache()
This commit is contained in:
parent
ea3625bcfd
commit
9c73ab3070
|
@ -98,17 +98,24 @@ func writeSource(f string, bin, sig []byte) (err error) {
|
||||||
return fSig.Commit()
|
return fSig.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (source *Source) updateCache(bin, sig []byte, now time.Time) {
|
func (source *Source) updateCache(bin, sig []byte, now time.Time) error {
|
||||||
f := source.cacheFile
|
f := source.cacheFile
|
||||||
var writeErr error // an error writing cache isn't fatal
|
// If the data and signature are unchanged, update the files timestamps only
|
||||||
if !bytes.Equal(source.bin, bin) {
|
if bytes.Equal(source.bin, bin) {
|
||||||
if writeErr = writeSource(f, bin, sig); writeErr != nil {
|
_ = os.Chtimes(f, now, now)
|
||||||
source.bin = bin
|
_ = os.Chtimes(f+".minisig", now, now)
|
||||||
return
|
return nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
os.Chtimes(f, now, now)
|
// Otherwise, write the new data and signature
|
||||||
source.bin = bin
|
if err := writeSource(f, bin, sig); err != nil {
|
||||||
|
dlog.Warnf("Source [%s] failed to update cache file [%s]: %v", source.name, f, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
source.bin = bin // In-memory copy of the cache file content
|
||||||
|
// The tests require the timestamps to be updated, no idea why
|
||||||
|
_ = os.Chtimes(f, now, now)
|
||||||
|
_ = os.Chtimes(f+".minisig", now, now)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (source *Source) parseURLs(urls []string) {
|
func (source *Source) parseURLs(urls []string) {
|
||||||
|
|
Loading…
Reference in New Issue