forked from TrueCloudLab/restic
Remove cache entries for non-existing snapshots
This commit is contained in:
parent
5257c54585
commit
3e246170de
1 changed files with 25 additions and 1 deletions
26
cache.go
26
cache.go
|
@ -208,10 +208,17 @@ func (c *Cache) filename(t backend.Type, subtype string, id backend.ID) (string,
|
||||||
|
|
||||||
// high-level functions
|
// high-level functions
|
||||||
|
|
||||||
// RefreshSnapshots loads the maps for all snapshots and saves them to the local cache.
|
// RefreshSnapshots loads the maps for all snapshots and saves them to the
|
||||||
|
// local cache. Old cache entries are purged.
|
||||||
func (c *Cache) RefreshSnapshots(s Server, p *Progress) error {
|
func (c *Cache) RefreshSnapshots(s Server, p *Progress) error {
|
||||||
defer p.Done()
|
defer p.Done()
|
||||||
|
|
||||||
|
// list cache entries
|
||||||
|
entries, err := c.List(backend.Snapshot)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// list snapshots first
|
// list snapshots first
|
||||||
snapshots, err := s.List(backend.Snapshot)
|
snapshots, err := s.List(backend.Snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -220,6 +227,14 @@ func (c *Cache) RefreshSnapshots(s Server, p *Progress) error {
|
||||||
|
|
||||||
// check that snapshot blobs are cached
|
// check that snapshot blobs are cached
|
||||||
for _, id := range snapshots {
|
for _, id := range snapshots {
|
||||||
|
// remove snapshot from list of entries
|
||||||
|
for i, e := range entries {
|
||||||
|
if e.ID.Equal(id) {
|
||||||
|
entries = append(entries[:i], entries[i+1:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
has, err := c.Has(backend.Snapshot, "blobs", id)
|
has, err := c.Has(backend.Snapshot, "blobs", id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -240,6 +255,15 @@ func (c *Cache) RefreshSnapshots(s Server, p *Progress) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove other entries
|
||||||
|
for _, e := range entries {
|
||||||
|
debug.Log("Cache.RefreshSnapshots", "remove entry %v", e)
|
||||||
|
err = c.Purge(backend.Snapshot, e.Subtype, e.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue