Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

rc: fix rc/uploadfile only working for root of the fs

Chaitanya Bankanhal61c7ea4085e0
diff --git a/fs/operations/rc.go b/fs/operations/rc.go
index 672dfc31d..ce66f353a 100644
--- a/fs/operations/rc.go
+++ b/fs/operations/rc.go
@@ -6,6 +6,7 @@ import (
"mime"
"mime/multipart"
"net/http"
+ "path"
"strings"
"time"
@@ -253,7 +254,7 @@ func rcSingleCommand(ctx context.Context, in rc.Params, name string, noRemote bo
return nil, err
}
if p.FileName() != "" {
- obj, err := Rcat(ctx, f, p.FileName(), p, time.Now())
+ obj, err := Rcat(ctx, f, path.Join(remote, p.FileName()), p, time.Now())
if err != nil {
return nil, err
}
diff --git a/fs/operations/rc_test.go b/fs/operations/rc_test.go
index 7635deadb..9427fc621 100644
--- a/fs/operations/rc_test.go
+++ b/fs/operations/rc_test.go
@@ -450,11 +450,13 @@ func TestUploadFile(t *testing.T) {
testFileName := "test.txt"
testFileContent := "Hello World"
r.WriteFile(testFileName, testFileContent, t1)
+ testItem1 := fstest.NewItem(testFileName, testFileContent, t1)
+ testItem2 := fstest.NewItem(path.Join("subdir", testFileName), testFileContent, t1)
currentFile, err := os.Open(path.Join(r.LocalName, testFileName))
require.NoError(t, err)
- formReader, contentType, _, err := rest.MultipartUpload(currentFile, url.Values{}, "content", testFileName)
+ formReader, contentType, _, err := rest.MultipartUpload(currentFile, url.Values{}, "file", testFileName)
require.NoError(t, err)
httpReq := httptest.NewRequest("POST", "/", formReader)
@@ -469,7 +471,30 @@ func TestUploadFile(t *testing.T) {
_, err = call.Fn(context.Background(), in)
require.NoError(t, err)
- fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{fstest.NewItem(testFileName, testFileContent, t1)}, nil, fs.ModTimeNotSupported)
+ fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{testItem1}, nil, fs.ModTimeNotSupported)
+
+ assert.NoError(t, r.Fremote.Mkdir(context.Background(), "subdir"))
+
+ currentFile, err = os.Open(path.Join(r.LocalName, testFileName))
+ require.NoError(t, err)
+
+ formReader, contentType, _, err = rest.MultipartUpload(currentFile, url.Values{}, "file", testFileName)
+ require.NoError(t, err)
+
+ httpReq = httptest.NewRequest("POST", "/", formReader)
+ httpReq.Header.Add("Content-Type", contentType)
+
+ in = rc.Params{
+ "_request": httpReq,
+ "fs": r.FremoteName,
+ "remote": "subdir",
+ }
+
+ _, err = call.Fn(context.Background(), in)
+ require.NoError(t, err)
+
+ fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{testItem1, testItem2}, nil, fs.ModTimeNotSupported)
+
}
// operations/command: Runs a backend command