mirror of
https://github.com/tailscale/tailscale.git
synced 2026-03-29 10:11:43 +02:00
add discard method for the disk cache
Change-Id: I7f597e3b1ad5319c0baf82079b248be948bf4b22 Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
This commit is contained in:
parent
049ab7c0d9
commit
cf92a2a9a3
@ -54,3 +54,29 @@ func (b *LocalBackend) loadDiskCacheLocked() (om *netmap.NetworkMap, ok bool) {
|
||||
}
|
||||
return nm, true
|
||||
}
|
||||
|
||||
func (b *LocalBackend) discardDiskCacheLocked() {
|
||||
if !buildfeatures.HasCacheNetMap {
|
||||
return
|
||||
}
|
||||
if b.diskCache.cache == nil {
|
||||
return // nothing to do, we do not have a cache
|
||||
}
|
||||
|
||||
// Reaching here, we have a cache directory that needs to be purged.
|
||||
// Log errors but do not fail for them.
|
||||
store := netmapcache.FileStore(b.diskCache.dir)
|
||||
ctx := b.currentNode().Context()
|
||||
for key, err := range store.List(ctx, "") {
|
||||
if err != nil {
|
||||
b.logf("listing cache contents: %v", err)
|
||||
break
|
||||
}
|
||||
if err := store.Remove(ctx, key); err != nil {
|
||||
b.logf("discarding cache key %q: %v", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
b.diskCache.cache = nil // drop reference
|
||||
b.diskCache.dir = ""
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user