prefix/delete: delete with prefix
This commit is contained in:
parent
4a77a49a3e
commit
2479bb343e
|
@ -191,7 +191,7 @@ if(${BUILD_WITH_S3})
|
||||||
#cat("${TD_SUPPORT_DIR}/curl_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
#cat("${TD_SUPPORT_DIR}/curl_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||||
#INCLUDE_DIRECTORIES($ENV{HOME}/.cos-local.1/include)
|
#INCLUDE_DIRECTORIES($ENV{HOME}/.cos-local.1/include)
|
||||||
|
|
||||||
cat("${TD_SUPPORT_DIR}/ssl_CMakeLists.txt.in" ${CONTRIB_TMP_FILE3})
|
cat("${TD_SUPPORT_DIR}/ssl_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||||
cat("${TD_SUPPORT_DIR}/xml2_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
cat("${TD_SUPPORT_DIR}/xml2_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||||
cat("${TD_SUPPORT_DIR}/curl_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
cat("${TD_SUPPORT_DIR}/curl_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||||
cat("${TD_SUPPORT_DIR}/libs3_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
cat("${TD_SUPPORT_DIR}/libs3_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||||
|
|
|
@ -123,6 +123,7 @@ typedef struct list_bucket_callback_data {
|
||||||
char nextMarker[1024];
|
char nextMarker[1024];
|
||||||
int keyCount;
|
int keyCount;
|
||||||
int allDetails;
|
int allDetails;
|
||||||
|
SArray *objectArray;
|
||||||
S3Status status;
|
S3Status status;
|
||||||
char err_msg[4096];
|
char err_msg[4096];
|
||||||
} list_bucket_callback_data;
|
} list_bucket_callback_data;
|
||||||
|
@ -149,7 +150,9 @@ static S3Status listBucketCallback(int isTruncated, const char *nextMarker, int
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < contentsCount; ++i) {
|
for (i = 0; i < contentsCount; ++i) {
|
||||||
const S3ListBucketContent *content = &(contents[i]);
|
const S3ListBucketContent *content = &(contents[i]);
|
||||||
printf("%-50s", content->key);
|
// printf("%-50s", content->key);
|
||||||
|
char *object_key = strdup(content->key);
|
||||||
|
taosArrayPush(data->objectArray, &object_key);
|
||||||
}
|
}
|
||||||
data->keyCount += contentsCount;
|
data->keyCount += contentsCount;
|
||||||
|
|
||||||
|
@ -160,6 +163,11 @@ static S3Status listBucketCallback(int isTruncated, const char *nextMarker, int
|
||||||
return S3StatusOK;
|
return S3StatusOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void s3FreeObjectKey(void *pItem) {
|
||||||
|
char *key = (char *)pItem;
|
||||||
|
taosMemoryFree(key);
|
||||||
|
}
|
||||||
|
|
||||||
void s3DeleteObjectsByPrefix(const char *prefix) {
|
void s3DeleteObjectsByPrefix(const char *prefix) {
|
||||||
S3BucketContext bucketContext = {0, tsS3BucketName, protocolG, uriStyleG, tsS3AccessKeyId, tsS3AccessKeySecret,
|
S3BucketContext bucketContext = {0, tsS3BucketName, protocolG, uriStyleG, tsS3AccessKeyId, tsS3AccessKeySecret,
|
||||||
0, awsRegionG};
|
0, awsRegionG};
|
||||||
|
@ -169,7 +177,11 @@ void s3DeleteObjectsByPrefix(const char *prefix) {
|
||||||
const char *marker = 0, *delimiter = 0;
|
const char *marker = 0, *delimiter = 0;
|
||||||
int maxkeys = 0, allDetails = 0;
|
int maxkeys = 0, allDetails = 0;
|
||||||
list_bucket_callback_data data;
|
list_bucket_callback_data data;
|
||||||
|
data.objectArray = taosArrayInit(32, POINTER_BYTES);
|
||||||
|
if (!data.objectArray) {
|
||||||
|
vError("%s: %s", __func__, "out of memoty");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (marker) {
|
if (marker) {
|
||||||
snprintf(data.nextMarker, sizeof(data.nextMarker), "%s", marker);
|
snprintf(data.nextMarker, sizeof(data.nextMarker), "%s", marker);
|
||||||
} else {
|
} else {
|
||||||
|
@ -192,10 +204,13 @@ void s3DeleteObjectsByPrefix(const char *prefix) {
|
||||||
if (data.status == S3StatusOK) {
|
if (data.status == S3StatusOK) {
|
||||||
if (!data.keyCount) {
|
if (!data.keyCount) {
|
||||||
// printListBucketHeader(allDetails);
|
// printListBucketHeader(allDetails);
|
||||||
|
s3DeleteObjects(TARRAY_DATA(data.objectArray), TARRAY_SIZE(data.objectArray));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
s3PrintError(__func__, data.status, data.err_msg);
|
s3PrintError(__func__, data.status, data.err_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosArrayDestroyEx(data.objectArray, s3FreeObjectKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void s3DeleteObjects(const char *object_name[], int nobject) {
|
void s3DeleteObjects(const char *object_name[], int nobject) {
|
||||||
|
|
Loading…
Reference in New Issue