Preserve failed-run checkpoint when snapshot receipts are invalid
Metadata integrity checks / metadata (push) Successful in 2m44s
Metadata integrity checks / metadata (push) Successful in 2m44s
This commit is contained in:
@@ -6,7 +6,6 @@ import hashlib
|
|||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import re
|
import re
|
||||||
import tempfile
|
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
from paper_atlas.io.html import Document, Node, clean
|
from paper_atlas.io.html import Document, Node, clean
|
||||||
@@ -147,11 +146,15 @@ def collect(out, *, snapshots=None, cache=None):
|
|||||||
evidence = {}; receipts = {}
|
evidence = {}; receipts = {}
|
||||||
if snapshots is not None:
|
if snapshots is not None:
|
||||||
root = Path(snapshots)
|
root = Path(snapshots)
|
||||||
for r in json.loads((root/'receipts.json').read_bytes()):
|
try:
|
||||||
name = r['file']
|
for r in json.loads((root/'receipts.json').read_bytes()):
|
||||||
if not isinstance(name, str) or Path(name).name != name or name in receipts:
|
name = r['file']
|
||||||
raise ValueError('Unsafe or repeated snapshot receipt')
|
if not isinstance(name, str) or Path(name).name != name or name in receipts:
|
||||||
receipts[name] = r
|
raise ValueError('Unsafe or repeated snapshot receipt')
|
||||||
|
receipts[name] = r
|
||||||
|
except Exception as error:
|
||||||
|
(out/'failed.json').write_text(json.dumps({'status': 'failed_not_complete', 'error_type': type(error).__name__, 'database_written': False})+'\n')
|
||||||
|
raise
|
||||||
def page(name, url):
|
def page(name, url):
|
||||||
if snapshots is not None:
|
if snapshots is not None:
|
||||||
path = root/name
|
path = root/name
|
||||||
|
|||||||
@@ -96,3 +96,5 @@ class Rss2026Tests(unittest.TestCase):
|
|||||||
receipts=[*self.fixture['receipts'],{**self.fixture['receipts'][0],'file':'../outside'}]
|
receipts=[*self.fixture['receipts'],{**self.fixture['receipts'][0],'file':'../outside'}]
|
||||||
(self.snap/'receipts.json').write_text(json.dumps(receipts))
|
(self.snap/'receipts.json').write_text(json.dumps(receipts))
|
||||||
with self.assertRaisesRegex(ValueError,'Unsafe'):rss.collect(self.root/'unsafe',snapshots=self.snap)
|
with self.assertRaisesRegex(ValueError,'Unsafe'):rss.collect(self.root/'unsafe',snapshots=self.snap)
|
||||||
|
self.assertTrue((self.root/'unsafe/failed.json').exists())
|
||||||
|
self.assertFalse((self.root/'unsafe/collection-report.json').exists())
|
||||||
|
|||||||
Reference in New Issue
Block a user