判断bucket 是否存在
更新时间:2024-04-09
判断Bucket是否存在
若用户需要判断某个Bucket是否存在,则如下代码可以做到:
void test_head_bucket(bos_request_options_t *options, bos_string_t bucket, bos_table_t *resp_headers) {
bos_status_t *status = NULL;
status = bos_head_bucket(options, &bucket, &resp_headers);
print_headers(resp_headers);
if (bos_status_is_ok(status)) {
printf("head bucket succeeded\n");
} else {
printf("head bucket failed\n");
}
bos_bucket_exist_status_e bucket_exist;
status = bos_check_bucket_exist(options, &bucket, &bucket_exist, &resp_headers);
if (bucket_exist == BOS_BUCKET_NON_EXIST) {
printf("bucket: %.*s non exist.\n", bucket.len, bucket.data);
} else if (bucket_exist == BOS_BUCKET_EXIST) {
printf("bucket: %.*s exist.\n", bucket.len, bucket.data);
} else {
printf("bucket: %.*s unknown status.\n", bucket.len, bucket.data);
log_status(status);
}
}
注意: 如果Bucket不为空(即Bucket中有Object存在),则Bucket无法被删除,必须清空Bucket后才能成功删除。