mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-01-06 01:37:12 +01:00
Make updateCache() more readable
This commit is contained in:
parent
ce55d1c5bb
commit
afcfd566c9
@ -102,24 +102,24 @@ func writeSource(f string, bin, sig []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (source *Source) updateCache(bin, sig []byte, now time.Time) {
|
func (source *Source) updateCache(bin, sig []byte, now time.Time) {
|
||||||
f := source.cacheFile
|
file := source.cacheFile
|
||||||
var writeErr error // an error writing cache isn't fatal
|
absPath := file
|
||||||
defer func() {
|
if resolved, err := filepath.Abs(file); err != nil {
|
||||||
source.bin = bin
|
absPath = resolved
|
||||||
if writeErr == nil {
|
}
|
||||||
return
|
|
||||||
}
|
if bytes.Equal(source.bin, bin) {
|
||||||
if absPath, absErr := filepath.Abs(f); absErr == nil {
|
if err := os.Chtimes(file, now, now); err != nil {
|
||||||
f = absPath
|
dlog.Warnf("Couldn't update cache file [%s]: %s", absPath, err)
|
||||||
}
|
}
|
||||||
dlog.Warnf("%s: %s", f, writeErr)
|
return
|
||||||
}()
|
}
|
||||||
if !bytes.Equal(source.bin, bin) {
|
|
||||||
if writeErr = writeSource(f, bin, sig); writeErr != nil {
|
source.bin = bin
|
||||||
return
|
|
||||||
}
|
if err := writeSource(file, bin, sig); err != nil {
|
||||||
|
dlog.Warnf("Couldn't write cache file [%s]: %s", absPath, err) // an error writing to the cache isn't fatal
|
||||||
}
|
}
|
||||||
writeErr = os.Chtimes(f, now, now)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (source *Source) parseURLs(urls []string) {
|
func (source *Source) parseURLs(urls []string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user