Skip to content

Commit

Permalink
Merge branch 'ftp-change-dir'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Linz committed Jun 15, 2018
2 parents b00af64 + be52bce commit b7a5de0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 11 additions & 5 deletions server/s3_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/url"
"path/filepath"
"reflect"
"time"

Expand Down Expand Up @@ -33,6 +34,7 @@ type S3Driver struct {
hostname string
bucketName string
bucketURL *url.URL
cwd string
}

func intoAwsError(err error) awserr.Error {
Expand Down Expand Up @@ -109,10 +111,14 @@ func (d S3Driver) Stat(key string) (ftp.FileInfo, error) {
}

// ChangeDir will always return an error because there is no such operation for a cloud object storage.
func (d S3Driver) ChangeDir(key string) error {
// There is no s3 equivalent
logrus.Warn("ChangeDir (CD) is not supported.")
return notEnabled("CD")
//
// To allow uploading into "subdirectories" of a bucket a path change is simulated by keeping track of `CD` calls.
// In FTP only a single directory level will be changed at a time, i.e. `CD /foo/bar` will result in two calls, `CD /foo` and `CD /foo/bar`.
// There is no server side logic to be implement because relative paths are handled by the client, at least is how lftp and Filezilla operated.
func (d S3Driver) ChangeDir(path string) error {
d.cwd = path
logrus.Debugf("Changed into path: %q", d.cwd)
return nil
}

// ListDir call the callback function with object metadata for each object located under prefix `key`.
Expand Down Expand Up @@ -284,7 +290,7 @@ func (d S3Driver) PutFile(key string, data io.Reader, appendMode bool) (int64, e
// fqdn returns the fully qualified name for a object with key `key`.
func (d S3Driver) fqdn(key string) string {
u := d.bucketURL
u.Path = key
u.Path = filepath.Join(d.cwd, key)
return u.String()
}

Expand Down
8 changes: 8 additions & 0 deletions server/s3_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ func TestIfPutFileChecksForNilReader(t *testing.T) {
}
}

func TestChangeDirectory(t *testing.T) {
// I can't test the value of the drivers 'cwd'
// because its methods need to be defined on a value receiver,
// i.e. that sideffect changes, like setting the cwd on a change-dir call,
// are not reflected in the test struct.
t.Log("ToDo")
}

func TestS3Driver(t *testing.T) {
logrus.SetLevel(logrus.PanicLevel)
bucketName := "test-bucket"
Expand Down

0 comments on commit b7a5de0

Please sign in to comment.