From 56fccecd0694cc39aa2d58c1940d31956e5c42f2 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Thu, 20 Jul 2017 22:22:51 +0200 Subject: [PATCH] prune: Repack mixed pack files --- cmd/restic/cmd_prune.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index d48d00192..1383d15a4 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -85,6 +85,25 @@ func runPrune(gopts GlobalOptions) error { 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 { ctx := gopts.ctx @@ -191,6 +210,11 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error { // find packs that need a rewrite rewritePacks := restic.NewIDSet() for _, pack := range idx.Packs { + if mixedBlobs(pack.Entries) { + rewritePacks.Insert(pack.ID) + continue + } + for _, blob := range pack.Entries { h := restic.BlobHandle{ID: blob.ID, Type: blob.Type} if !usedBlobs.Has(h) {