-
Notifications
You must be signed in to change notification settings - Fork 283
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
Fix GCSFS walk() method #561
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,7 @@ def isdir(self, path): | |
path = norm_path(_stringify_path(path)) | ||
try: | ||
contents = self.fs.ls(path) | ||
if len(contents) == 1 and contents[0] == path: | ||
return False | ||
else: | ||
return True | ||
return not(len(contents) == 1 and contents[0] == path) | ||
except OSError: | ||
return False | ||
|
||
|
@@ -41,26 +38,23 @@ def walk(self, path): | |
directories = set() | ||
files = set() | ||
|
||
for key in self.fs.ls(path, detail=True): | ||
for obj in self.fs.ls(path, detail=True): | ||
# each info name must be at least [path]/part , but here | ||
# we check also for names like [path]/part/ | ||
path = key['name'] | ||
if key['storageClass'] == 'DIRECTORY': | ||
if path.endswith('/'): | ||
directories.add(path[:-1]) | ||
else: | ||
directories.add(path) | ||
elif key['storageClass'] == 'BUCKET': | ||
pass | ||
else: | ||
files.add(path) | ||
|
||
files = sorted([posixpath.split(f)[1] for f in files | ||
if f not in directories]) | ||
directories = sorted([posixpath.split(x)[1] | ||
for x in directories]) | ||
|
||
yield path, directories, files | ||
obj_path = obj['name'] | ||
if obj_path == path: | ||
continue | ||
if obj['type'] == 'directory': | ||
directories.add(obj_path) | ||
elif obj['type'] == 'file': | ||
files.add(obj_path) | ||
|
||
rel_files = sorted([posixpath.split(f)[1] for f in files | ||
if f not in directories]) | ||
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. What's the purpose of checking |
||
rel_directories = sorted([posixpath.split(x[:-1])[1] | ||
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. More self explanatory, IMO: |
||
for x in directories]) | ||
|
||
yield path, rel_directories, rel_files | ||
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. When |
||
|
||
for directory in directories: | ||
for tup in self.walk(directory): | ||
|
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.
This check still fails to catch the desired directory.
obj_path
has an extra '/' on the end whichpath
does not.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.
Thanks, I was able to reproduce, but for some reason only when I provided a directory that didn't contain files, only other directories.