Skip to content

Commit 9ee3526

Browse files
committed
node: Hackily upgrade sha1 hashes to sha256
about time someone does something about this...
1 parent ebf116e commit 9ee3526

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

node/flatpak_node_generator/main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,23 @@ async def _async_main() -> None:
247247
gen.add_command(f'bash {gen.data_root / script_name}')
248248

249249
if args.split:
250+
sources = list(gen.ordered_sources())
251+
await Requests.instance.upgrade_to_sha256(sources)
252+
gen.set_upgraded_sources(sources)
250253
i = 0
251254
for i, part in enumerate(gen.split_sources()):
252255
output = Path(args.output)
253256
output = output.with_suffix(f'.{i}{output.suffix}')
254257
with open(output, 'w') as fp:
255258
json.dump(part, fp, indent=ManifestGenerator.JSON_INDENT)
256-
259+
delattr(gen, '_upgraded_sources')
257260
print(f'Wrote {gen.source_count} to {i + 1} file(s).')
258261
else:
262+
sources = list(gen.ordered_sources())
263+
await Requests.instance.upgrade_to_sha256(sources)
259264
with open(args.output, 'w') as fp:
260265
json.dump(
261-
list(gen.ordered_sources()),
266+
sources,
262267
fp,
263268
indent=ManifestGenerator.JSON_INDENT,
264269
)

node/flatpak_node_generator/manifest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ def tmp_root(self) -> Path:
4949
def source_count(self) -> int:
5050
return len(self._sources)
5151

52+
def set_upgraded_sources(self, sources: List[Dict[Any, Any]]) -> None:
53+
self._upgraded_sources = sources
54+
5255
def ordered_sources(self) -> Iterator[Dict[Any, Any]]:
56+
if hasattr(self, '_upgraded_sources'):
57+
return iter(self._upgraded_sources)
5358
return map(dict, sorted(self._sources))
5459

5560
def split_sources(self) -> Iterator[List[Dict[Any, Any]]]:

node/flatpak_node_generator/requests.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from typing import AsyncIterator, ClassVar
1+
from typing import Any, AsyncIterator, ClassVar
22

33
import contextlib
4+
import hashlib
45

56
import aiohttp
67

@@ -82,6 +83,20 @@ async def read_all(self, url: str, *, cachable: bool = False) -> bytes:
8283

8384
assert False
8485

86+
async def upgrade_to_sha256(self, sources: list[dict[str, Any]]) -> None:
87+
for source in sources:
88+
if 'sha1' in source and 'url' in source:
89+
sha1_digest = source['sha1']
90+
url = source['url']
91+
try:
92+
data = await self.read_all(url, cachable=True)
93+
except (aiohttp.ClientError, OSError):
94+
continue
95+
if data:
96+
sha256_digest = hashlib.sha256(data).hexdigest()
97+
source['sha256'] = sha256_digest
98+
del source['sha1']
99+
85100

86101
class StubRequests(Requests):
87102
async def _read_parts(

0 commit comments

Comments
 (0)