MCPcopy Create free account
hub / github.com/apache/cloudberry / listBucket

Method listBucket

gpcontrib/gpcloud/src/s3interface.cpp:293–338  ·  view source on GitHub ↗

ListBucket lists all keys in given bucket with given prefix. Return NULL when there is failure due to network instability or service unstable, so that caller could retry. Caller should delete returned object.

Source from the content-addressed store, hash-verified

291//
292// Caller should delete returned object.
293ListBucketResult S3InterfaceService::listBucket(S3Url &s3Url) {
294 ListBucketResult result;
295
296 string marker = "";
297 string encodedPrefix = s3Url.getPrefix();
298 FindAndReplace(encodedPrefix, "/", "%2F");
299 do {
300 // To get next set(up to 1000) keys in one iteration.
301 // S3 requires query parameters specified alphabetically.
302
303 // marker and prefix are used as the values of query parameters here
304 // so URI encode their whole string, "/" also.
305
306 // transfer /bucket/prefix to /bucket/?prefix=prefix because we need to "GET" a real thing
307 stringstream querySs;
308 if (!marker.empty()) {
309 querySs << "marker=" << UriEncode(marker);
310 }
311
312 if (!encodedPrefix.empty()) {
313 querySs << (marker.empty() ? "prefix=" : "&prefix=") << encodedPrefix;
314 }
315
316 s3Url.setPrefix("");
317 string queryStr = querySs.str();
318
319 Response resp = getBucketResponse(s3Url, queryStr);
320
321 if (resp.getStatus() == RESPONSE_OK) {
322 xmlParserCtxtPtr xmlContext = getXMLContext(resp);
323 XMLContextHolder holder(xmlContext);
324 if (parseBucketXML(&result, xmlContext, marker)) {
325 continue;
326 }
327 } else if (resp.getStatus() == RESPONSE_ERROR) {
328 S3MessageParser s3msg(resp);
329 S3_DIE(S3LogicError, s3msg.getCode(), s3msg.getMessage());
330 } else {
331 S3_DIE(S3RuntimeError, "unexpected response status");
332 }
333
334 return result;
335 } while (!marker.empty());
336
337 return result;
338}
339
340uint64_t S3InterfaceService::fetchData(uint64_t offset, S3VectorUInt8 &data, uint64_t len,
341 const S3Url &s3Url) {

Callers 2

TEST_FFunction · 0.80
openMethod · 0.80

Calls 7

FindAndReplaceFunction · 0.85
UriEncodeFunction · 0.85
getStatusMethod · 0.80
setPrefixMethod · 0.45
strMethod · 0.45
getCodeMethod · 0.45
getMessageMethod · 0.45

Tested by 1

TEST_FFunction · 0.64