Skip to content

Commit 7d50c22

Browse files
committed
SuspiciousSrcUriChange: fix false positive with mirrors
The original code for comparing for URL change was giving false positives when the URI is mirror based, since an object was used to compare. Pre-compute the URI string and use strings for comparison. Also add a test for that failure. Resolves: #531 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 02804d8 commit 7d50c22

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

src/pkgcheck/checks/git.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,10 @@ def desc(self):
186186
class SuspiciousSrcUriChange(results.PackageResult, results.Warning):
187187
"""Suspicious SRC_URI changing URI without distfile rename."""
188188

189-
def __init__(self, old_uri, new_uri, filename, **kwargs):
189+
def __init__(self, old_uri: str, new_uri: str, filename: str, **kwargs):
190190
super().__init__(**kwargs)
191-
if isinstance(old_uri, tuple):
192-
self.old_uri = f"mirror://{old_uri[0].mirror_name}/{old_uri[1]}"
193-
else:
194-
self.old_uri = str(old_uri)
195-
if isinstance(new_uri, tuple):
196-
self.new_uri = f"mirror://{new_uri[0].mirror_name}/{new_uri[1]}"
197-
else:
198-
self.new_uri = str(new_uri)
191+
self.old_uri = old_uri
192+
self.new_uri = new_uri
199193
self.filename = filename
200194

201195
@property
@@ -381,18 +375,26 @@ def modified_checks(self, pkgs):
381375
else:
382376
yield MissingSlotmove(old_slot, new_slot, pkg=new_pkg)
383377

378+
@staticmethod
379+
def _fetchable_str(fetch: fetchable) -> str:
380+
uri = tuple(fetch.uri._uri_source)[0]
381+
if isinstance(uri, tuple):
382+
return f"mirror://{uri[0].mirror_name}/{uri[1]}"
383+
else:
384+
return str(uri)
385+
384386
def src_uri_changes(self, pkgset):
385387
pkg = pkgset[0].unversioned_atom
386388

387389
try:
388390
new_checksums = {
389-
fetch.filename: (fetch.chksums, tuple(fetch.uri._uri_source))
391+
fetch.filename: (fetch.chksums, self._fetchable_str(fetch))
390392
for pkg in self.repo.match(pkg)
391393
for fetch in iflatten_instance(pkg.fetchables, fetchable)
392394
}
393395

394396
old_checksums = {
395-
fetch.filename: (fetch.chksums, tuple(fetch.uri._uri_source))
397+
fetch.filename: (fetch.chksums, self._fetchable_str(fetch))
396398
for pkg in self.modified_repo(pkgset).match(pkg)
397399
for fetch in iflatten_instance(pkg.fetchables, fetchable)
398400
}
@@ -406,7 +408,7 @@ def src_uri_changes(self, pkgset):
406408
if old_checksum != new_checksum:
407409
yield SrcUriChecksumChange(filename, pkg=pkg)
408410
elif old_uri != new_uri:
409-
yield SuspiciousSrcUriChange(old_uri[0], new_uri[0], filename, pkg=pkg)
411+
yield SuspiciousSrcUriChange(old_uri, new_uri, filename, pkg=pkg)
410412

411413
def feed(self, pkgset: list[git.GitPkgChange]):
412414
# Mapping of commit types to pkgs, available commit types can be seen

tests/checks/test_git.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,12 @@ def test_src_uri_change(self):
702702
self.init_check()
703703
r = self.assertReport(self.check, self.source)
704704
assert r == git_mod.SuspiciousSrcUriChange(old_url, new_url, distfile[1], pkg=CP("cat/pkg"))
705+
# revert change and check for no report with same mirror url
706+
self.child_git_repo.run(["git", "reset", "--hard", "origin/main"])
707+
self.child_repo.create_ebuild("cat/pkg-1", src_uri=old_url, eapi="8")
708+
self.child_git_repo.add_all("cat/pkg: bump EAPI", signoff=True)
709+
self.init_check()
710+
self.assertNoReport(self.check, self.source)
705711

706712

707713
class TestGitEclassCommitsCheck(ReportTestCase):

0 commit comments

Comments
 (0)