Skip to content

Commit 5581a9e

Browse files
committed
be less strict in non-strict mode
1 parent 7f95af6 commit 5581a9e

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

fs_s3fs/_s3fs.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def listdir(self, path):
492492
if name:
493493
_directory.append(name)
494494

495-
if not _directory:
495+
if self.strict and not _directory:
496496
if not self.getinfo(_path).is_dir:
497497
raise errors.DirectoryExpected(path)
498498

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

506-
if not self.isdir(dirname(_path)):
506+
if self.strict and not self.isdir(dirname(_path)):
507507
raise errors.ResourceNotFound(path)
508508

509509
try:
@@ -543,13 +543,14 @@ def on_close_create(s3file):
543543
finally:
544544
s3file.raw.close()
545545

546-
try:
547-
dir_path = dirname(_path)
548-
if dir_path != "/":
549-
_dir_key = self._path_to_dir_key(dir_path)
550-
self._get_object(dir_path, _dir_key)
551-
except errors.ResourceNotFound:
552-
raise errors.ResourceNotFound(path)
546+
if self.strict:
547+
try:
548+
dir_path = dirname(_path)
549+
if dir_path != "/":
550+
_dir_key = self._path_to_dir_key(dir_path)
551+
self._get_object(dir_path, _dir_key)
552+
except errors.ResourceNotFound:
553+
raise errors.ResourceNotFound(path)
553554

554555
try:
555556
info = self._getinfo(path)
@@ -558,7 +559,7 @@ def on_close_create(s3file):
558559
else:
559560
if _mode.exclusive:
560561
raise errors.FileExists(path)
561-
if info.is_dir:
562+
if self.strict and info.is_dir:
562563
raise errors.FileExpected(path)
563564

564565
s3file = S3File.factory(path, _mode, on_close=on_close_create)
@@ -692,9 +693,10 @@ def scandir(self, path, namespaces=None, page=None):
692693
_s3_key = self._path_to_dir_key(_path)
693694
prefix_len = len(_s3_key)
694695

695-
info = self.getinfo(path)
696-
if not info.is_dir:
697-
raise errors.DirectoryExpected(path)
696+
if self.strict:
697+
info = self.getinfo(path)
698+
if not info.is_dir:
699+
raise errors.DirectoryExpected(path)
698700

699701
paginator = self.client.get_paginator("list_objects")
700702
_paginate = paginator.paginate(

0 commit comments

Comments
 (0)