Skip to content

add if match statement to download#3375

Merged
sbiscigl merged 1 commit intomainfrom
transfer-manager-etag
Apr 8, 2025
Merged

add if match statement to download#3375
sbiscigl merged 1 commit intomainfrom
transfer-manager-etag

Conversation

@sbiscigl
Copy link
Copy Markdown
Collaborator

@sbiscigl sbiscigl commented Apr 4, 2025

Description of changes:

Adds a etag if match statement to the ranged get functionality of the transfer manager. Will error in the event a file is changed mid operation.

i.e.

#include <aws/core/Aws.h>
#include <aws/core/utils/threading/PooledThreadExecutor.h>
#include <aws/transfer/TransferManager.h>

using namespace Aws;
using namespace Aws::S3;
using namespace Aws::Transfer;
using namespace Aws::Utils;
using namespace Aws::Utils::Threading;
namespace {
const char * LOG_TAG = "test-app";
const char * BUCKET_NAME = "somebucket";
const char * KEY_NAME = "somekey";
}

auto main() -> int {
  SDKOptions options{};
  options.loggingOptions.logLevel = Logging::LogLevel::Debug;
  InitAPI(options);
  {
    const auto executor = Aws::MakeUnique<PooledThreadExecutor>(LOG_TAG, std::thread::hardware_concurrency());
    TransferManagerConfiguration configuration{executor.get()};
    configuration.s3Client = Aws::MakeShared<S3Client>(LOG_TAG);
    configuration.transferInitiatedCallback = [](const TransferManager*, const std::shared_ptr<const TransferHandle>&) {
      std::cout << "started transfer\n";
    };

    configuration.errorCallback = [](const TransferManager*, const std::shared_ptr<const TransferHandle>&, const Aws::Client::AWSError<Aws::S3::S3Errors>& error) {
      std::cout << "error: " << error.GetMessage() << "\n";
    };

    configuration.transferStatusUpdatedCallback = [](const TransferManager*, const std::shared_ptr<const TransferHandle>& handle) {
      if (handle->GetStatus() == TransferStatus::COMPLETED) {
        std::cout << "completed transfer\n";
      } else if (handle->GetStatus() == TransferStatus::FAILED) {
        std::cout << "failed\n";
      }
    };

    const auto transferManager = TransferManager::Create(configuration);

    const auto handle = transferManager->DownloadFile(BUCKET_NAME, KEY_NAME, KEY_NAME);

    transferManager->WaitUntilAllFinished();
  }
  ShutdownAPI(options);
  return 0;
}

will result in the output

error: Unable to parse ExceptionName: PreconditionFailed Message: At least one of the pre-conditions you specified did not hold
failed
finished transfer

when run when a objects etag changes and objects are not versioned. No file will be downloaded.

Check all that applies:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (If tests are not applicable, explain.)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Not adding a test as it requires a race condition i cannot force in sdk code

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@sbiscigl sbiscigl force-pushed the transfer-manager-etag branch from 832cc2a to cb0af52 Compare April 7, 2025 13:15
@sbiscigl sbiscigl marked this pull request as ready for review April 7, 2025 19:44
@sbiscigl sbiscigl force-pushed the transfer-manager-etag branch from cb0af52 to 4da266b Compare April 7, 2025 21:11
@sbiscigl sbiscigl merged commit 160cdad into main Apr 8, 2025
3 of 4 checks passed
@sbiscigl sbiscigl deleted the transfer-manager-etag branch April 8, 2025 13:30
@sbiscigl sbiscigl mentioned this pull request Sep 5, 2025
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants