コード例 #1
0
ファイル: s3.cpp プロジェクト: amitkr/libaws
bool deleteAllEntries(S3ConnectionPtr aS3, std::string aBucketName)
{
  ListBucketResponsePtr lListBucket;
  ListBucketResponse::Object lObject;
  std::string lMarker;
  std::cout << "Start deleting items from bucket " << aBucketName << std::endl;
  try {
    uint32_t lCtr = 0;
    do
    {
      lListBucket = aS3->listBucket(aBucketName, "", lMarker);
      lListBucket->open();
      while (lListBucket->next(lObject)) {
        DeleteResponsePtr lDelete = aS3->del(aBucketName, lObject.KeyValue);
        if(lCtr < 25){
        std::cout << "   deleted item with key " << lObject.KeyValue << std::endl;
        }else if( lCtr == 25){
          std::cout << "   deleting more items..." << std::endl;
        }else if (lCtr % 50 == 0){
          std::cout << " still deleting more items..." << std::endl;
        }
        ++lCtr;
        lMarker = lObject.KeyValue;
      }
      lListBucket->close();
    } while (lListBucket->isTruncated());
    std::cout << "deleted " << lCtr << " items" << std::endl;
  } catch (ListBucketException &e) {
    std::cerr << e.what() << std::endl;
    return false;
  }
  return true;
}
コード例 #2
0
ファイル: s3.cpp プロジェクト: amitkr/libaws
bool
listBucket(S3ConnectionPtr aS3, std::string aBucketName, std::string aPrefix, 
           std::string aMarker, std::string aDelimiter, int aMaxKeys) {
  ListBucketResponsePtr lListBucket;
  ListBucketResponse::Object lObject;

  std::string lMarker;
  try {
    do
    {
      lListBucket = aS3->listBucket(aBucketName, aPrefix, lMarker,
                                    aDelimiter, aMaxKeys);
      lListBucket->open();
      while (lListBucket->next(lObject)) {
        std::cout << "   Key: " << lObject.KeyValue << " | Last Modified: " << lObject.LastModified;
        std::cout <<  " | ETag: " << lObject.ETag << " | Size: " << lObject.Size << std::endl;
        lMarker = lObject.KeyValue;
        HeadResponsePtr lHead = aS3->head(aBucketName, lObject.KeyValue);
        std::map<std::string, std::string> lMeta = lHead->getMetaData();
        std::map<std::string, std::string>::const_iterator lIter = lMeta.begin();
        if (lMeta.size() != 0) {
          std::cout << "   Custom Metadata:" << std::endl;
          for (; lIter != lMeta.end(); ++lIter) {
            std::cout << "     Key: " << (*lIter).first << "; Value: " << (*lIter).second << std::endl;
          }
        }
      }
      lListBucket->close();
      std::vector<std::string> lCommonPrefixes = lListBucket->getCommonPrefixes();
      for (std::vector<std::string>::const_iterator lIter = lCommonPrefixes.begin();
           lIter != lCommonPrefixes.end(); ++lIter) {
        std::cout << "CommonPrefix " << *lIter << std::endl;
      }
    } while (lListBucket->isTruncated());
  } catch (S3Exception &e) {
    std::cerr << e.what() << std::endl;
    return false;
  }
  return true;
}
コード例 #3
0
int
listbucket(S3Connection* lS3Rest)
{
  {
    try {
      ListBucketResponsePtr lListBucket = lS3Rest->listBucket("28msec_s3buckettest");
      std::cout << "Listing Buckets:" << std::endl;
      ListBucketResponse::Object lObject;
      lListBucket->open();
      while (lListBucket->next(lObject)) {
        std::cout << "   Key: " << lObject.KeyValue << " | Last Modified: " << lObject.LastModified;
        std::cout <<  " | ETag: " << lObject.ETag << " | Length: " << lObject.Size << std::endl;
      }
      lListBucket->close();

    } catch (ListBucketException& e) {
      std::cerr << "Couldn't list bucket" << std::endl;
      std::cerr << e.what() << std::endl;
      return 4;
    }
  }
  return 0;
}