Skip to content

Commit

Permalink
be less strict in non-strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-its committed Nov 12, 2019
1 parent 7f95af6 commit 4986e8f
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions fs_s3fs/_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def listdir(self, path):
if name:
_directory.append(name)

if not _directory:
if self.strict and not _directory:
if not self.getinfo(_path).is_dir:
raise errors.DirectoryExpected(path)

Expand All @@ -503,7 +503,7 @@ def makedir(self, path, permissions=None, recreate=False):
_path = self.validatepath(path)
_key = self._path_to_dir_key(_path)

if not self.isdir(dirname(_path)):
if self.strict and not self.isdir(dirname(_path)):
raise errors.ResourceNotFound(path)

try:
Expand Down Expand Up @@ -543,23 +543,24 @@ def on_close_create(s3file):
finally:
s3file.raw.close()

try:
dir_path = dirname(_path)
if dir_path != "/":
_dir_key = self._path_to_dir_key(dir_path)
self._get_object(dir_path, _dir_key)
except errors.ResourceNotFound:
raise errors.ResourceNotFound(path)
if self.strict:
try:
dir_path = dirname(_path)
if dir_path != "/":
_dir_key = self._path_to_dir_key(dir_path)
self._get_object(dir_path, _dir_key)
except errors.ResourceNotFound:
raise errors.ResourceNotFound(path)

try:
info = self._getinfo(path)
except errors.ResourceNotFound:
pass
else:
if _mode.exclusive:
raise errors.FileExists(path)
if info.is_dir:
raise errors.FileExpected(path)
try:
info = self._getinfo(path)
except errors.ResourceNotFound:
pass
else:
if _mode.exclusive:
raise errors.FileExists(path)
if info.is_dir:
raise errors.FileExpected(path)

s3file = S3File.factory(path, _mode, on_close=on_close_create)
if _mode.appending:
Expand Down Expand Up @@ -692,9 +693,10 @@ def scandir(self, path, namespaces=None, page=None):
_s3_key = self._path_to_dir_key(_path)
prefix_len = len(_s3_key)

info = self.getinfo(path)
if not info.is_dir:
raise errors.DirectoryExpected(path)
if self.strict:
info = self.getinfo(path)
if not info.is_dir:
raise errors.DirectoryExpected(path)

paginator = self.client.get_paginator("list_objects")
_paginate = paginator.paginate(
Expand Down

0 comments on commit 4986e8f

Please sign in to comment.