Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

ftp: implement Shutdown method

Nick Craig-Wood843ddd9136e9
diff --git a/backend/ftp/ftp.go b/backend/ftp/ftp.go
index 0fab0081c..6a93b6fd4 100644
--- a/backend/ftp/ftp.go
+++ b/backend/ftp/ftp.go
@@ -325,6 +325,20 @@ func (f *Fs) putFtpConnection(pc **ftp.ServerConn, err error) {
f.poolMu.Unlock()
}
+// Drain the pool of any connections
+func (f *Fs) drainPool(ctx context.Context) (err error) {
+ f.poolMu.Lock()
+ defer f.poolMu.Unlock()
+ for i, c := range f.pool {
+ if cErr := c.Quit(); cErr != nil {
+ err = cErr
+ }
+ f.pool[i] = nil
+ }
+ f.pool = nil
+ return err
+}
+
// NewFs constructs an Fs from the path, container:path
func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (ff fs.Fs, err error) {
// defer fs.Trace(nil, "name=%q, root=%q", name, root)("fs=%v, err=%v", &ff, &err)
@@ -407,6 +421,12 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (ff fs.Fs
return f, err
}
+// Shutdown the backend, closing any background tasks and any
+// cached connections.
+func (f *Fs) Shutdown(ctx context.Context) error {
+ return f.drainPool(ctx)
+}
+
// translateErrorFile turns FTP errors into rclone errors if possible for a file
func translateErrorFile(err error) error {
switch errX := err.(type) {
@@ -1015,5 +1035,6 @@ var (
_ fs.Mover = &Fs{}
_ fs.DirMover = &Fs{}
_ fs.PutStreamer = &Fs{}
+ _ fs.Shutdowner = &Fs{}
_ fs.Object = &Object{}
)