Skip to content

Commit

Permalink
Merge pull request #45 from martindurant/exists_not_owned
Browse files Browse the repository at this point in the history
Exists not owned
  • Loading branch information
martindurant committed Dec 6, 2017
2 parents cfaf70f + 0f8c2e6 commit 65c9ab7
Show file tree
Hide file tree
Showing 2 changed files with 230 additions and 135 deletions.
20 changes: 16 additions & 4 deletions gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,11 @@ def _call(self, method, path, *args, **kwargs):

def _list_buckets(self):
if '' not in self.dirs:
out = self._call('get', 'b/', project=self.project)
dirs = out.get('items', [])
try:
out = self._call('get', 'b/', project=self.project)
dirs = out.get('items', [])
except (FileNotFoundError, IOError, ValueError):
dirs = []
self.dirs[''] = dirs
return self.dirs['']

Expand Down Expand Up @@ -399,7 +402,7 @@ def rmdir(self, bucket):
for v in self.dirs[''][:]:
if v['name'] == bucket:
self.dirs[''].remove(v)
self.invalidate_cache(bucket)
self.dirs.pop(bucket, None)

def invalidate_cache(self, bucket=None):
"""
Expand Down Expand Up @@ -501,7 +504,16 @@ def exists(self, path):
if key:
return bool(self.info(path))
else:
return bucket in self.ls('')
if bucket in self.ls(''):
return True
else:
try:
self._list_bucket(bucket)
return True
except (FileNotFoundError, IOError, ValueError):
# bucket listing failed as it doesn't exist or we can't
# see it
return False
except FileNotFoundError:
return False

Expand Down

0 comments on commit 65c9ab7

Please sign in to comment.