Remove list directory from storage driver
This commit is contained in:
parent
612098b645
commit
0b1951a4a4
5 changed files with 0 additions and 76 deletions
|
@ -74,9 +74,6 @@ class BaseStorage(StoragePaths):
|
||||||
def stream_write(self, path, fp, content_type=None, content_encoding=None):
|
def stream_write(self, path, fp, content_type=None, content_encoding=None):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def list_directory(self, path=None):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def exists(self, path):
|
def exists(self, path):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
|
@ -210,27 +210,6 @@ class _CloudStorage(BaseStorageV2):
|
||||||
mp.complete_upload()
|
mp.complete_upload()
|
||||||
return total_bytes_written, error
|
return total_bytes_written, error
|
||||||
|
|
||||||
def list_directory(self, path=None):
|
|
||||||
self._initialize_cloud_conn()
|
|
||||||
path = self._init_path(path)
|
|
||||||
if not path.endswith('/'):
|
|
||||||
path += '/'
|
|
||||||
ln = 0
|
|
||||||
if self._root_path != '/':
|
|
||||||
ln = len(self._root_path)
|
|
||||||
exists = False
|
|
||||||
for key in self._cloud_bucket.list(prefix=path, delimiter='/'):
|
|
||||||
exists = True
|
|
||||||
name = key.name
|
|
||||||
if name.endswith('/'):
|
|
||||||
yield name[ln:-1]
|
|
||||||
else:
|
|
||||||
yield name[ln:]
|
|
||||||
if exists is False:
|
|
||||||
# In order to be compliant with the LocalStorage API. Even though
|
|
||||||
# S3 does not have a concept of folders.
|
|
||||||
raise OSError('No such directory: \'{0}\''.format(path))
|
|
||||||
|
|
||||||
def exists(self, path):
|
def exists(self, path):
|
||||||
self._initialize_cloud_conn()
|
self._initialize_cloud_conn()
|
||||||
path = self._init_path(path)
|
path = self._init_path(path)
|
||||||
|
|
|
@ -44,7 +44,6 @@ class DistributedStorage(StoragePaths):
|
||||||
stream_read = _location_aware(BaseStorage.stream_read)
|
stream_read = _location_aware(BaseStorage.stream_read)
|
||||||
stream_read_file = _location_aware(BaseStorage.stream_read_file)
|
stream_read_file = _location_aware(BaseStorage.stream_read_file)
|
||||||
stream_write = _location_aware(BaseStorage.stream_write)
|
stream_write = _location_aware(BaseStorage.stream_write)
|
||||||
list_directory = _location_aware(BaseStorage.list_directory)
|
|
||||||
exists = _location_aware(BaseStorage.exists)
|
exists = _location_aware(BaseStorage.exists)
|
||||||
remove = _location_aware(BaseStorage.remove)
|
remove = _location_aware(BaseStorage.remove)
|
||||||
get_checksum = _location_aware(BaseStorage.get_checksum)
|
get_checksum = _location_aware(BaseStorage.get_checksum)
|
||||||
|
|
|
@ -56,18 +56,6 @@ class LocalStorage(BaseStorageV2):
|
||||||
with open(path, mode='wb') as out_fp:
|
with open(path, mode='wb') as out_fp:
|
||||||
self.stream_write_to_fp(fp, out_fp)
|
self.stream_write_to_fp(fp, out_fp)
|
||||||
|
|
||||||
def list_directory(self, path=None):
|
|
||||||
path = self._init_path(path)
|
|
||||||
prefix = path[len(self._root_path) + 1:] + '/'
|
|
||||||
exists = False
|
|
||||||
for d in os.listdir(path):
|
|
||||||
exists = True
|
|
||||||
yield prefix + d
|
|
||||||
if exists is False:
|
|
||||||
# Raises OSError even when the directory is empty
|
|
||||||
# (to be consistent with S3)
|
|
||||||
raise OSError('No such directory: \'{0}\''.format(path))
|
|
||||||
|
|
||||||
def exists(self, path):
|
def exists(self, path):
|
||||||
path = self._init_path(path)
|
path = self._init_path(path)
|
||||||
return os.path.exists(path)
|
return os.path.exists(path)
|
||||||
|
|
|
@ -61,15 +61,6 @@ class SwiftStorage(BaseStorage):
|
||||||
auth_version=self._auth_version,
|
auth_version=self._auth_version,
|
||||||
os_options=self._os_options)
|
os_options=self._os_options)
|
||||||
|
|
||||||
def _get_relative_path(self, path):
|
|
||||||
if path.startswith(self._storage_path):
|
|
||||||
path = path[len(self._storage_path)]
|
|
||||||
|
|
||||||
if path.endswith('/'):
|
|
||||||
path = path[:-1]
|
|
||||||
|
|
||||||
return path
|
|
||||||
|
|
||||||
def _normalize_path(self, object_path=None):
|
def _normalize_path(self, object_path=None):
|
||||||
path = self._storage_path
|
path = self._storage_path
|
||||||
if not path.endswith('/'):
|
if not path.endswith('/'):
|
||||||
|
@ -87,20 +78,6 @@ class SwiftStorage(BaseStorage):
|
||||||
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def _get_container(self, path):
|
|
||||||
path = self._normalize_path(path)
|
|
||||||
|
|
||||||
if path and not path.endswith('/'):
|
|
||||||
path += '/'
|
|
||||||
|
|
||||||
try:
|
|
||||||
_, container = self._get_connection().get_container(
|
|
||||||
container=self._swift_container,
|
|
||||||
prefix=path, delimiter='/')
|
|
||||||
return container
|
|
||||||
except:
|
|
||||||
logger.exception('Could not get container: %s', path)
|
|
||||||
raise IOError('Unknown path: %s' % path)
|
|
||||||
|
|
||||||
def _get_object(self, path, chunk_size=None):
|
def _get_object(self, path, chunk_size=None):
|
||||||
path = self._normalize_path(path)
|
path = self._normalize_path(path)
|
||||||
|
@ -218,22 +195,6 @@ class SwiftStorage(BaseStorage):
|
||||||
self._put_object(path, fp, self.buffer_size, content_type=content_type,
|
self._put_object(path, fp, self.buffer_size, content_type=content_type,
|
||||||
content_encoding=content_encoding)
|
content_encoding=content_encoding)
|
||||||
|
|
||||||
def list_directory(self, path=None):
|
|
||||||
container = self._get_container(path)
|
|
||||||
if not container:
|
|
||||||
raise OSError('Unknown path: %s' % path)
|
|
||||||
|
|
||||||
for entry in container:
|
|
||||||
param = None
|
|
||||||
if 'name' in entry:
|
|
||||||
param = 'name'
|
|
||||||
elif 'subdir' in entry:
|
|
||||||
param = 'subdir'
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
|
|
||||||
yield self._get_relative_path(entry[param])
|
|
||||||
|
|
||||||
def exists(self, path):
|
def exists(self, path):
|
||||||
return bool(self._head_object(path))
|
return bool(self._head_object(path))
|
||||||
|
|
||||||
|
|
Reference in a new issue