From b1411d4d523996297ac48025c90d152f094f2105 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 27 Sep 2018 15:12:04 -0400 Subject: [PATCH] Make sure empty segments in Swift are deleted on upload cancelation --- storage/swift.py | 4 ++++ storage/test/test_swift.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/storage/swift.py b/storage/swift.py index 6093df643..233549a3c 100644 --- a/storage/swift.py +++ b/storage/swift.py @@ -408,6 +408,10 @@ class SwiftStorage(BaseStorage): for segment in SwiftStorage._segment_list_from_metadata(storage_metadata, key=_SEGMENTS_KEY): self.remove(segment.path) + for segment in SwiftStorage._segment_list_from_metadata(storage_metadata, + key=_EMPTY_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 diff --git a/storage/test/test_swift.py b/storage/test/test_swift.py index 409151e80..abf617397 100644 --- a/storage/test/test_swift.py +++ b/storage/test/test_swift.py @@ -7,7 +7,7 @@ from collections import defaultdict from mock import MagicMock, patch from storage import StorageContext -from storage.swift import SwiftStorage +from storage.swift import SwiftStorage, _EMPTY_SEGMENTS_KEY from swiftclient.client import ClientException base_args = { @@ -278,6 +278,9 @@ def test_cancel_chunked_upload(): for segment in SwiftStorage._segment_list_from_metadata(metadata): assert not swift.exists(segment.path) + for segment in SwiftStorage._segment_list_from_metadata(metadata, key=_EMPTY_SEGMENTS_KEY): + assert not swift.exists(segment.path) + def test_empty_chunks_queued_for_deletion(): chunk_cleanup_queue = FakeQueue() args = dict(base_args)