|
13 | 13 |
|
14 | 14 | from pkgcore.ebuild.misc import sort_keywords |
15 | 15 | from pkgcore.ebuild.repository import UnconfiguredTree |
| 16 | +from pkgcore.fetch import fetchable |
16 | 17 | from snakeoil import klass |
17 | 18 | from snakeoil.mappings import ImmutableDict |
18 | 19 | from snakeoil.osutils import pjoin |
| 20 | +from snakeoil.sequences import iflatten_instance |
19 | 21 | from snakeoil.strings import pluralism |
20 | 22 |
|
21 | 23 | from .. import base, results, sources |
@@ -169,6 +171,38 @@ def desc(self): |
169 | 171 | return f"renamed package: {self.old} -> {self.new}" |
170 | 172 |
|
171 | 173 |
|
| 174 | +class SrcUriChecksumChange(results.PackageResult, results.Error): |
| 175 | + """SRC_URI changing checksum without distfile rename.""" |
| 176 | + |
| 177 | + def __init__(self, filename, **kwargs): |
| 178 | + super().__init__(**kwargs) |
| 179 | + self.filename = filename |
| 180 | + |
| 181 | + @property |
| 182 | + def desc(self): |
| 183 | + return f"{self.filename!r} has different checksums across commits" |
| 184 | + |
| 185 | + |
| 186 | +class SuspiciousSrcUriChange(results.PackageResult, results.Warning): |
| 187 | + """Suspicious SRC_URI changing URI without distfile rename.""" |
| 188 | + |
| 189 | + def __init__(self, old_uri, new_uri, filename, **kwargs): |
| 190 | + 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) |
| 199 | + self.filename = filename |
| 200 | + |
| 201 | + @property |
| 202 | + def desc(self): |
| 203 | + return f"{self.filename!r} has changed SRC_URI from {self.old_uri!r} to {self.new_uri!r}" |
| 204 | + |
| 205 | + |
172 | 206 | class _RemovalRepo(UnconfiguredTree): |
173 | 207 | """Repository of removed packages stored in a temporary directory.""" |
174 | 208 |
|
@@ -235,6 +269,8 @@ class GitPkgCommitsCheck(GentooRepoCheck, GitCommitsCheck): |
235 | 269 | DroppedUnstableKeywords, |
236 | 270 | MissingSlotmove, |
237 | 271 | MissingMove, |
| 272 | + SrcUriChecksumChange, |
| 273 | + SuspiciousSrcUriChange, |
238 | 274 | ] |
239 | 275 | ) |
240 | 276 |
|
@@ -345,7 +381,34 @@ def modified_checks(self, pkgs): |
345 | 381 | else: |
346 | 382 | yield MissingSlotmove(old_slot, new_slot, pkg=new_pkg) |
347 | 383 |
|
348 | | - def feed(self, pkgset): |
| 384 | + def src_uri_changes(self, pkgset): |
| 385 | + pkg = pkgset[0].unversioned_atom |
| 386 | + |
| 387 | + try: |
| 388 | + new_checksums = { |
| 389 | + fetch.filename: (fetch.chksums, tuple(fetch.uri._uri_source)) |
| 390 | + for pkg in self.repo.match(pkg) |
| 391 | + for fetch in iflatten_instance(pkg.fetchables, fetchable) |
| 392 | + } |
| 393 | + |
| 394 | + old_checksums = { |
| 395 | + fetch.filename: (fetch.chksums, tuple(fetch.uri._uri_source)) |
| 396 | + for pkg in self.modified_repo(pkgset).match(pkg) |
| 397 | + for fetch in iflatten_instance(pkg.fetchables, fetchable) |
| 398 | + } |
| 399 | + except (IndexError, FileNotFoundError, tarfile.ReadError): |
| 400 | + # ignore broken ebuild |
| 401 | + return |
| 402 | + |
| 403 | + for filename in old_checksums.keys() & new_checksums.keys(): |
| 404 | + old_checksum, old_uri = old_checksums[filename] |
| 405 | + new_checksum, new_uri = new_checksums[filename] |
| 406 | + if old_checksum != new_checksum: |
| 407 | + yield SrcUriChecksumChange(filename, pkg=pkg) |
| 408 | + elif old_uri != new_uri: |
| 409 | + yield SuspiciousSrcUriChange(old_uri[0], new_uri[0], filename, pkg=pkg) |
| 410 | + |
| 411 | + def feed(self, pkgset: list[git.GitPkgChange]): |
349 | 412 | # Mapping of commit types to pkgs, available commit types can be seen |
350 | 413 | # under the --diff-filter option in git log parsing support and are |
351 | 414 | # disambiguated as follows: |
@@ -407,6 +470,8 @@ def feed(self, pkgset): |
407 | 470 | if not pkg.maintainers and newly_added: |
408 | 471 | yield DirectNoMaintainer(pkg=pkg) |
409 | 472 |
|
| 473 | + yield from self.src_uri_changes(pkgset) |
| 474 | + |
410 | 475 |
|
411 | 476 | class MissingSignOff(results.CommitResult, results.Error): |
412 | 477 | """Local commit with missing sign offs. |
|
0 commit comments