Add Name() to Fs interface to return name as passed to NewFs

This commit is contained in:
Nick Craig-Wood 2015-08-22 16:53:11 +01:00
parent 0c6f816a49
commit fedf81c2b7
8 changed files with 51 additions and 1 deletions

View File

@ -74,6 +74,7 @@ func init() {
// FsDrive represents a remote drive server
type FsDrive struct {
name string // name of this remote
svc *drive.Service // the connection to the drive server
root string // the path we are working on
client *http.Client // authorized client
@ -146,6 +147,11 @@ func (m *dirCache) Flush() {
// ------------------------------------------------------------
// The name of the remote (as passed into NewFs)
func (f *FsDrive) Name() string {
return f.name
}
// String converts this FsDrive to a string
func (f *FsDrive) String() string {
return fmt.Sprintf("Google drive root '%s'", f.root)
@ -332,6 +338,7 @@ func NewFs(name, path string) (fs.Fs, error) {
}
f := &FsDrive{
name: name,
root: root,
dirCache: newDirCache(),
pacer: make(chan struct{}, 1),

View File

@ -104,6 +104,7 @@ func configHelper(name string) {
// FsDropbox represents a remote dropbox server
type FsDropbox struct {
name string // name of this remote
db *dropbox.Dropbox // the connection to the dropbox server
root string // the path we are working on
slashRoot string // root with "/" prefix, lowercase
@ -121,6 +122,11 @@ type FsObjectDropbox struct {
// ------------------------------------------------------------
// The name of the remote (as passed into NewFs)
func (f *FsDropbox) Name() string {
return f.name
}
// String converts this FsDropbox to a string
func (f *FsDropbox) String() string {
return fmt.Sprintf("Dropbox root '%s'", f.root)
@ -148,7 +154,8 @@ func newDropbox(name string) *dropbox.Dropbox {
func NewFs(name, root string) (fs.Fs, error) {
db := newDropbox(name)
f := &FsDropbox{
db: db,
name: name,
db: db,
}
f.setRoot(root)

View File

@ -63,6 +63,9 @@ func Register(info *FsInfo) {
// A Filesystem, describes the local filesystem and the remote object store
type Fs interface {
// The name of the remote (as passed into NewFs)
Name() string
// String returns a description of the FS
String() string

View File

@ -21,6 +21,11 @@ func NewLimited(fs Fs, objects ...Object) Fs {
return f
}
// The name of the remote (as passed into NewFs)
func (f *Limited) Name() string {
return f.fs.Name() // return name of underlying remote
}
// 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))

View File

@ -112,6 +112,7 @@ func init() {
// FsStorage represents a remote storage server
type FsStorage struct {
name string // name of this remote
svc *storage.Service // the connection to the storage server
client *http.Client // authorized client
bucket string // the bucket we are working on
@ -135,6 +136,11 @@ type FsObjectStorage struct {
// ------------------------------------------------------------
// The name of the remote (as passed into NewFs)
func (f *FsStorage) Name() string {
return f.name
}
// String converts this FsStorage to a string
func (f *FsStorage) String() string {
if f.root == "" {
@ -171,6 +177,7 @@ func NewFs(name, root string) (fs.Fs, error) {
}
f := &FsStorage{
name: name,
bucket: bucket,
root: directory,
projectNumber: fs.ConfigFile.MustValue(name, "project_number"),

View File

@ -33,6 +33,7 @@ func init() {
// FsLocal represents a local filesystem rooted at root
type FsLocal struct {
name string // the name of the remote
root string // The root directory
precisionOk sync.Once // Whether we need to read the precision
precision time.Duration // precision of local filesystem
@ -54,6 +55,7 @@ type FsObjectLocal struct {
func NewFs(name, root string) (fs.Fs, error) {
root = filepath.ToSlash(path.Clean(root))
f := &FsLocal{
name: name,
root: root,
warned: make(map[string]struct{}),
}
@ -70,6 +72,11 @@ func NewFs(name, root string) (fs.Fs, error) {
return f, nil
}
// The name of the remote (as passed into NewFs)
func (f *FsLocal) Name() string {
return f.name
}
// String converts this FsLocal to a string
func (f *FsLocal) String() string {
return fmt.Sprintf("Local file system at %s", f.root)

View File

@ -128,6 +128,7 @@ const (
// FsS3 represents a remote s3 server
type FsS3 struct {
name string // the name of the remote
c *s3.S3 // the connection to the s3 server
bucket string // the bucket we are working on
perm string // permissions for new buckets / objects
@ -151,6 +152,11 @@ type FsObjectS3 struct {
// ------------------------------------------------------------
// The name of the remote (as passed into NewFs)
func (f *FsS3) Name() string {
return f.name
}
// String converts this FsS3 to a string
func (f *FsS3) String() string {
if f.root == "" {
@ -235,6 +241,7 @@ func NewFs(name, root string) (fs.Fs, error) {
return nil, err
}
f := &FsS3{
name: name,
c: c,
bucket: bucket,
// FIXME perm: s3.Private, // FIXME need user to specify

View File

@ -58,6 +58,7 @@ func init() {
// FsSwift represents a remote swift server
type FsSwift struct {
name string // name of this remote
c swift.Connection // the connection to the swift server
container string // the container we are working on
root string // the path we are working on if any
@ -75,6 +76,11 @@ type FsObjectSwift struct {
// ------------------------------------------------------------
// The name of the remote (as passed into NewFs)
func (f *FsSwift) Name() string {
return f.name
}
// String converts this FsSwift to a string
func (f *FsSwift) String() string {
if f.root == "" {
@ -141,6 +147,7 @@ func NewFs(name, root string) (fs.Fs, error) {
return nil, err
}
f := &FsSwift{
name: name,
c: *c,
container: container,
root: directory,