From 5581a9e5ed15010d81a8bc1a9800155aa060f9da 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 | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/fs_s3fs/_s3fs.py b/fs_s3fs/_s3fs.py index d7f98e2..c6a5576 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,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) @@ -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) @@ -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(