mirror of
https://github.com/rclone/rclone.git
synced 2026-01-03 17:13:18 +00:00
fs: Pin created backends until parents are finalized
This attempts to solve the backend lifecycle problem by - Pinning backends mentioned on the command line into the cache indefinitely - Unpinning backends when the containing structure (VFS, wrapping backend) is destroyed See: https://forum.rclone.org/t/rclone-rc-backend-command-not-working-as-expected/18834
This commit is contained in:
13
fs/cache/cache.go
vendored
13
fs/cache/cache.go
vendored
@@ -2,6 +2,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
@@ -80,6 +81,18 @@ func Pin(f fs.Fs) {
|
||||
c.Pin(fs.ConfigString(f))
|
||||
}
|
||||
|
||||
// PinUntilFinalized pins f into the cache until x is garbage collected
|
||||
//
|
||||
// This calls runtime.SetFinalizer on x so it shouldn't have a
|
||||
// finalizer already.
|
||||
func PinUntilFinalized(f fs.Fs, x interface{}) {
|
||||
Pin(f)
|
||||
runtime.SetFinalizer(x, func(_ interface{}) {
|
||||
Unpin(f)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// Unpin f from the cache
|
||||
func Unpin(f fs.Fs) {
|
||||
c.Pin(fs.ConfigString(f))
|
||||
|
||||
Reference in New Issue
Block a user