Skip to content

feat(storage): add deleteSourceObjects option to combine/compose method#8444

Open
thiyaguk09 wants to merge 5 commits into
googleapis:mainfrom
thiyaguk09:feat/compose-delete-source-objects
Open

feat(storage): add deleteSourceObjects option to combine/compose method#8444
thiyaguk09 wants to merge 5 commits into
googleapis:mainfrom
thiyaguk09:feat/compose-delete-source-objects

Conversation

@thiyaguk09
Copy link
Copy Markdown
Contributor

Description

This PR implements a client-side workaround for the deleteSourceObjects parameter in the GCS Compose API (combine method).

Key Changes

  • API Signature & Types: Added deleteSourceObjects?: boolean to CombineOptions and documented it in the combine method JSDocs.
  • Request Body Integration: Added deleteSourceObjects to the JSON request body of the /compose request (omitted if undefined to ensure backward compatibility and clean requests).
  • Execution Logic:
    • Executes the standard compose operation first.
    • If deleteSourceObjects is set to true and the compose operation is successful, programmatically deletes all source files.
    • If the compose operation fails, aborts immediately without deleting any source files.
  • Error Handling (ComposeCleanupError):
    • Added a new ComposeCleanupError class.
    • If the compose succeeds but any source file deletion fails, a ComposeCleanupError is thrown/returned.
    • The error lists all individual deletion failures (errors) and attaches the newly composed file (newFile) and raw apiResponse so they are still accessible to the caller.
  • Tests: Added comprehensive unit tests in test/bucket.ts verifying all success, failure, and partial cleanup error conditions.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Jun 5, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new deleteSourceObjects option for the combine operation in the Bucket class, allowing for the automatic deletion of source objects after a successful compose operation. It also adds a ComposeCleanupError class to handle partial failures during this cleanup process. The review feedback highlights critical safety and robustness concerns regarding potential data loss and concurrent deletion issues, suggesting the use of ifGenerationMatch and ignoreNotFound: true in the delete calls, along with corresponding updates to the test suite.

Comment thread handwritten/storage/src/bucket.ts
Comment thread handwritten/storage/test/bucket.ts Outdated
@thiyaguk09 thiyaguk09 marked this pull request as ready for review June 5, 2026 09:58
@thiyaguk09 thiyaguk09 requested a review from a team as a code owner June 5, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant