forked from TrueCloudLab/restic
Explicitely specify supersedes for new index
This commit is contained in:
parent
29bb845f0e
commit
8d735cf6a9
2 changed files with 14 additions and 15 deletions
|
@ -180,22 +180,22 @@ func (cmd CmdPrune) Execute(args []string) error {
|
||||||
return err
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cmd.global.Verbosef("saved new index as %v\n", id.Str())
|
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")
|
cmd.global.Verbosef("done\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,15 +287,14 @@ func (idx *Index) FindBlob(h pack.Handle) ([]Location, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save writes the complete index to the repo and includes all previously read
|
// Save writes the complete index to the repo.
|
||||||
// indexes to the Supersedes field.
|
func (idx *Index) Save(repo types.Repository, supersedes backend.IDs) (backend.ID, error) {
|
||||||
func (idx *Index) Save(repo types.Repository) (backend.ID, error) {
|
|
||||||
packs := make(map[backend.ID][]pack.Blob, len(idx.Packs))
|
packs := make(map[backend.ID][]pack.Blob, len(idx.Packs))
|
||||||
for id, p := range idx.Packs {
|
for id, p := range idx.Packs {
|
||||||
packs[id] = p.Entries
|
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.
|
// Save writes a new index containing the given packs.
|
||||||
|
|
Loading…
Reference in a new issue