Skip to content

fix: don't delete sibling prefixes when delete is enabled - #3

Merged
zyclonite merged 1 commit into
mainfrom
fix/delete-sibling-prefixes
Oct 1, 2026
Merged

zyclonite merged 1 commit into
mainfrom
fix/delete-sibling-prefixes

Conversation

@cfuture81

Copy link
Copy Markdown

Summary

With delete: true, syncing to a target also deleted objects in sibling prefixes that share the same leading string.

List() used the target as a raw S3 prefix without a trailing slash, so a target of app/feature/x also listed app/feature/x-other/... and app/feature/xy/.... Those keys don't exist in the local source, so they became delete jobs and were removed. In practice, deploying branch feature/foo wiped the deployment of feature/foo-bar in the same bucket.

Changes

  • New listPrefix(target): trims slashes and appends /. The bucket root stays "".
  • New deleteCandidates(remote, local, target): only keys strictly below the target prefix can be deleted (defense in depth). Lookup now uses a map instead of a nested loop.
  • createSyncJobs uses both. Upload keys and the CloudFront invalidation path are unchanged.

Testing

  • plugin_test.go (new): sibling prefixes are ignored, a target with leading/trailing slashes works, and bucket-root sync still deletes stale keys.
  • go vet ./..., go test ./... and go build pass locally (Go 1.27).

The target was used as a raw S3 list prefix without a trailing slash, so
syncing to "app/feature/x" also listed "app/feature/x-other/...". With
delete: true those keys were not found locally and got deleted.

List with a trailing-slash prefix and only consider keys below it as
delete candidates. Adds unit tests.
@cfuture81
cfuture81 deployed to production October 1, 2026 09:47 — with GitHub Actions Active
@zyclonite zyclonite added the bug Something isn't working label Oct 1, 2026

@zyclonite zyclonite left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

please test as soon as the main branch artifact is built

@zyclonite
zyclonite merged commit 3954d3c into main Oct 1, 2026
3 checks passed
@zyclonite
zyclonite deleted the fix/delete-sibling-prefixes branch October 1, 2026 12:35

This branch was successfully deployed

1 active deployment
production — 4569cab1 Deployed Oct 1, 2026 by cfuture81 via Publish images #52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants