prune: Remove invalid files

Closes #1029
This commit is contained in:
Alexander Neumann
2017-06-15 15:03:05 +02:00
parent eadf5dcb2d
commit 4ae59bef96
5 changed files with 32 additions and 14 deletions

View File

@@ -106,11 +106,15 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error {
Verbosef("building new index for repo\n")
bar := newProgressMax(!gopts.Quiet, uint64(stats.packs), "packs")
idx, err := index.New(ctx, repo, restic.NewIDSet(), bar)
idx, invalidFiles, err := index.New(ctx, repo, restic.NewIDSet(), bar)
if err != nil {
return err
}
for _, id := range invalidFiles {
Warnf("incomplete pack file (will be removed): %v\n", id)
}
blobs := 0
for _, pack := range idx.Packs {
stats.bytes += pack.Size
@@ -196,6 +200,12 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error {
// find packs that are unneeded
removePacks := restic.NewIDSet()
Verbosef("will remove %d invalid files\n", len(invalidFiles))
for _, id := range invalidFiles {
removePacks.Insert(id)
}
for packID, p := range idx.Packs {
hasActiveBlob := false

View File

@@ -50,7 +50,7 @@ func rebuildIndex(ctx context.Context, repo restic.Repository, ignorePacks resti
}
bar := newProgressMax(!globalOptions.Quiet, packs, "packs")
idx, err := index.New(ctx, repo, ignorePacks, bar)
idx, _, err := index.New(ctx, repo, ignorePacks, bar)
if err != nil {
return err
}