-
Notifications
You must be signed in to change notification settings - Fork 173
fix(storage): skip downloading blobs whose name contain ":" eg: C: D: etc when application runs in Windows.
#1774
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
+67
−2
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
347c6ee
feat(storage): support returning skipped items as UserWarning in down…
chandra-siri 948de5f
feat(storage): raise InvalidPathError for Windows full paths with ':'…
chandra-siri 0db308d
test(storage): update InvalidPathError test to use native triggers
chandra-siri 82d9f35
Merge branch 'main' into skip_invalid_windows_path
chandra-siri 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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
|
|
@@ -513,6 +513,57 @@ def test_upload_many_from_filenames_additional_properties(): | |
| assert getattr(blob, attrib) == value | ||
|
|
||
|
|
||
|
|
||
| def test__resolve_path_raises_invalid_path_error_on_windows(): | ||
| from google.cloud.storage.transfer_manager import _resolve_path, InvalidPathError | ||
|
|
||
| with mock.patch("os.name", "nt"): | ||
| with pytest.raises(InvalidPathError) as exc_info: | ||
| _resolve_path("C:\\target", "C:\\target\\file.txt") | ||
| assert "cannot be downloaded into" in str(exc_info.value) | ||
|
Comment on lines
+517
to
+523
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The assertion message with pytest.raises(InvalidPathError) as exc_info:
_resolve_path("C:\\target", "C:\\target\\file.txt")
assert "Invalid path" in str(exc_info.value) |
||
|
|
||
| # Test that it DOES NOT raise on non-windows | ||
| with mock.patch("os.name", "posix"): | ||
| # Should not raise | ||
| _resolve_path("/target", "C:\\target\\file.txt") | ||
|
|
||
|
|
||
| def test_download_many_to_path_raises_invalid_path_error(): | ||
| bucket = mock.Mock() | ||
|
|
||
| BLOBNAMES = ["C:\\target\\file.txt"] | ||
| PATH_ROOT = "mypath/" | ||
| BLOB_NAME_PREFIX = "myprefix/" | ||
| DOWNLOAD_KWARGS = {"accept-encoding": "fake-gzip"} | ||
| MAX_WORKERS = 7 | ||
| DEADLINE = 10 | ||
| WORKER_TYPE = transfer_manager.THREAD | ||
|
|
||
| with mock.patch("os.name", "nt"): | ||
| import warnings | ||
|
|
||
| with warnings.catch_warnings(record=True) as w: | ||
| warnings.simplefilter("always") | ||
| results = transfer_manager.download_many_to_path( | ||
| bucket, | ||
| BLOBNAMES, | ||
| destination_directory=PATH_ROOT, | ||
| blob_name_prefix=BLOB_NAME_PREFIX, | ||
| download_kwargs=DOWNLOAD_KWARGS, | ||
| deadline=DEADLINE, | ||
| create_directories=False, | ||
| raise_exception=True, | ||
| max_workers=MAX_WORKERS, | ||
| worker_type=WORKER_TYPE, | ||
| skip_if_exists=True, | ||
| ) | ||
|
|
||
| assert len(w) == 1 | ||
| assert "will **NOT** be downloaded" in str(w[0].message) | ||
| assert len(results) == 1 | ||
| assert isinstance(results[0], UserWarning) | ||
|
|
||
|
|
||
| def test_download_many_to_path(): | ||
| bucket = mock.Mock() | ||
|
|
||
|
|
||
Oops, something went wrong.
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.