lib/backup: add MustStop() method for all remote filesystems

This commit is contained in:
Aliaksandr Valialkin 2020-10-09 15:31:39 +03:00
parent bf6d523bef
commit de1c07b937
7 changed files with 34 additions and 0 deletions

View file

@ -91,6 +91,8 @@ func main() {
logger.Fatalf("cannot create backup: %s", err)
}
srcFS.MustStop()
dstFS.MustStop()
originFS.MustStop()
}
func usage() {

View file

@ -52,6 +52,7 @@ func main() {
if err := a.Run(); err != nil {
logger.Fatalf("cannot restore from backup: %s", err)
}
srcFS.MustStop()
dstFS.MustStop()
}

View file

@ -9,6 +9,9 @@ import (
// This filesystem is used for performing server-side file copies
// instead of uploading data from local filesystem.
type OriginFS interface {
// MustStop must be called when the RemoteFS is no longer needed.
MustStop()
// String must return human-readable representation of OriginFS.
String() string
@ -18,6 +21,9 @@ type OriginFS interface {
// RemoteFS is a filesystem where backups are stored.
type RemoteFS interface {
// MustStop must be called when the RemoteFS is no longer needed.
MustStop()
// String must return human-readable representation of RemoteFS.
String() string

View file

@ -7,6 +7,11 @@ import (
// FS represents nil remote filesystem.
type FS struct{}
// MustStop stops fs.
func (fs *FS) MustStop() {
// Nothing to do
}
// String returns human-readable string representation for fs.
func (fs *FS) String() string {
return "fsnil"

View file

@ -22,6 +22,11 @@ type FS struct {
Dir string
}
// MustStop stops fs.
func (fs *FS) MustStop() {
// Nothing to do
}
// String returns human-readable string representation for fs.
func (fs *FS) String() string {
return fmt.Sprintf("fsremote %q", fs.Dir)

View file

@ -33,6 +33,8 @@ type FS struct {
}
// Init initializes fs.
//
// The returned fs must be stopped when no long needed with MustStop call.
func (fs *FS) Init() error {
if fs.bkt != nil {
logger.Panicf("BUG: fs.Init has been already called")
@ -63,6 +65,11 @@ func (fs *FS) Init() error {
return nil
}
// MustStop stops fs.
func (fs *FS) MustStop() {
fs.bkt = nil
}
// String returns human-readable description for fs.
func (fs *FS) String() string {
return fmt.Sprintf("GCS{bucket: %q, dir: %q}", fs.Bucket, fs.Dir)

View file

@ -45,6 +45,8 @@ type FS struct {
}
// Init initializes fs.
//
// The returned fs must be stopped when no long needed with MustStop call.
func (fs *FS) Init() error {
if fs.s3 != nil {
logger.Panicf("BUG: Init is already called")
@ -96,6 +98,12 @@ func (fs *FS) Init() error {
return nil
}
// MustStop stops fs.
func (fs *FS) MustStop() {
fs.s3 = nil
fs.uploader = nil
}
// String returns human-readable description for fs.
func (fs *FS) String() string {
return fmt.Sprintf("S3{bucket: %q, dir: %q}", fs.Bucket, fs.Dir)