mirror of https://github.com/rclone/rclone.git
rc: fix rc/uploadfile only working for root of the fs
This commit is contained in:
parent
01280798e9
commit
61c7ea4085
|
@ -6,6 +6,7 @@ import (
|
||||||
"mime"
|
"mime"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -253,7 +254,7 @@ func rcSingleCommand(ctx context.Context, in rc.Params, name string, noRemote bo
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if p.FileName() != "" {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -450,11 +450,13 @@ func TestUploadFile(t *testing.T) {
|
||||||
testFileName := "test.txt"
|
testFileName := "test.txt"
|
||||||
testFileContent := "Hello World"
|
testFileContent := "Hello World"
|
||||||
r.WriteFile(testFileName, testFileContent, t1)
|
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))
|
currentFile, err := os.Open(path.Join(r.LocalName, testFileName))
|
||||||
require.NoError(t, err)
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
httpReq := httptest.NewRequest("POST", "/", formReader)
|
httpReq := httptest.NewRequest("POST", "/", formReader)
|
||||||
|
@ -469,7 +471,30 @@ func TestUploadFile(t *testing.T) {
|
||||||
_, err = call.Fn(context.Background(), in)
|
_, err = call.Fn(context.Background(), in)
|
||||||
require.NoError(t, err)
|
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
|
// operations/command: Runs a backend command
|
||||||
|
|
Loading…
Reference in New Issue