feat: forget soft-deletes operations associated with removed snapshots

This commit is contained in:
garethgeorge
2023-12-01 19:49:56 -08:00
parent b8636d1e18
commit fc68467c5e
3 changed files with 14 additions and 7 deletions
+5 -1
View File
@@ -30,7 +30,11 @@ jobs:
run: ./scripts/install-deps.sh
- name: Build
run: ./scripts/build.sh
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: build --snapshot --clean
- name: Test
run: PATH=$(pwd):$PATH go test ./...
+2 -2
View File
@@ -183,12 +183,12 @@ func (o *OpLog) Update(op *v1.Operation) error {
func (o *OpLog) Delete(id int64) error {
err := o.db.Update(func(tx *bolt.Tx) error {
val := tx.Bucket(OpLogBucket).Get(serializationutil.Itob(op.Id))
val := tx.Bucket(OpLogBucket).Get(serializationutil.Itob(id))
if val == nil {
return ErrNotExist
}
if err := o.deleteOperationHelper(tx, id); err != nil {
return fmt.Errorf("deleting operation %v: %w", op.Id, err)
return fmt.Errorf("deleting operation %v: %w", id, err)
}
b := tx.Bucket(OpLogSoftDeleteBucket)
+7 -4
View File
@@ -8,6 +8,8 @@ import (
"time"
v1 "github.com/garethgeorge/resticui/gen/go/v1"
"github.com/garethgeorge/resticui/internal/oplog/indexutil"
"github.com/hashicorp/go-multierror"
"go.uber.org/zap"
)
@@ -85,13 +87,14 @@ func (t *ForgetTask) Run(ctx context.Context) error {
forgetOp.OperationForget.Forget = append(forgetOp.OperationForget.Forget, forgot...)
for _, forgot := range forgot {
t.orchestrator.OpLog.ForEachBySnapshotId(forgot.Id, func(op *v1.Operation) error {
if e := t.orchestrator.OpLog.ForEachBySnapshotId(forgot.Id, indexutil.CollectAll(), func(op *v1.Operation) error {
return t.orchestrator.OpLog.Delete(op.Id)
})
}); e != nil {
err = multierror.Append(err, fmt.Errorf("cleanup snapshot %v: %w", forgot.Id, e))
}
}
return nil
return err
}); err != nil {
return err
}