Merge pull request #1459 from restic/improve-s3-do-spaces
Improve s3 backend for DigitalOcean Spaces
This commit is contained in:
commit
0cedb3ac9f
2 changed files with 17 additions and 6 deletions
|
@ -25,16 +25,14 @@ func init() {
|
||||||
InstallSignalHandler()
|
InstallSignalHandler()
|
||||||
}
|
}
|
||||||
|
|
||||||
// InstallSignalHandler listens for SIGINT and SIGPIPE, and triggers the cleanup handlers.
|
// InstallSignalHandler listens for SIGINT, and triggers the cleanup handlers.
|
||||||
func InstallSignalHandler() {
|
func InstallSignalHandler() {
|
||||||
signal.Notify(cleanupHandlers.ch, syscall.SIGINT)
|
signal.Notify(cleanupHandlers.ch, syscall.SIGINT)
|
||||||
signal.Notify(cleanupHandlers.ch, syscall.SIGPIPE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SuspendSignalHandler removes the signal handler for SIGINT and SIGPIPE.
|
// SuspendSignalHandler removes the signal handler for SIGINT.
|
||||||
func SuspendSignalHandler() {
|
func SuspendSignalHandler() {
|
||||||
signal.Reset(syscall.SIGINT)
|
signal.Reset(syscall.SIGINT)
|
||||||
signal.Reset(syscall.SIGPIPE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddCleanupHandler adds the function f to the list of cleanup handlers so
|
// AddCleanupHandler adds the function f to the list of cleanup handlers so
|
||||||
|
@ -69,7 +67,7 @@ func RunCleanupHandlers() {
|
||||||
cleanupHandlers.list = nil
|
cleanupHandlers.list = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanupHandler handles the SIGINT and SIGPIPE signals.
|
// CleanupHandler handles the SIGINT signals.
|
||||||
func CleanupHandler(c <-chan os.Signal) {
|
func CleanupHandler(c <-chan os.Signal) {
|
||||||
for s := range c {
|
for s := range c {
|
||||||
debug.Log("signal %v received, cleaning up", s)
|
debug.Log("signal %v received, cleaning up", s)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff"
|
"github.com/cenkalti/backoff"
|
||||||
|
"github.com/restic/restic/internal/debug"
|
||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
)
|
)
|
||||||
|
@ -65,7 +66,19 @@ func (be *RetryBackend) Save(ctx context.Context, h restic.Handle, rd io.Reader)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return be.Backend.Save(ctx, h, rd)
|
err = be.Backend.Save(ctx, h, rd)
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
debug.Log("Save(%v) failed with error, removing file: %v", h, err)
|
||||||
|
rerr := be.Remove(ctx, h)
|
||||||
|
if rerr != nil {
|
||||||
|
debug.Log("Remove(%v) returned error: %v", h, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// return original error
|
||||||
|
return err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue