-
Notifications
You must be signed in to change notification settings - Fork 102
improved detection of files and directories in GoogleStorageMixin #129
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
Open
jesteria
wants to merge
11
commits into
stephenmcd:master
Choose a base branch
from
jesteria:gcloud-compat
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d6fbe51
Fix rmtree method of S3BotoStorageMixin
6f23b88
Fixes issue with old methods in gcs support
TysonRV d0d4a6d
Merge pull request #1 from TysonRV/trodriguez/fix_support_for_gcs
TysonRV 3d33898
Merge pull request #125 from mostlyserious/master
stephenmcd 3b86e28
Fix cs specification that is breaking compilemessages command
TysonRV 1f2bf78
Merge pull request #2 from TysonRV/trodriguez/fix_cs_specification
TysonRV 17f1146
Merge pull request #126 from TysonRV/master
stephenmcd 6ec3433
improved detection of files and directories in GoogleStorageMixin
jesteria 9f6c2f6
further refined isfile & isdir checks in GoogleStorageMixin
jesteria 7f2c233
reinstitute `isfile` check within `isdir` check
jesteria 896710a
improve file/dir detection and improve browsing performance (Google C…
jesteria 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ | |
| *.pyc | ||
| *.eggs/ | ||
| *.egg-info | ||
| .idea | ||
| mezzanine-git/ | ||
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 |
|---|---|---|
|
|
@@ -2,8 +2,10 @@ | |
| # coding: utf-8 | ||
|
|
||
| # PYTHON IMPORTS | ||
| import itertools | ||
| import os | ||
| import shutil | ||
| import posixpath | ||
|
|
||
| # DJANGO IMPORTS | ||
| from django.core.files.move import file_move_safe | ||
|
|
@@ -112,15 +114,19 @@ def makedirs(self, name): | |
|
|
||
| def rmtree(self, name): | ||
| name = self._normalize_name(self._clean_name(name)) | ||
| dirlist = self.listdir(self._encode_name(name)) | ||
| for item in dirlist: | ||
| item.delete() | ||
| directories, files = self.listdir(self._encode_name(name)) | ||
|
|
||
| for key in files: | ||
| self.delete('/'.join([name, key])) | ||
|
|
||
| for dirname in directories: | ||
| self.rmtree('/'.join([name, dirname])) | ||
|
|
||
|
|
||
| class GoogleStorageMixin(StorageMixin): | ||
|
|
||
| def isfile(self, name): | ||
| return self.exists(name) | ||
| return bool(name) and self.exists(name) | ||
|
|
||
| def isdir(self, name): | ||
| # That's some inefficient implementation... | ||
|
|
@@ -132,10 +138,10 @@ def isdir(self, name): | |
| if self.isfile(name): | ||
| return False | ||
|
|
||
| name = self._normalize_name(self._clean_name(name)) | ||
| dirlist = self.bucket.list(self._encode_name(name)) | ||
| (dirs, files) = self.listdir(name) | ||
|
jesteria marked this conversation as resolved.
Outdated
|
||
| dirlist = itertools.chain(dirs, files) | ||
|
|
||
| # Check whether the iterator is empty | ||
| # Check for contents | ||
| for item in dirlist: | ||
|
Author
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 |
||
| return True | ||
| return False | ||
|
|
@@ -163,6 +169,32 @@ def makedirs(self, name): | |
|
|
||
| def rmtree(self, name): | ||
| name = self._normalize_name(self._clean_name(name)) | ||
| dirlist = self.bucket.list(self._encode_name(name)) | ||
| dirlist = self.listdir(self._encode_name(name)) | ||
| for item in dirlist: | ||
| item.delete() | ||
|
|
||
| def _clean_name(self, name): | ||
| """ | ||
| Cleans the name so that Windows style paths work | ||
| """ | ||
| return clean_name(name) | ||
|
|
||
|
|
||
| def clean_name(name): | ||
| """ | ||
| Cleans the name so that Windows style paths work | ||
| """ | ||
| # Normalize Windows style paths | ||
| clean_name = posixpath.normpath(name).replace('\\', '/') | ||
|
|
||
| # os.path.normpath() can strip trailing slashes so we implement | ||
| # a workaround here. | ||
| if name.endswith('/') and not clean_name.endswith('/'): | ||
| # Add a trailing slash as it was stripped. | ||
| clean_name = clean_name + '/' | ||
|
|
||
| # Given an empty string, os.path.normpath() will return ., which we don't want | ||
| if clean_name == '.': | ||
| clean_name = '' | ||
|
|
||
| return clean_name | ||
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.
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.
by relying only on
exists(), the methodisfile()inappropriately considered the bucket root to be a file.