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

lsjson,lsf: make sure metadata appears for directories

Nick Craig-Wood09953d77b58f
diff --git a/fs/operations/lsjson.go b/fs/operations/lsjson.go
index 6c94ee6ee..e95984809 100644
--- a/fs/operations/lsjson.go
+++ b/fs/operations/lsjson.go
@@ -194,6 +194,14 @@ func (lj *listJSON) entry(ctx context.Context, entry fs.DirEntry) (*ListJSONItem
}
item.Encrypted = path.Base(item.EncryptedPath)
}
+ if lj.opt.Metadata {
+ metadata, err := fs.GetMetadata(ctx, entry)
+ if err != nil {
+ fs.Errorf(entry, "Failed to read metadata: %v", err)
+ } else if metadata != nil {
+ item.Metadata = metadata
+ }
+ }
if do, ok := entry.(fs.IDer); ok {
item.ID = do.ID()
}
@@ -224,14 +232,6 @@ func (lj *listJSON) entry(ctx context.Context, entry fs.DirEntry) (*ListJSONItem
item.Tier = do.GetTier()
}
}
- if lj.opt.Metadata {
- metadata, err := fs.GetMetadata(ctx, x)
- if err != nil {
- fs.Errorf(x, "Failed to read metadata: %v", err)
- } else if metadata != nil {
- item.Metadata = metadata
- }
- }
default:
fs.Errorf(nil, "Unknown type %T in listing in ListJSON", entry)
}
diff --git a/fs/operations/lsjson_test.go b/fs/operations/lsjson_test.go
index 7fbe67318..75d4728ba 100644
--- a/fs/operations/lsjson_test.go
+++ b/fs/operations/lsjson_test.go
@@ -174,7 +174,7 @@ func TestListJSON(t *testing.T) {
}, {
name: "Metadata",
opt: operations.ListJSONOpt{
- FilesOnly: true,
+ FilesOnly: false,
Metadata: true,
},
want: []*operations.ListJSONItem{{
@@ -183,6 +183,10 @@ func TestListJSON(t *testing.T) {
Size: 5,
ModTime: operations.Timestamp{When: t1},
IsDir: false,
+ }, {
+ Path: "sub",
+ Name: "sub",
+ IsDir: true,
}},
},
} {
@@ -203,6 +207,15 @@ func TestListJSON(t *testing.T) {
} else {
assert.NotEqual(t, "", got[i].MimeType)
}
+ if test.opt.Metadata {
+ features := r.Fremote.Features()
+ if features.ReadMetadata && !got[i].IsDir {
+ assert.Greater(t, len(got[i].Metadata), 0, "Expecting metadata for file")
+ }
+ if features.ReadDirMetadata && got[i].IsDir {
+ assert.Greater(t, len(got[i].Metadata), 0, "Expecting metadata for dir")
+ }
+ }
if test.opt.ShowHash {
hashes := got[i].Hashes
assert.NotNil(t, hashes)