2014-05-05 18:52:52 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
// Limited defines a Fs which can only return the Objects passed in
|
|
|
|
// from the Fs passed in
|
2014-05-05 18:52:52 +00:00
|
|
|
type Limited struct {
|
|
|
|
objects []Object
|
|
|
|
fs Fs
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewLimited maks a limited Fs limited to the objects passed in
|
|
|
|
func NewLimited(fs Fs, objects ...Object) Fs {
|
|
|
|
f := &Limited{
|
|
|
|
objects: objects,
|
|
|
|
fs: fs,
|
|
|
|
}
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
// Name is name of the remote (as passed into NewFs)
|
2015-08-22 15:53:11 +00:00
|
|
|
func (f *Limited) Name() string {
|
|
|
|
return f.fs.Name() // return name of underlying remote
|
|
|
|
}
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
// Root is the root of the remote (as passed into NewFs)
|
2015-09-01 19:45:27 +00:00
|
|
|
func (f *Limited) Root() string {
|
|
|
|
return f.fs.Root() // return root of underlying remote
|
|
|
|
}
|
|
|
|
|
2014-05-05 18:52:52 +00:00
|
|
|
// String returns a description of the FS
|
|
|
|
func (f *Limited) String() string {
|
|
|
|
return fmt.Sprintf("%s limited to %d objects", f.fs.String(), len(f.objects))
|
|
|
|
}
|
|
|
|
|
|
|
|
// List the Fs into a channel
|
2016-04-23 20:46:52 +00:00
|
|
|
func (f *Limited) List(opts ListOpts, dir string) {
|
2016-04-21 19:06:21 +00:00
|
|
|
defer opts.Finished()
|
2016-04-23 20:46:52 +00:00
|
|
|
if dir != "" {
|
|
|
|
opts.SetError(ErrorListOnlyRoot)
|
|
|
|
return
|
|
|
|
}
|
2016-04-21 19:06:21 +00:00
|
|
|
for _, obj := range f.objects {
|
|
|
|
if opts.Add(obj) {
|
|
|
|
return
|
2014-05-05 18:52:52 +00:00
|
|
|
}
|
2016-04-21 19:06:21 +00:00
|
|
|
}
|
2014-05-05 18:52:52 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
// NewFsObject finds the Object at remote. Returns nil if can't be found
|
2014-05-05 18:52:52 +00:00
|
|
|
func (f *Limited) NewFsObject(remote string) Object {
|
|
|
|
for _, obj := range f.objects {
|
|
|
|
if obj.Remote() == remote {
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put in to the remote path with the modTime given of the given size
|
|
|
|
//
|
|
|
|
// May create the object even if it returns an error - if so
|
|
|
|
// will return the object and the error, otherwise will return
|
|
|
|
// nil and the error
|
2016-02-18 11:35:25 +00:00
|
|
|
func (f *Limited) Put(in io.Reader, src ObjectInfo) (Object, error) {
|
|
|
|
remote := src.Remote()
|
2014-05-05 18:52:52 +00:00
|
|
|
obj := f.NewFsObject(remote)
|
|
|
|
if obj == nil {
|
|
|
|
return nil, fmt.Errorf("Can't create %q in limited fs", remote)
|
|
|
|
}
|
2016-02-18 11:35:25 +00:00
|
|
|
return obj, obj.Update(in, src)
|
2014-05-05 18:52:52 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
// Mkdir make the directory (container, bucket)
|
2014-05-05 18:52:52 +00:00
|
|
|
func (f *Limited) Mkdir() error {
|
|
|
|
// All directories are already made - just ignore
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-22 17:47:16 +00:00
|
|
|
// Rmdir removes the directory (container, bucket) if empty
|
2014-05-05 18:52:52 +00:00
|
|
|
func (f *Limited) Rmdir() error {
|
2015-08-25 18:16:25 +00:00
|
|
|
// Ignore this in a limited fs
|
|
|
|
return nil
|
2014-05-05 18:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Precision of the ModTimes in this Fs
|
|
|
|
func (f *Limited) Precision() time.Duration {
|
|
|
|
return f.fs.Precision()
|
|
|
|
}
|
|
|
|
|
2016-01-11 12:39:33 +00:00
|
|
|
// Hashes returns the supported hash sets.
|
|
|
|
func (f *Limited) Hashes() HashSet {
|
|
|
|
return f.fs.Hashes()
|
|
|
|
}
|
|
|
|
|
2015-02-14 18:48:08 +00:00
|
|
|
// Copy src to this remote using server side copy operations.
|
|
|
|
//
|
|
|
|
// This is stored with the remote path given
|
|
|
|
//
|
|
|
|
// It returns the destination Object and a possible error
|
|
|
|
//
|
|
|
|
// Will only be called if src.Fs().Name() == f.Name()
|
|
|
|
//
|
|
|
|
// If it isn't possible then return fs.ErrorCantCopy
|
|
|
|
func (f *Limited) Copy(src Object, remote string) (Object, error) {
|
|
|
|
fCopy, ok := f.fs.(Copier)
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrorCantCopy
|
|
|
|
}
|
|
|
|
return fCopy.Copy(src, remote)
|
|
|
|
}
|
|
|
|
|
2015-11-08 14:15:28 +00:00
|
|
|
// Move src to this remote using server side move operations.
|
|
|
|
//
|
|
|
|
// This is stored with the remote path given
|
|
|
|
//
|
|
|
|
// It returns the destination Object and a possible error
|
|
|
|
//
|
|
|
|
// Will only be called if src.Fs().Name() == f.Name()
|
|
|
|
//
|
|
|
|
// If it isn't possible then return fs.ErrorCantMove
|
|
|
|
func (f *Limited) Move(src Object, remote string) (Object, error) {
|
|
|
|
fMove, ok := f.fs.(Mover)
|
|
|
|
if !ok {
|
|
|
|
return nil, ErrorCantMove
|
|
|
|
}
|
|
|
|
return fMove.Move(src, remote)
|
|
|
|
}
|
|
|
|
|
2015-11-08 15:27:55 +00:00
|
|
|
// UnWrap returns the Fs that this Fs is wrapping
|
|
|
|
func (f *Limited) UnWrap() Fs {
|
|
|
|
return f.fs
|
|
|
|
}
|
|
|
|
|
2014-05-05 18:52:52 +00:00
|
|
|
// Check the interfaces are satisfied
|
2015-11-08 14:15:28 +00:00
|
|
|
var (
|
2015-11-08 15:27:55 +00:00
|
|
|
_ Fs = (*Limited)(nil)
|
|
|
|
_ Copier = (*Limited)(nil)
|
|
|
|
_ Mover = (*Limited)(nil)
|
|
|
|
_ UnWrapper = (*Limited)(nil)
|
2015-11-08 14:15:28 +00:00
|
|
|
)
|