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 5581a9e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 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,13 +543,14 @@ 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)
Expand All @@ -558,7 +559,7 @@ def on_close_create(s3file):
else:
if _mode.exclusive:
raise errors.FileExists(path)
if info.is_dir:
if self.strict and info.is_dir:
raise errors.FileExpected(path)

s3file = S3File.factory(path, _mode, on_close=on_close_create)
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 5581a9e

Please sign in to comment.