1
0
mirror of https://github.com/restic/restic.git synced 2024-06-30 08:20:55 +02:00

Explicitely specify supersedes for new index

This commit is contained in:
Alexander Neumann 2016-08-15 20:49:01 +02:00
parent 29bb845f0e
commit 8d735cf6a9
2 changed files with 14 additions and 15 deletions

View File

@ -180,22 +180,22 @@ func (cmd CmdPrune) Execute(args []string) error {
return err
}
id, err := idx.Save(repo)
var supersedes backend.IDs
for idxID := range repo.List(backend.Index, done) {
err := repo.Backend().Remove(backend.Index, idxID.String())
if err != nil {
fmt.Fprintf(os.Stderr, "unable to remove index %v: %v\n", idxID.Str(), err)
}
supersedes = append(supersedes, idxID)
}
id, err := idx.Save(repo, supersedes)
if err != nil {
return err
}
cmd.global.Verbosef("saved new index as %v\n", id.Str())
for oldIndex := range repo.List(backend.Index, done) {
if id.Equal(oldIndex) {
continue
}
err := repo.Backend().Remove(backend.Index, oldIndex.String())
if err != nil {
fmt.Fprintf(os.Stderr, "unable to remove index %v: %v\n", oldIndex.Str(), err)
}
}
cmd.global.Verbosef("done\n")
return nil
}

View File

@ -287,15 +287,14 @@ func (idx *Index) FindBlob(h pack.Handle) ([]Location, error) {
return result, nil
}
// Save writes the complete index to the repo and includes all previously read
// indexes to the Supersedes field.
func (idx *Index) Save(repo types.Repository) (backend.ID, error) {
// Save writes the complete index to the repo.
func (idx *Index) Save(repo types.Repository, supersedes backend.IDs) (backend.ID, error) {
packs := make(map[backend.ID][]pack.Blob, len(idx.Packs))
for id, p := range idx.Packs {
packs[id] = p.Entries
}
return Save(repo, packs, idx.IndexIDs.List())
return Save(repo, packs, supersedes)
}
// Save writes a new index containing the given packs.