lib/db: Improve error handling checking db (ref #7026) (#7027)

This commit is contained in:
Simon Frei 2020-10-06 20:14:09 +02:00 committed by GitHub
parent 977ee4f06b
commit 14ae330eff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/binary" "encoding/binary"
"fmt"
"io" "io"
"os" "os"
"time" "time"
@ -822,6 +823,7 @@ func (db *Lowlevel) getMetaAndCheck(folder string) *metadataTracker {
var fixed int var fixed int
fixed, err = db.checkLocalNeed([]byte(folder)) fixed, err = db.checkLocalNeed([]byte(folder))
if err != nil { if err != nil {
err = fmt.Errorf("checking local need: %w", err)
return nil return nil
} }
if fixed != 0 { if fixed != 0 {
@ -830,11 +832,13 @@ func (db *Lowlevel) getMetaAndCheck(folder string) *metadataTracker {
meta, err := db.recalcMeta(folder) meta, err := db.recalcMeta(folder)
if err != nil { if err != nil {
err = fmt.Errorf("recalculating metadata: %w", err)
return nil return nil
} }
fixed, err = db.repairSequenceGCLocked(folder, meta) fixed, err = db.repairSequenceGCLocked(folder, meta)
if err != nil { if err != nil {
err = fmt.Errorf("repairing sequences: %w", err)
return nil return nil
} }
if fixed != 0 { if fixed != 0 {
@ -1094,7 +1098,7 @@ func (db *Lowlevel) checkLocalNeed(folder []byte) (int, error) {
f := fi.(FileInfoTruncated) f := fi.(FileInfoTruncated)
for !needDone && needName < f.Name { for !needDone && needName < f.Name {
repaired++ repaired++
if err = t.Delete(dbi.Key()); err != nil { if err = t.Delete(dbi.Key()); err != nil && !backend.IsNotFound(err) {
return false return false
} }
l.Debugln("check local need: removing", needName) l.Debugln("check local need: removing", needName)
@ -1121,7 +1125,7 @@ func (db *Lowlevel) checkLocalNeed(folder []byte) (int, error) {
for !needDone { for !needDone {
repaired++ repaired++
if err := t.Delete(dbi.Key()); err != nil { if err := t.Delete(dbi.Key()); err != nil && !backend.IsNotFound(err) {
return 0, err return 0, err
} }
l.Debugln("check local need: removing", needName) l.Debugln("check local need: removing", needName)