From fd83071b6b2b49042fc7f423aab08997e270adec Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 7 Mar 2023 18:02:03 +0000 Subject: [PATCH] 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 --- fs/operations/lsjson.go | 3 +++ fs/operations/lsjson_test.go | 9 +++++++++ 2 files changed, 12 insertions(+) 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",