"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
cmount: fix openFile leak
Nick Craig-Woodbc88f1dafa64
diff --git a/cmd/cmount/fs.go b/cmd/cmount/fs.goindex a3203ed4a..a24debea9 100644--- a/cmd/cmount/fs.go+++ b/cmd/cmount/fs.go@@ -161,19 +161,28 @@ func (fsys *FS) lookupFile(path string) (file *mountlib.File, errc int) {return file, 0}-// Get the underlying handle from the file handle-func (fsys *FS) getHandleFromFh(fh uint64) (handle mountlib.Noder, errc int) {+// Get the underlying openFile handle from the file handle+func (fsys *FS) getOpenFilesFromFh(fh uint64) (of *openFiles, errc int) {switch {case fsys.openFilesRd.InRange(fh):- return fsys.openFilesRd.Get(fh)+ return fsys.openFilesRd, 0case fsys.openFilesWr.InRange(fh):- return fsys.openFilesWr.Get(fh)+ return fsys.openFilesWr, 0case fsys.openDirs.InRange(fh):- return fsys.openDirs.Get(fh)+ return fsys.openDirs, 0}return nil, -fuse.EBADF}+// Get the underlying handle from the file handle+func (fsys *FS) getHandleFromFh(fh uint64) (handle mountlib.Noder, errc int) {+ of, errc := fsys.getOpenFilesFromFh(fh)+ if errc != 0 {+ return nil, errc+ }+ return of.Get(fh)+}+// get a node from the path or from the fh if not fhUnsetfunc (fsys *FS) getNode(path string, fh uint64) (node mountlib.Node, errc int) {if fh == fhUnset {@@ -462,10 +471,15 @@ func (fsys *FS) Flush(path string, fh uint64) (errc int) {// Release closes the file if still openfunc (fsys *FS) Release(path string, fh uint64) (errc int) {defer fs.Trace(path, "fh=0x%X", fh)("errc=%d", &errc)- handle, errc := fsys.getHandleFromFh(fh)+ of, errc := fsys.getOpenFilesFromFh(fh)+ if errc != 0 {+ return errc+ }+ handle, errc := of.Get(fh)if errc != 0 {return errc}+ _ = of.Close(fh)var err errorswitch x := handle.(type) {case *mountlib.ReadFileHandle: