Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions qfieldcloud_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,11 @@ def download_file(
```
"""

headers: dict[str, str] = {}
if remote_etag and local_filename.exists():
if calc_etag(str(local_filename)) == remote_etag:
local_etag = calc_etag(str(local_filename))

if local_etag == remote_etag:
if show_progress:
print(
f"{remote_filename}: Already present locally. Download skipped."
Expand All @@ -1140,14 +1143,22 @@ def download_file(
)
return None

headers["If-None-Match"] = local_etag

if download_type == FileTransferType.PROJECT:
url = f"files/{project_id}/{remote_filename}"
elif download_type == FileTransferType.PACKAGE:
url = f"packages/{project_id}/latest/files/{remote_filename}"
else:
raise NotImplementedError()

resp = self._request("GET", url, stream=True)
resp = self._request("GET", url, stream=True, headers=headers)

# Since we are sending the `If-None-Match` header to check the `ETag` of the remote file,
# we shall expect HTTP 304 in case the local and remote `ETag` match.
# The early return will prevent overwriting the file with empty contents of the 304 response.
if resp.status_code == 304:
return None

if not local_filename.parent.exists():
local_filename.parent.mkdir(parents=True)
Expand Down