Commit 524d9cdd authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Add option to fail upload if remote file exists

The if-none-match header option with '*' is used in that case.
This is exposed as 'if_not_exist' in PithosClient.upload_object

Feature #3574
parent e5c76b1a
......@@ -204,7 +204,6 @@ class PithosClient(PithosRestClient):
format='json',
hashmap=True,
content_type=None,
etag=None,
content_encoding=None,
content_disposition=None,
permissions=None,
......@@ -216,7 +215,6 @@ class PithosClient(PithosRestClient):
hashmap=True,
content_type=content_type,
json=json,
etag=etag,
content_encoding=content_encoding,
content_disposition=content_disposition,
permissions=permissions,
......@@ -293,6 +291,7 @@ class PithosClient(PithosRestClient):
hash_cb=None,
upload_cb=None,
etag=None,
if_not_exist=None,
content_encoding=None,
content_disposition=None,
content_type=None,
......@@ -310,6 +309,11 @@ class PithosClient(PithosRestClient):
:param etag: (str)
:param if_not_exist: (bool) If true, the file will be uploaded ONLY if
it does not exist remotely, otherwise the operation will fail.
Involves the case of an object with the same path is created while
the object is being uploaded.
:param content_encoding: (str)
:param content_disposition: (str)
......@@ -342,7 +346,6 @@ class PithosClient(PithosRestClient):
obj, hashmap,
content_type=content_type,
size=size,
etag=etag,
content_encoding=content_encoding,
content_disposition=content_disposition,
permissions=sharing,
......@@ -393,6 +396,8 @@ class PithosClient(PithosRestClient):
format='json',
hashmap=True,
content_type=content_type,
if_etag_not_match='*' if if_not_exist else None,
etag=etag,
json=hashmap,
success=201)
......
......@@ -835,7 +835,6 @@ class PithosClient(TestCase):
json=dict(
hashes=['s0m3h@5h'] * num_of_blocks,
bytes=num_of_blocks * 4 * 1024 * 1024),
etag=None,
content_encoding=None,
content_type='application/octet-stream',
content_disposition=None,
......@@ -911,13 +910,18 @@ class PithosClient(TestCase):
tmpFile.seek(0)
kwargs = dict(
etag='s0m3E74g',
if_not_exist=True,
content_type=ctype,
content_disposition=ctype + 'd15p051710n',
public=True,
content_encoding='802.11')
self.client.upload_object(obj, tmpFile, **kwargs)
kwargs.pop('if_not_exist')
etag = kwargs.pop('etag')
for arg, val in kwargs.items():
self.assertEqual(OP.mock_calls[-2][2][arg], val)
self.assertEqual(OP.mock_calls[-1][2]['if_etag_not_match'], '*')
self.assertEqual(OP.mock_calls[-1][2]['etag'], etag)
def test_get_object_info(self):
FR.headers = object_info
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment