forked from TrueCloudLab/rclone
fs: add Wrap feature for FS to identify their parent FS (#1884)
This commit is contained in:
parent
ebd7780188
commit
25b073c767
3 changed files with 49 additions and 4 deletions
16
cache/cache.go
vendored
16
cache/cache.go
vendored
|
@ -206,6 +206,7 @@ type Storage interface {
|
||||||
// Fs represents a wrapped fs.Fs
|
// Fs represents a wrapped fs.Fs
|
||||||
type Fs struct {
|
type Fs struct {
|
||||||
fs.Fs
|
fs.Fs
|
||||||
|
wrapper fs.Fs
|
||||||
|
|
||||||
name string
|
name string
|
||||||
root string
|
root string
|
||||||
|
@ -379,7 +380,9 @@ func NewFs(name, rpath string) (fs.Fs, error) {
|
||||||
PutStream: f.PutStream,
|
PutStream: f.PutStream,
|
||||||
CleanUp: f.CleanUp,
|
CleanUp: f.CleanUp,
|
||||||
UnWrap: f.UnWrap,
|
UnWrap: f.UnWrap,
|
||||||
}).Fill(f).Mask(wrappedFs)
|
WrapFs: f.WrapFs,
|
||||||
|
SetWrapper: f.SetWrapper,
|
||||||
|
}).Fill(f).Mask(wrappedFs).WrapsFs(f, wrappedFs)
|
||||||
|
|
||||||
return f, wrapErr
|
return f, wrapErr
|
||||||
}
|
}
|
||||||
|
@ -938,6 +941,16 @@ func (f *Fs) UnWrap() fs.Fs {
|
||||||
return f.Fs
|
return f.Fs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WrapFs returns the Fs that is wrapping this Fs
|
||||||
|
func (f *Fs) WrapFs() fs.Fs {
|
||||||
|
return f.wrapper
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetWrapper sets the Fs that is wrapping this Fs
|
||||||
|
func (f *Fs) SetWrapper(wrapper fs.Fs) {
|
||||||
|
f.wrapper = wrapper
|
||||||
|
}
|
||||||
|
|
||||||
// DirCacheFlush flushes the dir cache
|
// DirCacheFlush flushes the dir cache
|
||||||
func (f *Fs) DirCacheFlush() {
|
func (f *Fs) DirCacheFlush() {
|
||||||
_ = f.cache.RemoveDir("")
|
_ = f.cache.RemoveDir("")
|
||||||
|
@ -963,5 +976,6 @@ var (
|
||||||
_ fs.PutStreamer = (*Fs)(nil)
|
_ fs.PutStreamer = (*Fs)(nil)
|
||||||
_ fs.CleanUpper = (*Fs)(nil)
|
_ fs.CleanUpper = (*Fs)(nil)
|
||||||
_ fs.UnWrapper = (*Fs)(nil)
|
_ fs.UnWrapper = (*Fs)(nil)
|
||||||
|
_ fs.Wrapper = (*Fs)(nil)
|
||||||
_ fs.ListRer = (*Fs)(nil)
|
_ fs.ListRer = (*Fs)(nil)
|
||||||
)
|
)
|
||||||
|
|
|
@ -129,7 +129,7 @@ func NewFs(name, rpath string) (fs.Fs, error) {
|
||||||
WriteMimeType: false,
|
WriteMimeType: false,
|
||||||
BucketBased: true,
|
BucketBased: true,
|
||||||
CanHaveEmptyDirectories: true,
|
CanHaveEmptyDirectories: true,
|
||||||
}).Fill(f).Mask(wrappedFs)
|
}).Fill(f).Mask(wrappedFs).WrapsFs(f, wrappedFs)
|
||||||
|
|
||||||
doDirChangeNotify := wrappedFs.Features().DirChangeNotify
|
doDirChangeNotify := wrappedFs.Features().DirChangeNotify
|
||||||
if doDirChangeNotify != nil {
|
if doDirChangeNotify != nil {
|
||||||
|
|
35
fs/fs.go
35
fs/fs.go
|
@ -301,6 +301,12 @@ type Features struct {
|
||||||
// UnWrap returns the Fs that this Fs is wrapping
|
// UnWrap returns the Fs that this Fs is wrapping
|
||||||
UnWrap func() Fs
|
UnWrap func() Fs
|
||||||
|
|
||||||
|
// WrapFs returns the Fs that is wrapping this Fs
|
||||||
|
WrapFs func() Fs
|
||||||
|
|
||||||
|
// SetWrapper sets the Fs that is wrapping this Fs
|
||||||
|
SetWrapper func(f Fs)
|
||||||
|
|
||||||
// DirCacheFlush resets the directory cache - used in testing
|
// DirCacheFlush resets the directory cache - used in testing
|
||||||
// as an optional interface
|
// as an optional interface
|
||||||
DirCacheFlush func()
|
DirCacheFlush func()
|
||||||
|
@ -413,6 +419,10 @@ func (ft *Features) Fill(f Fs) *Features {
|
||||||
if do, ok := f.(UnWrapper); ok {
|
if do, ok := f.(UnWrapper); ok {
|
||||||
ft.UnWrap = do.UnWrap
|
ft.UnWrap = do.UnWrap
|
||||||
}
|
}
|
||||||
|
if do, ok := f.(Wrapper); ok {
|
||||||
|
ft.WrapFs = do.WrapFs
|
||||||
|
ft.SetWrapper = do.SetWrapper
|
||||||
|
}
|
||||||
if do, ok := f.(DirCacheFlusher); ok {
|
if do, ok := f.(DirCacheFlusher); ok {
|
||||||
ft.DirCacheFlush = do.DirCacheFlush
|
ft.DirCacheFlush = do.DirCacheFlush
|
||||||
}
|
}
|
||||||
|
@ -438,7 +448,7 @@ func (ft *Features) Fill(f Fs) *Features {
|
||||||
//
|
//
|
||||||
// Only optional features which are implemented in both the original
|
// Only optional features which are implemented in both the original
|
||||||
// Fs AND the one passed in will be advertised. Any features which
|
// Fs AND the one passed in will be advertised. Any features which
|
||||||
// aren't in both will be set to false/nil, except for UnWrap which
|
// aren't in both will be set to false/nil, except for UnWrap/Wrap which
|
||||||
// will be left untouched.
|
// will be left untouched.
|
||||||
func (ft *Features) Mask(f Fs) *Features {
|
func (ft *Features) Mask(f Fs) *Features {
|
||||||
mask := f.Features()
|
mask := f.Features()
|
||||||
|
@ -487,7 +497,7 @@ func (ft *Features) Mask(f Fs) *Features {
|
||||||
return ft.DisableList(Config.DisableFeatures)
|
return ft.DisableList(Config.DisableFeatures)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap makes a Copy of the features passed in, overriding the UnWrap
|
// Wrap makes a Copy of the features passed in, overriding the UnWrap/Wrap
|
||||||
// method only if available in f.
|
// method only if available in f.
|
||||||
func (ft *Features) Wrap(f Fs) *Features {
|
func (ft *Features) Wrap(f Fs) *Features {
|
||||||
copy := new(Features)
|
copy := new(Features)
|
||||||
|
@ -495,9 +505,22 @@ func (ft *Features) Wrap(f Fs) *Features {
|
||||||
if do, ok := f.(UnWrapper); ok {
|
if do, ok := f.(UnWrapper); ok {
|
||||||
copy.UnWrap = do.UnWrap
|
copy.UnWrap = do.UnWrap
|
||||||
}
|
}
|
||||||
|
if do, ok := f.(Wrapper); ok {
|
||||||
|
copy.WrapFs = do.WrapFs
|
||||||
|
copy.SetWrapper = do.SetWrapper
|
||||||
|
}
|
||||||
return copy
|
return copy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WrapsFs adds extra information between `f` which wraps `w`
|
||||||
|
func (ft *Features) WrapsFs(f Fs, w Fs) *Features {
|
||||||
|
wFeatures := w.Features()
|
||||||
|
if wFeatures.WrapFs != nil && wFeatures.SetWrapper != nil {
|
||||||
|
wFeatures.SetWrapper(f)
|
||||||
|
}
|
||||||
|
return ft
|
||||||
|
}
|
||||||
|
|
||||||
// Purger is an optional interfaces for Fs
|
// Purger is an optional interfaces for Fs
|
||||||
type Purger interface {
|
type Purger interface {
|
||||||
// Purge all files in the root and the root directory
|
// Purge all files in the root and the root directory
|
||||||
|
@ -564,6 +587,14 @@ type UnWrapper interface {
|
||||||
UnWrap() Fs
|
UnWrap() Fs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wrapper is an optional interfaces for Fs
|
||||||
|
type Wrapper interface {
|
||||||
|
// Wrap returns the Fs that is wrapping this Fs
|
||||||
|
WrapFs() Fs
|
||||||
|
// SetWrapper sets the Fs that is wrapping this Fs
|
||||||
|
SetWrapper(f Fs)
|
||||||
|
}
|
||||||
|
|
||||||
// DirCacheFlusher is an optional interface for Fs
|
// DirCacheFlusher is an optional interface for Fs
|
||||||
type DirCacheFlusher interface {
|
type DirCacheFlusher interface {
|
||||||
// DirCacheFlush resets the directory cache - used in testing
|
// DirCacheFlush resets the directory cache - used in testing
|
||||||
|
|
Loading…
Reference in a new issue