diff --git a/lib/backup/azremote/azblob.go b/lib/backup/azremote/azblob.go index 2e9b5bf07..b2f559829 100644 --- a/lib/backup/azremote/azblob.go +++ b/lib/backup/azremote/azblob.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "path" "strings" "time" @@ -272,7 +273,7 @@ func (fs *FS) DeleteFile(filePath string) error { return nil } - path := fs.Dir + filePath + path := path.Join(fs.Dir, filePath) return fs.delete(path) } @@ -333,7 +334,7 @@ func (fs *FS) deleteObject(path string) error { // // The file is overwritten if it exists. func (fs *FS) CreateFile(filePath string, data []byte) error { - path := fs.Dir + filePath + path := path.Join(fs.Dir, filePath) bc := fs.clientForPath(path) ctx := context.Background() @@ -350,8 +351,7 @@ func (fs *FS) CreateFile(filePath string, data []byte) error { // HasFile returns true if filePath exists at fs. func (fs *FS) HasFile(filePath string) (bool, error) { - path := fs.Dir + filePath - + path := path.Join(fs.Dir, filePath) bc := fs.clientForPath(path) ctx := context.Background() diff --git a/lib/backup/common/fs.go b/lib/backup/common/fs.go index 42c051556..74fbf9080 100644 --- a/lib/backup/common/fs.go +++ b/lib/backup/common/fs.go @@ -45,15 +45,23 @@ type RemoteFS interface { // UploadPart must upload part p from r to RemoteFS. UploadPart(p Part, r io.Reader) error - // DeleteFile deletes filePath at RemoteFS + // DeleteFile deletes filePath at RemoteFS. + // + // filePath must use / as directory delimiters. DeleteFile(filePath string) error // CreateFile creates filePath at RemoteFS and puts data into it. + // + // filePath must use / as directory delimiters. CreateFile(filePath string, data []byte) error // HasFile returns true if filePath exists at RemoteFS. + // + // filePath must use / as directory delimiters. HasFile(filePath string) (bool, error) // ReadFile returns file contents at the given filePath. + // + // filePath must use / as directory delimiters. ReadFile(filePath string) ([]byte, error) } diff --git a/lib/backup/gcsremote/gcs.go b/lib/backup/gcsremote/gcs.go index ce7ece62a..bca2c4fac 100644 --- a/lib/backup/gcsremote/gcs.go +++ b/lib/backup/gcsremote/gcs.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "path" "strings" "time" @@ -211,7 +212,7 @@ func (fs *FS) object(p common.Part) *storage.ObjectHandle { // // The function does nothing if the filePath doesn't exists. func (fs *FS) DeleteFile(filePath string) error { - path := fs.Dir + filePath + path := path.Join(fs.Dir, filePath) return fs.delete(path) } @@ -265,7 +266,7 @@ func (fs *FS) deleteObject(path string) error { // // The file is overwritten if it exists. func (fs *FS) CreateFile(filePath string, data []byte) error { - path := fs.Dir + filePath + path := path.Join(fs.Dir, filePath) o := fs.bkt.Object(path) ctx := context.Background() w := o.NewWriter(ctx) @@ -286,7 +287,7 @@ func (fs *FS) CreateFile(filePath string, data []byte) error { // HasFile returns ture if filePath exists at fs. func (fs *FS) HasFile(filePath string) (bool, error) { - path := fs.Dir + filePath + path := path.Join(fs.Dir, filePath) o := fs.bkt.Object(path) ctx := context.Background() _, err := o.Attrs(ctx) @@ -301,7 +302,8 @@ func (fs *FS) HasFile(filePath string) (bool, error) { // ReadFile returns the content of filePath at fs. func (fs *FS) ReadFile(filePath string) ([]byte, error) { - o := fs.bkt.Object(fs.Dir + filePath) + path := path.Join(fs.Dir, filePath) + o := fs.bkt.Object(path) ctx := context.Background() r, err := o.NewReader(ctx) if err != nil { diff --git a/lib/backup/s3remote/s3.go b/lib/backup/s3remote/s3.go index 45bc8cfc1..fc37e86ed 100644 --- a/lib/backup/s3remote/s3.go +++ b/lib/backup/s3remote/s3.go @@ -5,6 +5,7 @@ import ( "context" "fmt" "io" + "path" "strings" "github.com/aws/aws-sdk-go-v2/aws" @@ -53,7 +54,7 @@ type FS struct { // Path to S3 configs file. ConfigFilePath string - // GCS bucket to use. + // S3 bucket to use. Bucket string // Directory in the bucket to write to. @@ -292,7 +293,7 @@ func (fs *FS) DeleteFile(filePath string) error { return nil } - path := fs.Dir + filePath + path := path.Join(fs.Dir, filePath) return fs.delete(path) } @@ -344,7 +345,7 @@ func (fs *FS) deleteObjectWithVersions(path string) error { // // The file is overwritten if it already exists. func (fs *FS) CreateFile(filePath string, data []byte) error { - path := fs.Dir + filePath + path := path.Join(fs.Dir, filePath) sr := &statReader{ r: bytes.NewReader(data), } @@ -367,7 +368,7 @@ func (fs *FS) CreateFile(filePath string, data []byte) error { // HasFile returns true if filePath exists at fs. func (fs *FS) HasFile(filePath string) (bool, error) { - path := fs.Dir + filePath + path := path.Join(fs.Dir, filePath) input := &s3.GetObjectInput{ Bucket: aws.String(fs.Bucket), Key: aws.String(path), @@ -387,7 +388,7 @@ func (fs *FS) HasFile(filePath string) (bool, error) { // ReadFile returns the content of filePath at fs. func (fs *FS) ReadFile(filePath string) ([]byte, error) { - p := fs.Dir + filePath + p := path.Join(fs.Dir, filePath) input := &s3.GetObjectInput{ Bucket: aws.String(fs.Bucket), Key: aws.String(p),