diff --git a/src/internal/operations/backup.go b/src/internal/operations/backup.go index 026061b59..7d6c14748 100644 --- a/src/internal/operations/backup.go +++ b/src/internal/operations/backup.go @@ -90,7 +90,6 @@ type backupStats struct { k *kopia.BackupStats gc *support.ConnectorOperationStatus resourceCount int - started bool readErr, writeErr error } @@ -228,7 +227,6 @@ func (op *BackupOperation) Run(ctx context.Context) (err error) { // should always be 1, since backups are 1:1 with resourceOwners. opStats.resourceCount = 1 - opStats.started = true return err } @@ -558,9 +556,12 @@ func (op *BackupOperation) persistResults( ) error { op.Results.StartedAt = started op.Results.CompletedAt = time.Now() + op.Results.ReadErrors = opStats.readErr + op.Results.WriteErrors = opStats.writeErr op.Status = Completed - if !opStats.started { + + if opStats.readErr != nil || opStats.writeErr != nil { op.Status = Failed return multierror.Append( @@ -573,9 +574,6 @@ func (op *BackupOperation) persistResults( op.Status = NoData } - op.Results.ReadErrors = opStats.readErr - op.Results.WriteErrors = opStats.writeErr - op.Results.BytesRead = opStats.k.TotalHashedBytes op.Results.BytesUploaded = opStats.k.TotalUploadedBytes op.Results.ItemsRead = opStats.gc.Successful diff --git a/src/internal/operations/backup_test.go b/src/internal/operations/backup_test.go index 795f341c6..2a7a1ecce 100644 --- a/src/internal/operations/backup_test.go +++ b/src/internal/operations/backup_test.go @@ -373,7 +373,6 @@ func (suite *BackupOpSuite) TestBackupOperation_PersistResults() { expectStatus: Completed, expectErr: assert.NoError, stats: backupStats{ - started: true, resourceCount: 1, k: &kopia.BackupStats{ TotalFileCount: 1, @@ -389,7 +388,7 @@ func (suite *BackupOpSuite) TestBackupOperation_PersistResults() { expectStatus: Failed, expectErr: assert.Error, stats: backupStats{ - started: false, + readErr: assert.AnError, k: &kopia.BackupStats{}, gc: &support.ConnectorOperationStatus{}, }, @@ -398,9 +397,8 @@ func (suite *BackupOpSuite) TestBackupOperation_PersistResults() { expectStatus: NoData, expectErr: assert.NoError, stats: backupStats{ - started: true, - k: &kopia.BackupStats{}, - gc: &support.ConnectorOperationStatus{}, + k: &kopia.BackupStats{}, + gc: &support.ConnectorOperationStatus{}, }, }, } diff --git a/src/internal/operations/restore.go b/src/internal/operations/restore.go index 7dfd689d6..8ddaa8d29 100644 --- a/src/internal/operations/restore.go +++ b/src/internal/operations/restore.go @@ -89,7 +89,6 @@ type restoreStats struct { gc *support.ConnectorOperationStatus bytesRead *stats.ByteCounter resourceCount int - started bool readErr, writeErr error // a transient value only used to pair up start-end events. @@ -143,10 +142,8 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De detailsStore, ) if err != nil { - err = errors.Wrap(err, "restore") - opStats.readErr = err - - return nil, err + opStats.readErr = errors.Wrap(err, "restore") + return nil, opStats.readErr } ctx = clues.Add(ctx, "resource_owner", bup.Selector.DiscreteOwner) @@ -178,10 +175,8 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De dcs, err := op.kopia.RestoreMultipleItems(ctx, bup.SnapshotID, paths, opStats.bytesRead) if err != nil { - err = errors.Wrap(err, "retrieving service data") - opStats.readErr = err - - return nil, err + opStats.readErr = errors.Wrap(err, "retrieving service data") + return nil, opStats.readErr } kopiaComplete <- struct{}{} @@ -207,14 +202,11 @@ func (op *RestoreOperation) Run(ctx context.Context) (restoreDetails *details.De op.Destination, dcs) if err != nil { - err = errors.Wrap(err, "restoring service data") - opStats.writeErr = err - - return nil, err + opStats.writeErr = errors.Wrap(err, "restoring service data") + return nil, opStats.writeErr } restoreComplete <- struct{}{} - opStats.started = true opStats.gc = gc.AwaitStatus() logger.Ctx(ctx).Debug(gc.PrintableStatus()) @@ -230,10 +222,12 @@ func (op *RestoreOperation) persistResults( ) error { op.Results.StartedAt = started op.Results.CompletedAt = time.Now() + op.Results.ReadErrors = opStats.readErr + op.Results.WriteErrors = opStats.writeErr op.Status = Completed - if !opStats.started { + if opStats.readErr != nil || opStats.writeErr != nil { op.Status = Failed return multierror.Append( @@ -246,9 +240,6 @@ func (op *RestoreOperation) persistResults( op.Status = NoData } - op.Results.ReadErrors = opStats.readErr - op.Results.WriteErrors = opStats.writeErr - op.Results.BytesRead = opStats.bytesRead.NumBytes op.Results.ItemsRead = len(opStats.cs) // TODO: file count, not collection count op.Results.ItemsWritten = opStats.gc.Successful diff --git a/src/internal/operations/restore_test.go b/src/internal/operations/restore_test.go index 44de04c66..973a178b4 100644 --- a/src/internal/operations/restore_test.go +++ b/src/internal/operations/restore_test.go @@ -57,7 +57,6 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() { expectStatus: Completed, expectErr: assert.NoError, stats: restoreStats{ - started: true, resourceCount: 1, bytesRead: &stats.ByteCounter{ NumBytes: 42, @@ -73,7 +72,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() { expectStatus: Failed, expectErr: assert.Error, stats: restoreStats{ - started: false, + readErr: assert.AnError, bytesRead: &stats.ByteCounter{}, gc: &support.ConnectorOperationStatus{}, }, @@ -82,7 +81,6 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() { expectStatus: NoData, expectErr: assert.NoError, stats: restoreStats{ - started: true, bytesRead: &stats.ByteCounter{}, cs: []data.Collection{}, gc: &support.ConnectorOperationStatus{},