forked from TrueCloudLab/rclone
operations: fix lsjson --stat on root directories of bucket based backends
This commit is contained in:
parent
f50537b64b
commit
54da6154c4
2 changed files with 34 additions and 9 deletions
|
@ -264,6 +264,21 @@ func StatJSON(ctx context.Context, fsrc fs.Fs, remote string, opt *ListJSONOpt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Root is always a directory. When we have a NewDirEntry
|
||||||
|
// primitive we need to call it, but for now this will do.
|
||||||
|
if remote == "" {
|
||||||
|
if !lj.dirs {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
// Check the root directory exists
|
||||||
|
_, err := fsrc.List(ctx, "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return lj.entry(ctx, fs.NewDir("", time.Now()))
|
||||||
|
}
|
||||||
|
|
||||||
// Could be a file or a directory here
|
// Could be a file or a directory here
|
||||||
if lj.files {
|
if lj.files {
|
||||||
// NewObject can return the sentinel errors ErrorObjectNotFound or ErrorIsDir
|
// NewObject can return the sentinel errors ErrorObjectNotFound or ErrorIsDir
|
||||||
|
@ -288,14 +303,6 @@ func StatJSON(ctx context.Context, fsrc fs.Fs, remote string, opt *ListJSONOpt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Must be a directory here
|
// Must be a directory here
|
||||||
if remote == "" {
|
|
||||||
// Check the root directory exists
|
|
||||||
_, err := fsrc.List(ctx, "")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return lj.entry(ctx, fs.NewDir("", time.Now()))
|
|
||||||
}
|
|
||||||
parent := path.Dir(remote)
|
parent := path.Dir(remote)
|
||||||
if parent == "." || parent == "/" {
|
if parent == "." || parent == "/" {
|
||||||
parent = ""
|
parent = ""
|
||||||
|
|
|
@ -133,7 +133,7 @@ func TestListJSON(t *testing.T) {
|
||||||
IsDir: false,
|
IsDir: false,
|
||||||
}},
|
}},
|
||||||
}, {
|
}, {
|
||||||
name: "NoModTime",
|
name: "NoMimeType",
|
||||||
opt: operations.ListJSONOpt{
|
opt: operations.ListJSONOpt{
|
||||||
FilesOnly: true,
|
FilesOnly: true,
|
||||||
NoMimeType: true,
|
NoMimeType: true,
|
||||||
|
@ -254,6 +254,24 @@ func TestStatJSON(t *testing.T) {
|
||||||
Name: "",
|
Name: "",
|
||||||
IsDir: true,
|
IsDir: true,
|
||||||
},
|
},
|
||||||
|
}, {
|
||||||
|
name: "RootFilesOnly",
|
||||||
|
remote: "",
|
||||||
|
opt: operations.ListJSONOpt{
|
||||||
|
FilesOnly: true,
|
||||||
|
},
|
||||||
|
want: nil,
|
||||||
|
}, {
|
||||||
|
name: "RootDirsOnly",
|
||||||
|
remote: "",
|
||||||
|
opt: operations.ListJSONOpt{
|
||||||
|
DirsOnly: true,
|
||||||
|
},
|
||||||
|
want: &operations.ListJSONItem{
|
||||||
|
Path: "",
|
||||||
|
Name: "",
|
||||||
|
IsDir: true,
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
name: "Dir",
|
name: "Dir",
|
||||||
remote: "sub",
|
remote: "sub",
|
||||||
|
|
Loading…
Add table
Reference in a new issue