Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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