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 operations/stat with trailing /

Nick Craig-Woodfd83071b6b2b
diff --git a/fs/operations/lsjson.go b/fs/operations/lsjson.go
index 067681956..176c2cb9f 100644
--- a/fs/operations/lsjson.go
+++ b/fs/operations/lsjson.go
@@ -314,6 +314,9 @@ func StatJSON(ctx context.Context, fsrc fs.Fs, remote string, opt *ListJSONOpt)
}
}
// Must be a directory here
+ //
+ // Remove trailing / as rclone listings won't have them
+ remote = strings.TrimRight(remote, "/")
parent := path.Dir(remote)
if parent == "." || parent == "/" {
parent = ""
diff --git a/fs/operations/lsjson_test.go b/fs/operations/lsjson_test.go
index c9be36173..7fbe67318 100644
--- a/fs/operations/lsjson_test.go
+++ b/fs/operations/lsjson_test.go
@@ -292,6 +292,15 @@ func TestStatJSON(t *testing.T) {
Name: "sub",
IsDir: true,
},
+ }, {
+ name: "DirWithTrailingSlash",
+ remote: "sub/",
+ opt: operations.ListJSONOpt{},
+ want: &operations.ListJSONItem{
+ Path: "sub",
+ Name: "sub",
+ IsDir: true,
+ },
}, {
name: "File",
remote: "file1",