Add missing copy_to
method to Swift
Along with tests Fixes https://coreosdev.atlassian.net/browse/QS-22
This commit is contained in:
parent
3bef21253d
commit
ab886226f3
2 changed files with 69 additions and 4 deletions
|
@ -355,3 +355,28 @@ class SwiftStorage(BaseStorage):
|
|||
# Delete all the uploaded segments.
|
||||
for segment in SwiftStorage._segment_list_from_metadata(storage_metadata, key=_SEGMENTS_KEY):
|
||||
self.remove(segment.path)
|
||||
|
||||
def copy_to(self, destination, path):
|
||||
if (self.__class__ == destination.__class__ and
|
||||
self._swift_user == destination._swift_user and
|
||||
self._swift_password == destination._swift_password and
|
||||
self._auth_url == destination._auth_url and
|
||||
self._auth_version == destination._auth_version):
|
||||
logger.debug('Copying file from swift %s to swift %s via a Swift copy',
|
||||
self._swift_container, destination)
|
||||
|
||||
normalized_path = self._normalize_path(path)
|
||||
target = '/%s/%s' % (destination._swift_container, normalized_path)
|
||||
|
||||
try:
|
||||
self._get_connection().copy_object(self._swift_container, normalized_path, target)
|
||||
except Exception as ex:
|
||||
logger.exception('Could not swift copy path %s: %s', path, ex)
|
||||
raise IOError('Failed to swift copy path %s' % path)
|
||||
return
|
||||
|
||||
# Fallback to a slower, default copy.
|
||||
logger.debug('Copying file from swift %s to %s via a streamed copy', self._swift_container,
|
||||
destination)
|
||||
with self.stream_read_file(path) as fp:
|
||||
destination.stream_write(path, fp)
|
||||
|
|
Reference in a new issue