forked from TrueCloudLab/rclone
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:
parent
e042d9089f
commit
fd83071b6b
2 changed files with 12 additions and 0 deletions
|
@ -314,6 +314,9 @@ func StatJSON(ctx context.Context, fsrc fs.Fs, remote string, opt *ListJSONOpt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Must be a directory here
|
// Must be a directory here
|
||||||
|
//
|
||||||
|
// Remove trailing / as rclone listings won't have them
|
||||||
|
remote = strings.TrimRight(remote, "/")
|
||||||
parent := path.Dir(remote)
|
parent := path.Dir(remote)
|
||||||
if parent == "." || parent == "/" {
|
if parent == "." || parent == "/" {
|
||||||
parent = ""
|
parent = ""
|
||||||
|
|
|
@ -292,6 +292,15 @@ func TestStatJSON(t *testing.T) {
|
||||||
Name: "sub",
|
Name: "sub",
|
||||||
IsDir: true,
|
IsDir: true,
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
name: "DirWithTrailingSlash",
|
||||||
|
remote: "sub/",
|
||||||
|
opt: operations.ListJSONOpt{},
|
||||||
|
want: &operations.ListJSONItem{
|
||||||
|
Path: "sub",
|
||||||
|
Name: "sub",
|
||||||
|
IsDir: true,
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
name: "File",
|
name: "File",
|
||||||
remote: "file1",
|
remote: "file1",
|
||||||
|
|
Loading…
Reference in a new issue