-
Notifications
You must be signed in to change notification settings - Fork 52
fix: prevent S3 path conflicts using tempfile #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7f9e207
fix: prevent S3 path conflicts using hash-based directory isolation
CyMule ef832cc
version
CyMule aca99e5
update test
CyMule 3102775
cleanup
CyMule eedf93c
target s3
CyMule 35736b9
temp files
CyMule 966fdda
fix
CyMule 7dd4231
mkdir and download dir
CyMule bc8e2ed
remove line
CyMule ed2a837
addres feedback
CyMule 9d1ee57
Merge branch 'main' into fix/s3-path-conflicts-hash-isolation
CyMule File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
...results/s3-minio/directory_structure.json → ...ed_results/s3-minio/expected_s3_keys.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "directory_structure": [ | ||
| "s3_keys": [ | ||
| "wiki_movie_plots_small.csv" | ||
| ] | ||
| } |
2 changes: 1 addition & 1 deletion
2
...s/s3-specialchar/directory_structure.json → ...ults/s3-specialchar/expected_s3_keys.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "directory_structure": [ | ||
| "s3_keys": [ | ||
| "Why_is_the_sky_blue?.txt", | ||
| "[test]?*.txt" | ||
| ] | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
...ected_results/s3/directory_structure.json → ...expected_results/s3/expected_s3_keys.json
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = "1.1.3" # pragma: no cover | ||
| __version__ = "1.1.4" # pragma: no cover |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,6 +270,22 @@ class FsspecDownloader(Downloader): | |
| download_config: Optional[FsspecDownloaderConfigT] = field( | ||
| default_factory=lambda: FsspecDownloaderConfig() | ||
| ) | ||
|
|
||
| def get_download_path(self, file_data: FileData) -> Optional[Path]: | ||
| if not file_data.source_identifiers: | ||
| return None | ||
|
|
||
| filename = file_data.source_identifiers.filename | ||
| if not filename: | ||
| return None | ||
|
||
|
|
||
| mkdir_concurrent_safe(self.download_dir) | ||
|
|
||
| temp_dir = tempfile.mkdtemp( | ||
| prefix="unstructured_", | ||
|
||
| dir=self.download_dir | ||
| ) | ||
| return Path(temp_dir) / filename | ||
|
|
||
| def is_async(self) -> bool: | ||
| with self.connection_config.get_client(protocol=self.protocol) as client: | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not super important here and shouldn't be a blocker but in general I would avoid this pattern in the code.
I did some math and you should get about 10x-12x speedup if you create and compare two sets because TimSort has O(n*log n) complexity. Comparing two sets or two lists is the same O(n).
For 100k files this would be a difference of 3.5kk operations (sorted lists) vs. 300k operations (sets)