Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Regex repairs and epoch stripping fix #410

Merged
merged 3 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
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
25 changes: 11 additions & 14 deletions src/retrace/retrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,7 @@ def run_gdb(savedir: Union[str, Path], plugin, repopath: str, taskid: int):


def remove_epoch(nvr: str) -> str:
pos = nvr.find(":")
if pos > 0:
return nvr[pos + 1:]
return nvr
return re.sub("[1-9][0-9]*:", "", nvr)


def is_package_known(package_nvr: str, arch: str, releaseid: Optional[str] = None):
Expand All @@ -361,7 +358,7 @@ def is_package_known(package_nvr: str, arch: str, releaseid: Optional[str] = Non
from pyfaf.queries import get_package_by_nevra

db = getDatabase()
(n, v, r, e, _a) = splitFilename(package_nvr+".mockarch.rpm")
(n, v, r, e, _a) = splitFilename(f"{package_nvr}.mockarch.rpm")
for derived_archs in ARCH_MAP.values():
if arch not in derived_archs:
continue
Expand All @@ -371,10 +368,7 @@ def is_package_known(package_nvr: str, arch: str, releaseid: Optional[str] = Non
return True
# Try with noarch
p = get_package_by_nevra(db, n, e or 0, v, r, "noarch")
if p is not None:
return True

return False
return p is not None

if releaseid is None:
releases = get_supported_releases()
Expand All @@ -384,20 +378,23 @@ def is_package_known(package_nvr: str, arch: str, releaseid: Optional[str] = Non
candidates = []
package_nvr = remove_epoch(package_nvr)
repodir = Path(CONFIG["RepoDir"])

for release in releases:
repopath = repodir / release

for derived_archs in ARCH_MAP.values():
if arch not in derived_archs:
continue

for a in derived_archs:
candidates.append(Path(repodir, release, "Packages", "%s.%s.rpm" % (package_nvr, a)))
candidates.append(Path(repodir, release, "%s.%s.rpm" % (package_nvr, a)))
candidates.append(repopath / "Packages" / f"{package_nvr}.{a}.rpm")
candidates.append(repopath / f"{package_nvr}.{a}.rpm")
break
else:
candidates.append(Path(repodir, release, "Packages", "%s.%s.rpm" % (package_nvr, arch)))
candidates.append(Path(repodir, release, "%s.%s.rpm" % (package_nvr, arch)))
candidates.append(repopath / "Packages" / f"{package_nvr}.{arch}.rpm")
candidates.append(repopath / f"{package_nvr}.{arch}.rpm")

return any([f.is_file() for f in candidates])
return any(f.is_file() for f in candidates)


def cache_files_from_debuginfo(debuginfo: Path, basedir: Path, files: List[str]) -> None:
Expand Down
8 changes: 4 additions & 4 deletions src/retrace/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
DF_OUTPUT_PARSER = re.compile(r"^([^ ^\t]*)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+%)[ \t]+(.*)$")

# architecture (i386, x86_64, armv7hl, mips4kec)
INPUT_ARCH_PARSER = re.compile(r"^[\w\d_]+$")
INPUT_ARCH_PARSER = re.compile(r"^\w+$", re.ASCII)
# characters, numbers, dash (utf-8, iso-8859-2 etc.)
INPUT_CHARSET_PARSER = re.compile(r"^([\w\d-]+)(,.*)?$")
INPUT_CHARSET_PARSER = re.compile(r"^([a-zA-Z0-9-]+)(,.*)?$")
# en_GB, sk-SK, cs, fr etc.
INPUT_LANG_PARSER = re.compile(r"^([a-z]{2}([_\-][A-Z]{2})?)(,.*)?$")
# characters allowed by Fedora Naming Guidelines
INPUT_PACKAGE_PARSER = re.compile(r"^[\w\d_.+-]+([1-9][0-9]*:)?[\w\d.+~-]+$")
INPUT_PACKAGE_PARSER = re.compile(r"^[\w.+-]+([1-9][0-9]*:)?[a-zA-Z0-9.+~-]+$", re.ASCII)
# name-version-arch (fedora-16-x86_64, rhel-6.2-i386, opensuse-12.1-x86_64)
INPUT_RELEASEID_PARSER = re.compile(r"^[\w\d]+-[\w\d.]+-[\w\d_]+$")
INPUT_RELEASEID_PARSER = re.compile(r"^[a-zA-Z0-9]+-[a-zA-Z0-9.]+-\w+$", re.ASCII)

UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB"]
URL_PARSER = re.compile(r"^/([0-9]+)/?")
Expand Down