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

prune: Repack mixed pack files

This commit is contained in:
Alexander Neumann 2017-07-20 22:22:51 +02:00
parent 3890a947ca
commit 56fccecd06

View File

@ -85,6 +85,25 @@ func runPrune(gopts GlobalOptions) error {
return pruneRepository(gopts, repo) return pruneRepository(gopts, repo)
} }
func mixedBlobs(list []restic.Blob) bool {
var tree, data bool
for _, pb := range list {
switch pb.Type {
case restic.TreeBlob:
tree = true
case restic.DataBlob:
data = true
}
if tree && data {
return true
}
}
return false
}
func pruneRepository(gopts GlobalOptions, repo restic.Repository) error { func pruneRepository(gopts GlobalOptions, repo restic.Repository) error {
ctx := gopts.ctx ctx := gopts.ctx
@ -191,6 +210,11 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error {
// find packs that need a rewrite // find packs that need a rewrite
rewritePacks := restic.NewIDSet() rewritePacks := restic.NewIDSet()
for _, pack := range idx.Packs { for _, pack := range idx.Packs {
if mixedBlobs(pack.Entries) {
rewritePacks.Insert(pack.ID)
continue
}
for _, blob := range pack.Entries { for _, blob := range pack.Entries {
h := restic.BlobHandle{ID: blob.ID, Type: blob.Type} h := restic.BlobHandle{ID: blob.ID, Type: blob.Type}
if !usedBlobs.Has(h) { if !usedBlobs.Has(h) {