aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/state_impl
diff options
context:
space:
mode:
Diffstat (limited to 'src/hydrilla/proxy/state_impl')
-rw-r--r--src/hydrilla/proxy/state_impl/_operations/pull_missing_files.py9
-rw-r--r--src/hydrilla/proxy/state_impl/base.py37
2 files changed, 41 insertions, 5 deletions
diff --git a/src/hydrilla/proxy/state_impl/_operations/pull_missing_files.py b/src/hydrilla/proxy/state_impl/_operations/pull_missing_files.py
index 04a2910..f1e0414 100644
--- a/src/hydrilla/proxy/state_impl/_operations/pull_missing_files.py
+++ b/src/hydrilla/proxy/state_impl/_operations/pull_missing_files.py
@@ -81,17 +81,16 @@ def pull_missing_files(
try:
url = urljoin(repo_url, f'file/sha256/{sha256}')
response = requests.get(url)
- except:
- raise state.RepoCommunicationError()
- if not response.ok:
+ assert response.ok
+
+ file_bytes = response.content
+ except:
raise state.FileMissingError(
repo_id = str(repo_id),
sha256 = sha256
)
- file_bytes = response.content
-
computed_sha256 = hashlib.sha256(file_bytes).digest().hex()
if computed_sha256 != sha256:
raise state.FileIntegrityError(
diff --git a/src/hydrilla/proxy/state_impl/base.py b/src/hydrilla/proxy/state_impl/base.py
index 25fd4c5..a889e71 100644
--- a/src/hydrilla/proxy/state_impl/base.py
+++ b/src/hydrilla/proxy/state_impl/base.py
@@ -78,6 +78,34 @@ class PolicyTree(pattern_tree.PatternTree[policies.PolicyFactory]):
return policy_tree
+def mark_failed_file_installs(
+ cursor: sqlite3.Cursor,
+ file_sha256: str,
+ repo_id: int
+) -> None:
+ cursor.execute(
+ '''
+ WITH failed_items AS (
+ SELECT DISTINCT
+ item_version_id
+ FROM
+ files AS f
+ JOIN file_uses AS fu USING (file_id)
+ JOIN item_versions_extra AS ive USING (item_version_id)
+ WHERE
+ f.sha256 = ? AND f.data IS NULL AND ive.repo_id = ?
+ )
+ UPDATE
+ item_versions
+ SET
+ installed = 'F'
+ WHERE
+ item_version_id IN failed_items;
+ ''',
+ (file_sha256, repo_id)
+ )
+
+
PayloadsData = t.Mapping[st.PayloadRef, st.PayloadData]
# mypy needs to be corrected:
@@ -123,6 +151,15 @@ class HaketiloStateWithFields(st.HaketiloState):
if start_transaction:
self.current_cursor.execute('ROLLBACK TRANSACTION;')
raise
+ except st.FileInstallationError as ex:
+ if start_transaction:
+ assert self.current_cursor is not None
+ mark_failed_file_installs(
+ cursor = self.current_cursor,
+ file_sha256 = ex.sha256,
+ repo_id = int(ex.repo_id)
+ )
+ raise
finally:
self.current_cursor = None