rc: fix operations/stat with trailing /

Before this change using operations/stat with a remote pointing to a
dir with a trailing / would return a null output rather than the
correct info.

This was because the directory was not found with a trailing slash in
the directory listing.

Fixes #6817
This commit is contained in:
Nick Craig-Wood 2023-03-07 18:02:03 +00:00
parent e042d9089f
commit fd83071b6b
2 changed files with 12 additions and 0 deletions

View file

@ -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 = ""

View file

@ -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",