Skip to content

Commit

Permalink
added package manifest id check
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed May 30, 2024
1 parent e64f165 commit cb82de3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
7 changes: 3 additions & 4 deletions repogen/downloadipk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
except (requests.exceptions.JSONDecodeError, json.decoder.JSONDecodeError) as e:
print(f'Could not parse manifest: {e}')
exit(2)
except requests.RequestException as e:
print(f'Could not download package info: {e}')
exit(5)
except IOError as e:
print(f'Could not open package info file: {e.strerror}')
exit(3)
except ValidationError as e:
print(f'Could not parse package info: {e.message}')
exit(4)

if pkginfo is None:
print(f'Failed to get manifest for unknown reason')
exit(5)

try:
ipk_url = pkginfo['manifest']['ipkUrl']
except KeyError as e:
Expand Down
15 changes: 12 additions & 3 deletions repogen/lintpkg.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from pathlib import Path
from typing import Tuple, List
from urllib.parse import urlparse
Expand Down Expand Up @@ -40,6 +41,9 @@ def lint(self, info: PackageInfo) -> Tuple[List[str], List[str]]:
if info['pool'] not in ['main', 'non-free']:
errors.append('pool property must be `main` or `non-free`')

if info['id'] != info['manifest']['id']:
errors.append('id in manifest must match id in info')

# Process icon
icon_uri = urlparse(info['iconUri'])
if icon_uri.scheme == 'data' or icon_uri.scheme == 'https':
Expand Down Expand Up @@ -89,9 +93,14 @@ def _validate_manifest_url(url: str, key: str, e: [str]):
parser.add_argument('-f', '--file', required=True)
args = parser.parse_args()

lint_pkginfo = pkg_info.from_package_info_file(Path(args.file))
if lint_pkginfo is None:
raise ValueError('No package info')
try:
lint_pkginfo = pkg_info.from_package_info_file(Path(args.file))
except requests.exceptions.RequestException as e:
print(f'Could not download package info: {e}', file=sys.stderr)
exit(5)
except IOError as e:
print(f'Could not open package info file: {e.strerror}', file=sys.stderr)
exit(3)

linter = PackageInfoLinter()
lint_errors, lint_warnings = linter.lint(lint_pkginfo)
Expand Down
2 changes: 1 addition & 1 deletion repogen/pkg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def load_registry(info_path: Path) -> tuple[str, PackageRegistry]:
return pkgid, content


def from_package_info_file(info_path: Path, offline=False) -> PackageInfo | None:
def from_package_info_file(info_path: Path, offline=False) -> PackageInfo:
pkgid, content = load_registry(info_path)
return from_package_info(pkgid, content, offline)

Expand Down
3 changes: 3 additions & 0 deletions repogen/pkg_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import urllib.parse
from datetime import datetime
from email.utils import parsedate_to_datetime
from json import JSONDecodeError
from typing import TypedDict, NotRequired, Literal
from urllib.parse import urljoin
from urllib.request import url2pathname
Expand Down Expand Up @@ -51,6 +52,8 @@ def obtain_manifest(pkgid: str, channel: str, uri: str, offline: bool = False) -
raise requests.exceptions.ConnectionError('Offline')
uri = url_fixup(uri)
resp = requests.get(url=uri, allow_redirects=True)
if resp.status_code != 200:
raise requests.exceptions.HTTPError(f'Failed to fetch manifest: HTTP {resp.status_code}')
manifest = resp.json()
manifest['ipkUrl'] = urljoin(uri, manifest['ipkUrl'])
manifest['ipkSize'] = url_size(manifest['ipkUrl'])
Expand Down

0 comments on commit cb82de3

Please sign in to comment.