Skip to content

Commit 5071913

Browse files
committed
StorageService supports IfNoneMatch param
1 parent 27d1b17 commit 5071913

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/azul/indexer/mirror_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def mirror_file(self, catalog: CatalogName, file: File):
155155
file_content = self._download(catalog, file)
156156
self._storage(catalog).put(object_key=self.mirror_object_key(file),
157157
data=file_content,
158-
content_type=file.content_type)
158+
content_type=file.content_type,
159+
IfNoneMatch='*')
159160
_, digest_type = file.digest()
160161
hasher = get_resumable_hasher(digest_type)
161162
hasher.update(file_content)

src/azul/service/storage_service.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ def put(self,
110110
data: bytes,
111111
content_type: str | None = None,
112112
tagging: Tagging | None = None,
113+
*,
114+
exists_okay: bool = True,
113115
**kwargs):
114116
self._s3.put_object(Bucket=self.bucket_name,
115117
Key=object_key,
116118
Body=data,
117-
**self._object_creation_kwargs(content_type=content_type, tagging=tagging),
119+
**self._object_creation_kwargs(content_type=content_type,
120+
tagging=tagging,
121+
exists_okay=exists_okay),
118122
**kwargs)
119123

120124
def list(self, prefix: str) -> OrderedSet[str]:
@@ -155,15 +159,19 @@ def upload_multipart_part(self,
155159

156160
def complete_multipart_upload(self,
157161
upload: MultipartUpload,
158-
etags: Sequence[str]) -> None:
162+
etags: Sequence[str],
163+
*,
164+
exists_okay: bool = True,
165+
) -> None:
159166
parts = [
160167
{
161168
'PartNumber': index + 1,
162169
'ETag': etag
163170
}
164171
for index, etag in enumerate(etags)
165172
]
166-
upload.complete(MultipartUpload={'Parts': parts})
173+
upload.complete(MultipartUpload={'Parts': parts},
174+
**self._object_creation_kwargs(exists_okay=exists_okay))
167175

168176
def upload(self,
169177
file_path: str,
@@ -181,12 +189,16 @@ def upload(self,
181189

182190
def _object_creation_kwargs(self, *,
183191
content_type: str | None = None,
184-
tagging: Tagging | None = None):
192+
tagging: Tagging | None = None,
193+
exists_okay: bool = True
194+
) -> Mapping[str, str]:
185195
kwargs = {}
186196
if content_type is not None:
187197
kwargs['ContentType'] = content_type
188198
if tagging is not None:
189199
kwargs['Tagging'] = urlencode(tagging)
200+
if exists_okay is False:
201+
kwargs['IfNoneMatch'] = '*'
190202
return kwargs
191203

192204
def get_presigned_url(self, key: str, file_name: str | None = None) -> str:

0 commit comments

Comments
 (0)