Fix aws s3 sync traverses excluded directory - takes up a long time #1138#10273
Open
Fix aws s3 sync traverses excluded directory - takes up a long time #1138#10273
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
Fixes #1138, #1117
Description of changes:
The local file walker in
s3 sync/cp/mv/rmnow consults the user's--include/--excludefilter chain and prunes any directory whose descendants cannot possibly be included.A 1M-file directory excluded via
--exclude 'src/*'drops from ~70s to ~50ms, and FIFOs/sockets inside excluded subtrees no longer produce spurious warnings (rc=2→rc=0).--exclude excluded/*(canonical, prune fires)--exclude '*'(prune at root)--exclude excluded/d[0-4]*(partial prune via char class)--exclude excluded/excluded//excluded/d?00/*(filter cannot match anything, or pattern shape blocks prune)--include/--excludeat allThe +12% slowdown row is the cost of the per-file pre-filter that fixes #1117, so a FIFO/socket/0o000 file inside an excluded subtree no longer produces a warning that elevates rc to 2.
When the filter shape lets the algorithm prove a subtree is fully excluded, that cost is eliminated by the directory-level prune. When it cannot, the per-file probe pays for the #1117 fix.
The "no filter" row confirms the gating in
should_ignore_fileshort-circuits cleanly when there are no patterns to evaluate.Two prior PRs in this area did not merge: #2105, abandoned in 2016, and #5425, which was closed after
--exclude '*' --include '*.py'was shown to silently drop nested.pyfiles (discussion_r883991435).This PR's algorithm is sound: it prunes only when the filter chain provably cannot include any descendant, so PR #5425's regression case is handled automatically. The include
<root>/*.pyis detected as possibly matching descendants of<root>/foo/, blocking the prune.filters.pygets three new module-private helpers and one new method onFilter; existing match logic is untouched.Out of scope:
filters.pyrefactoringTesting:
sync/cp/mv/rm× upload/download/cross-bucket × Non zero RC for S3 sync even if file is excluded #1117 / aws s3 sync traverses excluded directory - takes up a long time #1138 regressionsBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.