az/get object by prefix: catch all cpp eceptions

This commit is contained in:
Minglei Jin 2024-11-05 14:34:20 +08:00
parent 90d1e014db
commit 7316b339b6
1 changed files with 18 additions and 3 deletions

View File

@ -32,7 +32,6 @@ void azEnd() {}
#include <azure/storage/blobs.hpp> #include <azure/storage/blobs.hpp>
#include "td_block_blob_client.hpp" #include "td_block_blob_client.hpp"
// Add appropriate using namespace directives
using namespace Azure::Storage; using namespace Azure::Storage;
using namespace Azure::Storage::Blobs; using namespace Azure::Storage::Blobs;
@ -223,7 +222,6 @@ static int32_t azPutObjectFromFileOffsetImpl(const char *file, const char *objec
uint8_t blobContent[] = "Hello Azure!"; uint8_t blobContent[] = "Hello Azure!";
// Create the block blob client // Create the block blob client
// BlockBlobClient blobClient = containerClient.GetBlockBlobClient(blobName); // BlockBlobClient blobClient = containerClient.GetBlockBlobClient(blobName);
// TDBlockBlobClient blobClient(containerClient.GetBlobClient(blobName));
TDBlockBlobClient blobClient(containerClient.GetBlobClient(object_name)); TDBlockBlobClient blobClient(containerClient.GetBlobClient(object_name));
blobClient.UploadFrom(file, offset, size); blobClient.UploadFrom(file, offset, size);
@ -467,7 +465,7 @@ int32_t azGetObjectToFile(const char *object_name, const char *fileName) {
TAOS_RETURN(code); TAOS_RETURN(code);
} }
int32_t azGetObjectsByPrefix(const char *prefix, const char *path) { static int32_t azGetObjectsByPrefixImpl(const char *prefix, const char *path) {
const std::string delimiter = "/"; const std::string delimiter = "/";
std::string accountName = tsS3AccessKeyId[0]; std::string accountName = tsS3AccessKeyId[0];
std::string accountKey = tsS3AccessKeySecret[0]; std::string accountKey = tsS3AccessKeySecret[0];
@ -514,6 +512,23 @@ int32_t azGetObjectsByPrefix(const char *prefix, const char *path) {
return 0; return 0;
} }
int32_t azGetObjectsByPrefix(const char *prefix, const char *path) {
int32_t code = 0;
try {
code = azGetObjectsByPrefixImpl(prefix, path);
} catch (const std::exception &e) {
azError("%s: Reason Phrase: %s", __func__, e.what());
code = TAOS_SYSTEM_ERROR(EIO);
azError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
TAOS_RETURN(code);
}
TAOS_RETURN(code);
}
int32_t azDeleteObjects(const char *object_name[], int nobject) { int32_t azDeleteObjects(const char *object_name[], int nobject) {
for (int i = 0; i < nobject; ++i) { for (int i = 0; i < nobject; ++i) {
azDeleteObjectsByPrefix(object_name[i]); azDeleteObjectsByPrefix(object_name[i]);