"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
nfsmount: fix exit after external unmount #7503
nielash0e2f1d64e361
diff --git a/cmd/nfsmount/nfsmount.go b/cmd/nfsmount/nfsmount.goindex 610c2f655..8b9f21b7e 100644--- a/cmd/nfsmount/nfsmount.go+++ b/cmd/nfsmount/nfsmount.go@@ -81,6 +81,9 @@ func mount(VFS *vfs.VFS, mountpoint string, opt *mountlib.Options) (asyncerrors}asyncerrors = errChanunmount = func() error {+ if s.UnmountedExternally {+ return nil+ }var umountErr errorvar out []byteif runtime.GOOS == "darwin" {@@ -98,5 +101,12 @@ func mount(VFS *vfs.VFS, mountpoint string, opt *mountlib.Options) (asyncerrors}return nil}++ nfs.OnUnmountFunc = func() {+ s.UnmountedExternally = true+ errChan <- nil+ VFS.Shutdown()+ }+return}diff --git a/cmd/serve/nfs/handler.go b/cmd/serve/nfs/handler.goindex 9cfa82999..ed00639af 100644--- a/cmd/serve/nfs/handler.go+++ b/cmd/serve/nfs/handler.go@@ -7,6 +7,7 @@ import ("context""fmt""net"+ "strings""github.com/go-git/go-billy/v5""github.com/rclone/rclone/fs"@@ -100,6 +101,16 @@ func (o *Options) Limit() int {return o.HandleLimit}+// OnUnmountFunc registers a function to call when externally unmounted+var OnUnmountFunc func()++func onUnmount() {+ fs.Infof(nil, "unmount detected")+ if OnUnmountFunc != nil {+ OnUnmountFunc()+ }+}+// LogIntercepter intercepts noisy go-nfs logs and reroutes them to DEBUGtype LogIntercepter struct {Level nfs.LogLevel@@ -114,6 +125,12 @@ func (l *LogIntercepter) Intercept(args ...interface{}) {// Interceptf intercepts go-nfs logs and calls fs.Debugf insteadfunc (l *LogIntercepter) Interceptf(format string, args ...interface{}) {+ argsS := fmt.Sprint(args...)+ // bit of a workaround... the real fix is probably https://github.com/willscott/go-nfs/pull/28+ if strings.Contains(argsS, "mount.Umnt") {+ onUnmount()+ }+fs.Debugf(nil, "[NFS DEBUG] "+format, args...)}diff --git a/cmd/serve/nfs/server.go b/cmd/serve/nfs/server.goindex a7396cdb0..14e125264 100644--- a/cmd/serve/nfs/server.go+++ b/cmd/serve/nfs/server.go@@ -16,10 +16,11 @@ import (// Server contains everything to run the Servertype Server struct {- opt Options- handler nfs.Handler- ctx context.Context // for global config- listener net.Listener+ opt Options+ handler nfs.Handler+ ctx context.Context // for global config+ listener net.Listener+ UnmountedExternally bool}// NewServer creates a new server