github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/fs/rc/cache.go (about)

     1  // Utilities for accessing the Fs cache
     2  
     3  package rc
     4  
     5  import (
     6  	"github.com/rclone/rclone/fs"
     7  	"github.com/rclone/rclone/fs/cache"
     8  )
     9  
    10  // GetFsNamed gets a fs.Fs named fsName either from the cache or creates it afresh
    11  func GetFsNamed(in Params, fsName string) (f fs.Fs, err error) {
    12  	fsString, err := in.GetString(fsName)
    13  	if err != nil {
    14  		return nil, err
    15  	}
    16  
    17  	return cache.Get(fsString)
    18  }
    19  
    20  // GetFs gets a fs.Fs named "fs" either from the cache or creates it afresh
    21  func GetFs(in Params) (f fs.Fs, err error) {
    22  	return GetFsNamed(in, "fs")
    23  }
    24  
    25  // GetFsAndRemoteNamed gets the fsName parameter from in, makes a
    26  // remote or fetches it from the cache then gets the remoteName
    27  // parameter from in too.
    28  func GetFsAndRemoteNamed(in Params, fsName, remoteName string) (f fs.Fs, remote string, err error) {
    29  	remote, err = in.GetString(remoteName)
    30  	if err != nil {
    31  		return
    32  	}
    33  	f, err = GetFsNamed(in, fsName)
    34  	return
    35  
    36  }
    37  
    38  // GetFsAndRemote gets the `fs` parameter from in, makes a remote or
    39  // fetches it from the cache then gets the `remote` parameter from in
    40  // too.
    41  func GetFsAndRemote(in Params) (f fs.Fs, remote string, err error) {
    42  	return GetFsAndRemoteNamed(in, "fs", "remote")
    43  }