Просмотр исходного кода

fix: listFiles carries each record's metadata map (it was always empty)

The ListFiles handler copied every FileInfo field except metadata, so a
listing showed none while getFileInfo returned it. Reported by
smartbotic-vectorapi. test_file_store +2; with the copy reverted 1 fails.
fszontagh 6 дней назад
Родитель
Сommit
b1b4ed9cdf

+ 8 - 0
CHANGELOG.md

@@ -12,6 +12,14 @@ consumer-facing usage is in `docs/integration-guide.md`.
 
 ## Unreleased
 
+### Fixed
+
+- **[server]** `listFiles` returned every record with an empty `metadata` map
+  (`getFileInfo` always carried it): the `ListFiles` handler never copied the
+  map. A listing now carries each record's metadata, so a lookup by a metadata
+  value no longer needs one `getFileInfo` per row. The client already read the
+  field; no client change.
+
 ## 2.21.7 - 2026-11-20 (bug fix, server only)
 
 ### Fixed

+ 3 - 0
docs/integration-guide.md

@@ -2082,6 +2082,9 @@ auto files = db.listFiles(
     /*limit=*/100, /*offset=*/0,
     /*checksum=*/"",
     /*name=*/"photo.jpg");
+// Each FileRecord carries its metadata map. Servers up to 2.21.7 sent it
+// empty in a listing (getFileInfo always had it): a consumer that must work
+// against those fetches getFileInfo for a listed record whose map is empty.
 
 // Delete
 db.deleteFile(result.id);

+ 5 - 0
service/src/database_grpc_impl.cpp

@@ -3147,6 +3147,11 @@ grpc::Status DatabaseGrpcImpl::ListFiles(
         file->set_is_public(info.isPublic);
         file->set_project(info.project);
         file->set_expires_at(info.expiresAt);
+        // After 2.21.7: the listing never carried the metadata map (GetFileInfo
+        // always did), so every listed record read as having none.
+        for (const auto& [key, value] : info.metadata) {
+            (*file->mutable_metadata())[key] = value;
+        }
     }
 
     // v2.8.0 — total_count must reflect what the caller may actually SEE, but it

+ 17 - 0
tests/load_test/test_file_store.cpp

@@ -108,6 +108,23 @@ static void beforeRestart() {
            "a path as the project: InvalidArgument, invalid_project, got '" + d2.reason + "'");
     }
 
+    // ---- after 2.21.7: listFiles carries the metadata map, as getFileInfo does
+    {
+        auto m = meta("aliased.bin");
+        m.metadata["path"] = "/img/logo.png";
+        m.metadata["owner"] = "web";
+        auto up = c.uploadFile(bytes(100, 6), m);
+        auto listed = c.listFiles("", "", 100, 0, "", "aliased.bin");
+        ck(listed.files.size() == 1 &&
+           listed.files[0].metadata.size() == 2 &&
+           listed.files[0].metadata.count("path") &&
+           listed.files[0].metadata.at("path") == "/img/logo.png",
+           "listFiles returns the stored metadata map");
+        auto info = c.getFileInfo(up.id);
+        ck(info && info->metadata.count("owner") && info->metadata.at("owner") == "web",
+           "getFileInfo returns the same metadata");
+    }
+
     // ---- dropProject deletes the project's files, not shared content
     Client admin({.address = ADDR, .project = "default"});
     admin.connect();