2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 21:05:10 +00:00

Remove cache entries for non-existing snapshots

This commit is contained in:
Alexander Neumann 2015-03-22 16:09:35 +01:00
parent 5257c54585
commit 3e246170de

View File

@ -208,10 +208,17 @@ func (c *Cache) filename(t backend.Type, subtype string, id backend.ID) (string,
// 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 {
defer p.Done()
// list cache entries
entries, err := c.List(backend.Snapshot)
if err != nil {
return err
}
// list snapshots first
snapshots, err := s.List(backend.Snapshot)
if err != nil {
@ -220,6 +227,14 @@ func (c *Cache) RefreshSnapshots(s Server, p *Progress) error {
// check that snapshot blobs are cached
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)
if err != nil {
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
}