1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-15 15:53:41 +00:00

Implement single file operations for all file systems

This commit is contained in:
Nick Craig-Wood
2014-05-05 19:52:52 +01:00
parent ca3752f824
commit 99695d57ab
9 changed files with 228 additions and 44 deletions

View File

@@ -188,8 +188,8 @@ func s3Connection(name string) (*s3.S3, error) {
}
// NewFsS3 contstructs an FsS3 from the path, bucket:path
func NewFs(name, path string) (fs.Fs, error) {
bucket, directory, err := s3ParsePath(path)
func NewFs(name, root string) (fs.Fs, error) {
bucket, directory, err := s3ParsePath(root)
if err != nil {
return nil, err
}
@@ -197,10 +197,6 @@ func NewFs(name, path string) (fs.Fs, error) {
if err != nil {
return nil, err
}
// FIXME - check if it is a file before doing this and make a limited fs
if directory != "" {
directory += "/"
}
f := &FsS3{
c: c,
bucket: bucket,
@@ -208,6 +204,23 @@ func NewFs(name, path string) (fs.Fs, error) {
perm: s3.Private, // FIXME need user to specify
root: directory,
}
if f.root != "" {
f.root += "/"
// Check to see if the object exists
_, err = f.b.Head(directory, nil)
if err == nil {
remote := path.Base(directory)
f.root = path.Dir(directory)
if f.root == "." {
f.root = ""
} else {
f.root += "/"
}
obj := f.NewFsObject(remote)
// return a Fs Limited to this object
return fs.NewLimited(f, obj), nil
}
}
return f, nil
}
@@ -328,7 +341,7 @@ func (f *FsS3) ListDir() fs.DirChan {
}
}()
} else {
// List the directories in the path in the container
// List the directories in the path in the bucket
go func() {
defer close(out)
f.list(true, func(remote string, object *s3.Key) {