From 2bdf61fadda655323a36185f921f8a3e183bcdf9 Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Wed, 9 Nov 2016 14:02:23 +0100 Subject: [PATCH] Handle deleted files with if-none-match When an object is deleted, we retrieve its metadata on the next PUT requests, which make if-none-match requests fail while the object shouldn't be here. It seems we're only interested in the timestamp of the deleted object, so get that but forget the metadata. Change-Id: I4a4a8be9b631598ca1cd52c53885c68c3fbdfc4a Closes-Bug: #1640448 --- swift/obj/server.py | 2 +- test/functional/test_object.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/swift/obj/server.py b/swift/obj/server.py index 408b6416e1..157cca4d93 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -686,7 +686,7 @@ class ObjectController(BaseStorageServer): except DiskFileXattrNotSupported: return HTTPInsufficientStorage(drive=device, request=request) except DiskFileDeleted as e: - orig_metadata = e.metadata + orig_metadata = {} orig_timestamp = e.timestamp except (DiskFileNotExist, DiskFileQuarantined): orig_metadata = {} diff --git a/test/functional/test_object.py b/test/functional/test_object.py index f23ccbc78e..f6c82668f2 100644 --- a/test/functional/test_object.py +++ b/test/functional/test_object.py @@ -273,6 +273,12 @@ class TestObject(unittest2.TestCase): }) def test_if_none_match(self): + def delete(url, token, parsed, conn): + conn.request('DELETE', '%s/%s/%s' % ( + parsed.path, self.container, 'if_none_match_test'), '', + {'X-Auth-Token': token}) + return check_response(conn) + def put(url, token, parsed, conn): conn.request('PUT', '%s/%s/%s' % ( parsed.path, self.container, 'if_none_match_test'), '', @@ -287,6 +293,13 @@ class TestObject(unittest2.TestCase): resp.read() self.assertEqual(resp.status, 412) + resp = retry(delete) + resp.read() + self.assertEqual(resp.status, 204) + resp = retry(put) + resp.read() + self.assertEqual(resp.status, 201) + def put(url, token, parsed, conn): conn.request('PUT', '%s/%s/%s' % ( parsed.path, self.container, 'if_none_match_test'), '',