2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-27 15:26:37 +00:00

fsck: Fix check for orphaned blobs

This commit is contained in:
Alexander Neumann 2015-05-17 23:41:53 +02:00
parent df1e3e03e9
commit 0314d2b0c3

View File

@ -57,7 +57,7 @@ func fsckFile(opts CmdFsck, repo *repository.Repository, IDs []backend.ID) (uint
return 0, err return 0, err
} }
} else { } else {
// test if data blob is there // test if pack for data blob is there
ok, err := repo.Backend().Test(backend.Data, packID.String()) ok, err := repo.Backend().Test(backend.Data, packID.String())
if err != nil { if err != nil {
return 0, err return 0, err
@ -70,6 +70,7 @@ func fsckFile(opts CmdFsck, repo *repository.Repository, IDs []backend.ID) (uint
// if orphan check is active, record storage id // if orphan check is active, record storage id
if opts.o_data != nil { if opts.o_data != nil {
debug.Log("restic.fsck", " recording blob %v as used\n", id)
opts.o_data.Insert(id) opts.o_data.Insert(id)
} }
} }
@ -235,14 +236,16 @@ func (cmd CmdFsck) Execute(args []string) error {
debug.Log("restic.fsck", "starting orphaned check\n") debug.Log("restic.fsck", "starting orphaned check\n")
cnt := make(map[pack.BlobType]*backend.IDSet) cnt := make(map[pack.BlobType]*backend.IDSet)
cnt[pack.Data] = backend.NewIDSet() cnt[pack.Data] = cmd.o_data
cnt[pack.Tree] = backend.NewIDSet() cnt[pack.Tree] = cmd.o_trees
for blob := range s.Index().Each(done) { for blob := range s.Index().Each(done) {
fmt.Println(blob.ID) debug.Log("restic.fsck", "checking %v blob %v\n", blob.Type, blob.ID)
err = cnt[blob.Type].Find(blob.ID) err = cnt[blob.Type].Find(blob.ID)
if err != nil { if err != nil {
debug.Log("restic.fsck", " blob %v is orphaned\n", blob.ID)
if !cmd.RemoveOrphaned { if !cmd.RemoveOrphaned {
fmt.Printf("orphaned %v blob %v\n", blob.Type, blob.ID) fmt.Printf("orphaned %v blob %v\n", blob.Type, blob.ID)
continue continue