From 4986e8f0b48ff9aa6a161f842a92c648ff4323dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Kry=C5=84ski?= Date: Tue, 12 Nov 2019 23:42:05 +0100 Subject: [PATCH] be less strict in non-strict mode --- fs_s3fs/_s3fs.py | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/fs_s3fs/_s3fs.py b/fs_s3fs/_s3fs.py index d7f98e2..052fa76 100644 --- a/fs_s3fs/_s3fs.py +++ b/fs_s3fs/_s3fs.py @@ -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) @@ -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: @@ -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: @@ -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(