Coverage for daklib/checks.py: 70%
664 statements
« prev ^ index » next coverage.py v7.6.0, created at 2026-11-21 08:51 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2026-11-21 08:51 +0000
1# Copyright (C) 2012, Ansgar Burchardt <ansgar@debian.org>
2#
3# Parts based on code that is
4# Copyright (C) 2001-2006, James Troup <james@nocrew.org>
5# Copyright (C) 2009-2010, Joerg Jaspert <joerg@debian.org>
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21"""module provided pre-acceptance tests
23Please read the documentation for the :class:`Check` class for the interface.
24"""
26import datetime
27import os
28import re
29import subprocess
30import tempfile
31import textwrap
32import time
33from collections.abc import Callable, Iterable
34from typing import TYPE_CHECKING, Literal, cast, override
36import apt_inst
37import apt_pkg
38import yaml
39from apt_pkg import version_compare
40from sqlalchemy import select
42import daklib.gpg
43import daklib.upload
44from daklib import dbconn, lintian, utils
45from daklib.config import Config
46from daklib.dbconn import (
47 ACL,
48 ACLPerSource,
49 Architecture,
50 DBBinary,
51 DBSource,
52 SignatureHistory,
53 SrcFormat,
54 Suite,
55 external_files,
56 get_source_in_suite,
57)
58from daklib.regexes import (
59 re_field_package,
60 re_field_source,
61 re_field_version,
62 re_field_version_upstream,
63 re_file_binary,
64 re_file_changes,
65 re_file_dsc,
66 re_file_orig,
67 re_file_source,
68 re_isanum,
69)
70from daklib.textutils import ParseMaintError, fix_maintainer
72if TYPE_CHECKING:
73 from sqlalchemy.orm import Session
75 import daklib.archive
78def check_fields_for_valid_utf8(filename: str, control: apt_pkg.TagSection) -> None:
79 """Check all fields of a control file for valid UTF-8"""
80 for field in control.keys():
81 try:
82 # Access the field value to make `TagSection` try to decode it.
83 # We should also do the same for the field name, but this requires
84 # https://bugs.debian.org/995118 to be fixed.
85 # TODO: make sure the field name `field` is valid UTF-8 too
86 control[field]
87 except UnicodeDecodeError:
88 raise Reject(
89 "{0}: The {1} field is not valid UTF-8".format(filename, field)
90 )
93class Reject(Exception):
94 """exception raised by failing checks"""
97class RejectExternalFilesMismatch(Reject):
98 """exception raised by failing the external hashes check"""
100 @override
101 def __str__(self):
102 return (
103 "'%s' has mismatching %s from the external files db ('%s' [current] vs '%s' [external])"
104 % self.args[:4]
105 )
108class RejectACL(Reject):
109 """exception raise by failing ACL checks"""
111 def __init__(self, acl: ACL, reason: str):
112 self.acl = acl
113 self.reason = reason
115 @override
116 def __str__(self):
117 return "ACL {0}: {1}".format(self.acl.name, self.reason)
120class Check:
121 """base class for checks
123 checks are called by :class:`daklib.archive.ArchiveUpload`. Failing tests should
124 raise a :exc:`daklib.checks.Reject` exception including a human-readable
125 description why the upload should be rejected.
126 """
128 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
129 """do checks
131 :param upload: upload to check
133 :raises Reject: upload should be rejected
134 """
135 raise NotImplementedError
137 def per_suite_check(
138 self, upload: "daklib.archive.ArchiveUpload", suite: Suite
139 ) -> bool:
140 """do per-suite checks
142 :param upload: upload to check
143 :param suite: suite to check
145 :raises Reject: upload should be rejected
146 """
147 raise NotImplementedError
149 @property
150 def forcable(self) -> bool:
151 """allow to force ignore failing test
153 :const:`True` if it is acceptable to force ignoring a failing test,
154 :const:`False` otherwise
155 """
156 return False
159class SignatureAndHashesCheck(Check):
160 """Check signature of changes and dsc file (if included in upload)
162 Make sure the signature is valid and done by a known user.
163 """
165 def check_replay(self, upload: "daklib.archive.ArchiveUpload") -> bool:
166 # Use private session as we want to remember having seen the .changes
167 # in all cases.
168 session = upload.session
169 history = SignatureHistory.from_signed_file(upload.changes.signature)
170 r = history.query(session)
171 if r is not None: 171 ↛ 172line 171 didn't jump to line 172 because the condition on line 171 was never true
172 raise Reject(
173 "Signature for changes file was already seen at {0}.\nPlease refresh the signature of the changes file if you want to upload it again.".format(
174 r.seen
175 )
176 )
177 return True
179 @override
180 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
181 allow_source_untrusted_sig_keys = Config().value_list(
182 "Dinstall::AllowSourceUntrustedSigKeys"
183 )
185 changes = upload.changes
186 if not changes.valid_signature: 186 ↛ 187line 186 didn't jump to line 187 because the condition on line 186 was never true
187 raise Reject("Signature for .changes not valid.")
188 self.check_replay(upload)
189 self._check_hashes(upload, changes.filename, changes.files.values())
191 source = None
192 try:
193 source = changes.source
194 except Exception as e:
195 raise Reject("Invalid dsc file: {0}".format(e))
196 if source is not None:
197 if changes.primary_fingerprint not in allow_source_untrusted_sig_keys: 197 ↛ 202line 197 didn't jump to line 202 because the condition on line 197 was always true
198 if not source.valid_signature: 198 ↛ 199line 198 didn't jump to line 199 because the condition on line 198 was never true
199 raise Reject("Signature for .dsc not valid.")
200 if source.primary_fingerprint != changes.primary_fingerprint: 200 ↛ 201line 200 didn't jump to line 201 because the condition on line 200 was never true
201 raise Reject(".changes and .dsc not signed by the same key.")
202 self._check_hashes(upload, source.filename, source.files.values())
204 if upload.fingerprint is None or upload.fingerprint.uid is None:
205 raise Reject(".changes signed by unknown key.")
207 return True
209 def _check_hashes(
210 self,
211 upload: "daklib.archive.ArchiveUpload",
212 filename: str,
213 files: Iterable[daklib.upload.HashedFile],
214 ) -> None:
215 """Make sure hashes match existing files
217 :param upload: upload we are processing
218 :param filename: name of the file the expected hash values are taken from
219 :param files: files to check the hashes for
220 """
221 try:
222 for f in files:
223 f.check(upload.directory)
224 except daklib.upload.FileDoesNotExist as e: 224 ↛ 232line 224 didn't jump to line 232
225 raise Reject(
226 "{0}: {1}\n"
227 "Perhaps you need to include the file in your upload?\n\n"
228 "If the orig tarball is missing, the -sa flag for dpkg-buildpackage will be your friend.".format(
229 filename, str(e)
230 )
231 )
232 except daklib.upload.UploadException as e:
233 raise Reject("{0}: {1}".format(filename, str(e)))
236class WeakSignatureCheck(Check):
237 """Check that .changes and .dsc are not signed using a weak algorithm"""
239 @override
240 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
241 changes = upload.changes
242 if changes.weak_signature: 242 ↛ 243line 242 didn't jump to line 243 because the condition on line 242 was never true
243 raise Reject(
244 "The .changes was signed using a weak algorithm (such as SHA-1)"
245 )
247 source = changes.source
248 if source is not None and source.weak_signature: 248 ↛ 249line 248 didn't jump to line 249 because the condition on line 248 was never true
249 raise Reject(
250 "The source package was signed using a weak algorithm (such as SHA-1)"
251 )
253 return True
256def check_signature_timestamp(prefix: str, signed_file: daklib.gpg.SignedFile) -> bool:
257 now = datetime.datetime.now(datetime.UTC)
258 timestamp = signed_file.signature_timestamp
259 age = now - timestamp
261 age_max = datetime.timedelta(days=365)
262 age_min = datetime.timedelta(days=-7)
264 if age > age_max: 264 ↛ 265line 264 didn't jump to line 265 because the condition on line 264 was never true
265 raise Reject(
266 "{0}: Signature from {1} is too old (maximum age is {2} days)".format(
267 prefix, timestamp, age_max.days
268 )
269 )
270 if age < age_min: 270 ↛ 271line 270 didn't jump to line 271 because the condition on line 270 was never true
271 raise Reject(
272 "{0}: Signature from {1} is too far in the future (tolerance is {2} days)".format(
273 prefix, timestamp, abs(age_min.days)
274 )
275 )
276 return True
279class SignatureTimestampCheck(Check):
280 """Check timestamp of .changes signature"""
282 @override
283 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
284 return check_signature_timestamp(
285 upload.changes.filename, upload.changes.signature
286 )
289class ChangesCheck(Check):
290 """Check changes file for syntax errors."""
292 @override
293 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
294 changes = upload.changes
295 control = changes.changes
296 fn = changes.filename
298 for field in (
299 "Distribution",
300 "Source",
301 "Architecture",
302 "Version",
303 "Maintainer",
304 "Files",
305 "Changes",
306 ):
307 if field not in control: 307 ↛ 308line 307 didn't jump to line 308 because the condition on line 307 was never true
308 raise Reject("{0}: misses mandatory field {1}".format(fn, field))
310 if len(changes.binaries) > 0:
311 for field in ("Binary", "Description"):
312 if field not in control: 312 ↛ 313line 312 didn't jump to line 313 because the condition on line 312 was never true
313 raise Reject(
314 "{0}: binary upload requires {1} field".format(fn, field)
315 )
317 check_fields_for_valid_utf8(fn, control)
319 source_match = re_field_source.match(control["Source"])
320 if not source_match: 320 ↛ 321line 320 didn't jump to line 321 because the condition on line 320 was never true
321 raise Reject("{0}: Invalid Source field".format(fn))
322 version_match = re_field_version.match(control["Version"])
323 if not version_match: 323 ↛ 324line 323 didn't jump to line 324 because the condition on line 323 was never true
324 raise Reject("{0}: Invalid Version field".format(fn))
325 version_without_epoch = version_match.group("without_epoch")
327 match = re_file_changes.match(fn)
328 if not match: 328 ↛ 329line 328 didn't jump to line 329 because the condition on line 328 was never true
329 raise Reject("{0}: Does not match re_file_changes".format(fn))
330 if match.group("package") != source_match.group("package"): 330 ↛ 331line 330 didn't jump to line 331 because the condition on line 330 was never true
331 raise Reject("{0}: Filename does not match Source field".format(fn))
332 if match.group("version") != version_without_epoch: 332 ↛ 333line 332 didn't jump to line 333 because the condition on line 332 was never true
333 raise Reject("{0}: Filename does not match Version field".format(fn))
335 for bn in changes.binary_names:
336 if not re_field_package.match(bn): 336 ↛ 337line 336 didn't jump to line 337 because the condition on line 336 was never true
337 raise Reject("{0}: Invalid binary package name {1}".format(fn, bn))
339 if changes.sourceful and changes.source is None: 339 ↛ 340line 339 didn't jump to line 340 because the condition on line 339 was never true
340 raise Reject("Changes has architecture source, but no source found.")
341 if changes.source is not None and not changes.sourceful: 341 ↛ 342line 341 didn't jump to line 342 because the condition on line 341 was never true
342 raise Reject("Upload includes source, but changes does not say so.")
344 try:
345 fix_maintainer(changes.changes["Maintainer"])
346 except ParseMaintError as e:
347 raise Reject(
348 "{0}: Failed to parse Maintainer field: {1}".format(changes.filename, e)
349 )
351 try:
352 changed_by = changes.changes.get("Changed-By")
353 if changed_by is not None: 353 ↛ 360line 353 didn't jump to line 360 because the condition on line 353 was always true
354 fix_maintainer(changed_by)
355 except ParseMaintError as e:
356 raise Reject(
357 "{0}: Failed to parse Changed-By field: {1}".format(changes.filename, e)
358 )
360 try:
361 changes.byhand_files
362 except daklib.upload.InvalidChangesException as e:
363 raise Reject("{0}".format(e))
365 if len(changes.files) == 0: 365 ↛ 366line 365 didn't jump to line 366 because the condition on line 365 was never true
366 raise Reject("Changes includes no files.")
368 for bugnum in changes.closed_bugs: 368 ↛ 369line 368 didn't jump to line 369 because the loop on line 368 never started
369 if not re_isanum.match(bugnum):
370 raise Reject(
371 '{0}: "{1}" in Closes field is not a number'.format(
372 changes.filename, bugnum
373 )
374 )
376 return True
379class ExternalHashesCheck(Check):
380 """Checks hashes in .changes and .dsc against an external database."""
382 def check_single(self, session: "Session", f):
383 q = session.execute(
384 select(
385 external_files.c.size,
386 external_files.c.md5sum,
387 external_files.c.sha1sum,
388 external_files.c.sha256sum,
389 ).where(
390 external_files.c.filename.endswith(f"/{f.filename}", autoescape=True)
391 )
392 )
393 (ext_size, ext_md5sum, ext_sha1sum, ext_sha256sum) = q.fetchone() or (
394 None,
395 None,
396 None,
397 None,
398 )
400 if not ext_size:
401 return
403 if ext_size != f.size:
404 raise RejectExternalFilesMismatch(f.filename, "size", f.size, ext_size)
406 if ext_md5sum != f.md5sum:
407 raise RejectExternalFilesMismatch(
408 f.filename, "md5sum", f.md5sum, ext_md5sum
409 )
411 if ext_sha1sum != f.sha1sum:
412 raise RejectExternalFilesMismatch(
413 f.filename, "sha1sum", f.sha1sum, ext_sha1sum
414 )
416 if ext_sha256sum != f.sha256sum:
417 raise RejectExternalFilesMismatch(
418 f.filename, "sha256sum", f.sha256sum, ext_sha256sum
419 )
421 @override
422 def check(self, upload: "daklib.archive.ArchiveUpload"):
423 cnf = Config()
425 if not cnf.use_extfiles: # type: ignore[attr-defined] 425 ↛ 428line 425 didn't jump to line 428 because the condition on line 425 was always true
426 return
428 session = upload.session
429 changes = upload.changes
431 for f in changes.files.values():
432 self.check_single(session, f)
433 source = changes.source
434 if source is not None:
435 for f in source.files.values():
436 self.check_single(session, f)
439class BinaryCheck(Check):
440 """Check binary packages for syntax errors."""
442 @override
443 def check(self, upload):
444 debug_deb_name_postfix = "-dbgsym"
445 # XXX: Handle dynamic debug section name here
447 self._architectures: set[str] = set()
449 for binary in upload.changes.binaries:
450 self.check_binary(upload, binary)
452 for arch in upload.changes.architectures:
453 if arch == "source":
454 continue
455 if arch not in self._architectures: 455 ↛ 456line 455 didn't jump to line 456 because the condition on line 455 was never true
456 raise Reject(
457 "{}: Architecture field includes {}, but no binary packages for {} are included in the upload".format(
458 upload.changes.filename, arch, arch
459 )
460 )
462 binaries = {
463 binary.control["Package"]: binary for binary in upload.changes.binaries
464 }
466 for name, binary in list(binaries.items()):
467 if name in upload.changes.binary_names: 467 ↛ 470line 467 didn't jump to line 470 because the condition on line 467 was always true
468 # Package is listed in Binary field. Everything is good.
469 pass
470 elif daklib.utils.is_in_debug_section(binary.control):
471 # If we have a binary package in the debug section, we
472 # can allow it to not be present in the Binary field
473 # in the .changes file, so long as its name (without
474 # -dbgsym) is present in the Binary list.
475 if not name.endswith(debug_deb_name_postfix):
476 raise Reject(
477 "Package {0} is in the debug section, but "
478 "does not end in {1}.".format(name, debug_deb_name_postfix)
479 )
481 # Right, so, it's named properly, let's check that
482 # the corresponding package is in the Binary list
483 origin_package_name = name[: -len(debug_deb_name_postfix)]
484 if origin_package_name not in upload.changes.binary_names:
485 raise Reject(
486 "Debug package {debug}'s corresponding binary package "
487 "{origin} is not present in the Binary field.".format(
488 debug=name, origin=origin_package_name
489 )
490 )
491 else:
492 # Someone was a nasty little hacker and put a package
493 # into the .changes that isn't in debian/control. Bad,
494 # bad person.
495 raise Reject(
496 "Package {0} is not mentioned in Binary field in changes".format(
497 name
498 )
499 )
501 return True
503 def check_binary(self, upload: "daklib.archive.ArchiveUpload", binary):
504 fn = binary.hashed_file.filename
505 control = binary.control
507 for field in ("Package", "Architecture", "Version", "Description", "Section"):
508 if field not in control: 508 ↛ 509line 508 didn't jump to line 509 because the condition on line 508 was never true
509 raise Reject("{0}: Missing mandatory field {1}.".format(fn, field))
511 check_fields_for_valid_utf8(fn, control)
513 # check fields
515 package = control["Package"]
516 if not re_field_package.match(package): 516 ↛ 517line 516 didn't jump to line 517 because the condition on line 516 was never true
517 raise Reject("{0}: Invalid Package field".format(fn))
519 version = control["Version"]
520 version_match = re_field_version.match(version)
521 if not version_match: 521 ↛ 522line 521 didn't jump to line 522 because the condition on line 521 was never true
522 raise Reject("{0}: Invalid Version field".format(fn))
523 version_without_epoch = version_match.group("without_epoch")
525 architecture = control["Architecture"]
526 if architecture not in upload.changes.architectures: 526 ↛ 527line 526 didn't jump to line 527 because the condition on line 526 was never true
527 raise Reject(
528 "{0}: Architecture not in Architecture field in changes file".format(fn)
529 )
530 if architecture == "source": 530 ↛ 531line 530 didn't jump to line 531 because the condition on line 530 was never true
531 raise Reject(
532 '{0}: Architecture "source" invalid for binary packages'.format(fn)
533 )
534 self._architectures.add(architecture)
536 source = control.get("Source")
537 if source is not None and not re_field_source.match(source): 537 ↛ 538line 537 didn't jump to line 538 because the condition on line 537 was never true
538 raise Reject("{0}: Invalid Source field".format(fn))
540 section = control.get("Section", "")
541 if section == "" or section == "unknown" or section.endswith("/unknown"): 541 ↛ 542line 541 didn't jump to line 542 because the condition on line 541 was never true
542 raise Reject(
543 '{0}: The "Section" field must be present and use a real section name.'.format(
544 fn
545 )
546 )
548 # check filename
550 match = re_file_binary.match(fn)
551 if match is None: 551 ↛ 552line 551 didn't jump to line 552 because the condition on line 551 was never true
552 raise Reject(f"{fn}: does not match re_file_binary")
553 if package != match.group("package"): 553 ↛ 554line 553 didn't jump to line 554 because the condition on line 553 was never true
554 raise Reject("{0}: filename does not match Package field".format(fn))
555 if version_without_epoch != match.group("version"): 555 ↛ 556line 555 didn't jump to line 556 because the condition on line 555 was never true
556 raise Reject("{0}: filename does not match Version field".format(fn))
557 if architecture != match.group("architecture"): 557 ↛ 558line 557 didn't jump to line 558 because the condition on line 557 was never true
558 raise Reject("{0}: filename does not match Architecture field".format(fn))
560 # check dependency field syntax
562 def check_dependency_field(
563 field,
564 control,
565 dependency_parser=apt_pkg.parse_depends,
566 allow_alternatives=True,
567 allow_relations=("", "<", "<=", "=", ">=", ">"),
568 ):
569 value = control.get(field)
570 if value is not None:
571 if value.strip() == "": 571 ↛ 572line 571 didn't jump to line 572 because the condition on line 571 was never true
572 raise Reject("{0}: empty {1} field".format(fn, field))
573 try:
574 depends = dependency_parser(value)
575 except:
576 raise Reject("{0}: APT could not parse {1} field".format(fn, field))
577 for group in depends:
578 if not allow_alternatives and len(group) != 1: 578 ↛ 579line 578 didn't jump to line 579 because the condition on line 578 was never true
579 raise Reject(
580 "{0}: {1}: alternatives are not allowed".format(fn, field)
581 )
582 for dep_pkg, dep_ver, dep_rel in group:
583 if dep_rel not in allow_relations: 583 ↛ 584line 583 didn't jump to line 584 because the condition on line 583 was never true
584 raise Reject(
585 "{}: {}: depends on {}, but only relations {} are allowed for this field".format(
586 fn,
587 field,
588 " ".join([dep_pkg, dep_rel, dep_ver]),
589 allow_relations,
590 )
591 )
593 for field in (
594 "Breaks",
595 "Conflicts",
596 "Depends",
597 "Enhances",
598 "Pre-Depends",
599 "Recommends",
600 "Replaces",
601 "Suggests",
602 ):
603 check_dependency_field(field, control)
605 check_dependency_field(
606 "Provides", control, allow_alternatives=False, allow_relations=("", "=")
607 )
608 check_dependency_field(
609 "Built-Using",
610 control,
611 dependency_parser=apt_pkg.parse_src_depends,
612 allow_alternatives=False,
613 allow_relations=("=",),
614 )
617_DEB_ALLOWED_MEMBERS = {
618 "debian-binary",
619 *(f"control.tar.{comp}" for comp in ("gz", "xz")),
620 *(f"data.tar.{comp}" for comp in ("gz", "bz2", "xz")),
621}
624class BinaryMembersCheck(Check):
625 """check members of .deb file"""
627 @override
628 def check(self, upload: "daklib.archive.ArchiveUpload"):
629 for binary in upload.changes.binaries:
630 filename = binary.hashed_file.filename
631 path = os.path.join(upload.directory, filename)
632 self._check_binary(filename, path)
633 return True
635 def _check_binary(self, filename: str, path: str) -> None:
636 deb = apt_inst.DebFile(path)
637 members = {member.name for member in deb.getmembers()} # type: ignore[attr-defined]
638 if blocked_members := members - _DEB_ALLOWED_MEMBERS: 638 ↛ 639line 638 didn't jump to line 639 because the condition on line 638 was never true
639 raise Reject(
640 f"{filename}: Contains blocked members {', '.join(blocked_members)}"
641 )
644class BinaryTimestampCheck(Check):
645 """check timestamps of files in binary packages
647 Files in the near future cause ugly warnings and extreme time travel
648 can cause errors on extraction.
649 """
651 @override
652 def check(self, upload: "daklib.archive.ArchiveUpload"):
653 cnf = Config()
654 future_cutoff = time.time() + cnf.find_i(
655 "Dinstall::FutureTimeTravelGrace", 24 * 3600
656 )
657 past_cutoff = time.mktime(
658 time.strptime(cnf.find("Dinstall::PastCutoffYear", "1975"), "%Y")
659 )
661 class TarTime:
662 def __init__(self):
663 self.future_files: dict[str, int] = {}
664 self.past_files: dict[str, int] = {}
666 def callback(self, member, data) -> None:
667 if member.mtime > future_cutoff: 667 ↛ 668line 667 didn't jump to line 668 because the condition on line 667 was never true
668 self.future_files[member.name] = member.mtime
669 elif member.mtime < past_cutoff: 669 ↛ 670line 669 didn't jump to line 670 because the condition on line 669 was never true
670 self.past_files[member.name] = member.mtime
672 def format_reason(filename, direction, files) -> str:
673 reason = (
674 "{0}: has {1} file(s) with a timestamp too far in the {2}:\n".format(
675 filename, len(files), direction
676 )
677 )
678 for fn, ts in files.items():
679 reason += " {0} ({1})".format(fn, time.ctime(ts))
680 return reason
682 for binary in upload.changes.binaries:
683 filename = binary.hashed_file.filename
684 path = os.path.join(upload.directory, filename)
685 deb = apt_inst.DebFile(path)
686 tar = TarTime()
687 for archive in (deb.control, deb.data):
688 archive.go(tar.callback)
689 if tar.future_files: 689 ↛ 690line 689 didn't jump to line 690 because the condition on line 689 was never true
690 raise Reject(format_reason(filename, "future", tar.future_files))
691 if tar.past_files: 691 ↛ 692line 691 didn't jump to line 692 because the condition on line 691 was never true
692 raise Reject(format_reason(filename, "past", tar.past_files))
695class SourceCheck(Check):
696 """Check source package for syntax errors."""
698 def check_filename(self, control, filename, regex: re.Pattern) -> None:
699 # In case we have an .orig.tar.*, we have to strip the Debian revison
700 # from the version number. So handle this special case first.
701 is_orig = True
702 match = re_file_orig.match(filename)
703 if not match:
704 is_orig = False
705 match = regex.match(filename)
707 if not match: 707 ↛ 708line 707 didn't jump to line 708 because the condition on line 707 was never true
708 raise Reject(
709 "{0}: does not match regular expression for source filenames".format(
710 filename
711 )
712 )
713 if match.group("package") != control["Source"]: 713 ↛ 714line 713 didn't jump to line 714 because the condition on line 713 was never true
714 raise Reject("{0}: filename does not match Source field".format(filename))
716 version = control["Version"]
717 if is_orig:
718 upstream_match = re_field_version_upstream.match(version)
719 if not upstream_match: 719 ↛ 720line 719 didn't jump to line 720 because the condition on line 719 was never true
720 raise Reject(
721 "{0}: Source package includes upstream tarball, but {1} has no Debian revision.".format(
722 filename, version
723 )
724 )
725 version = upstream_match.group("upstream")
726 version_match = re_field_version.match(version)
727 if version_match is None: 727 ↛ 728line 727 didn't jump to line 728 because the condition on line 727 was never true
728 raise Reject(f"{filename}: Version field does not match re_field_version")
729 version_without_epoch = version_match.group("without_epoch")
730 if match.group("version") != version_without_epoch: 730 ↛ 731line 730 didn't jump to line 731 because the condition on line 730 was never true
731 raise Reject("{0}: filename does not match Version field".format(filename))
733 @override
734 def check(self, upload: "daklib.archive.ArchiveUpload"):
735 if upload.changes.source is None:
736 if upload.changes.sourceful: 736 ↛ 737line 736 didn't jump to line 737 because the condition on line 736 was never true
737 raise Reject(
738 "{}: Architecture field includes source, but no source package is included in the upload".format(
739 upload.changes.filename
740 )
741 )
742 return True
744 if not upload.changes.sourceful: 744 ↛ 745line 744 didn't jump to line 745 because the condition on line 744 was never true
745 raise Reject(
746 "{}: Architecture field does not include source, but a source package is included in the upload".format(
747 upload.changes.filename
748 )
749 )
751 changes = upload.changes.changes
752 source = upload.changes.source
753 control = cast(apt_pkg.TagSection, source.dsc)
754 dsc_fn = source._dsc_file.filename
756 check_fields_for_valid_utf8(dsc_fn, control)
758 # check fields
759 if not re_field_package.match(control["Source"]): 759 ↛ 760line 759 didn't jump to line 760 because the condition on line 759 was never true
760 raise Reject("{0}: Invalid Source field".format(dsc_fn))
761 if control["Source"] != changes["Source"]: 761 ↛ 762line 761 didn't jump to line 762 because the condition on line 761 was never true
762 raise Reject(
763 "{0}: Source field does not match Source field in changes".format(
764 dsc_fn
765 )
766 )
767 if control["Version"] != changes["Version"]: 767 ↛ 768line 767 didn't jump to line 768 because the condition on line 767 was never true
768 raise Reject(
769 "{0}: Version field does not match Version field in changes".format(
770 dsc_fn
771 )
772 )
774 # check filenames
775 self.check_filename(control, dsc_fn, re_file_dsc)
776 for f in source.files.values():
777 self.check_filename(control, f.filename, re_file_source)
779 # check dependency field syntax
780 for field in (
781 "Build-Conflicts",
782 "Build-Conflicts-Indep",
783 "Build-Depends",
784 "Build-Depends-Arch",
785 "Build-Depends-Indep",
786 ):
787 value = control.get(field)
788 if value is not None:
789 if value.strip() == "": 789 ↛ 790line 789 didn't jump to line 790 because the condition on line 789 was never true
790 raise Reject("{0}: empty {1} field".format(dsc_fn, field))
791 try:
792 apt_pkg.parse_src_depends(value)
793 except Exception as e:
794 raise Reject(
795 "{0}: APT could not parse {1} field: {2}".format(
796 dsc_fn, field, e
797 )
798 )
800 rejects = utils.check_dsc_files(dsc_fn, control, list(source.files.keys()))
801 if len(rejects) > 0: 801 ↛ 802line 801 didn't jump to line 802 because the condition on line 801 was never true
802 raise Reject("\n".join(rejects))
804 return True
807class SingleDistributionCheck(Check):
808 """Check that the .changes targets only a single distribution."""
810 @override
811 def check(self, upload):
812 if len(upload.changes.distributions) != 1: 812 ↛ 813line 812 didn't jump to line 813 because the condition on line 812 was never true
813 raise Reject("Only uploads to a single distribution are allowed.")
816class ACLCheck(Check):
817 """Check the uploader is allowed to upload the packages in .changes"""
819 def _does_hijack(
820 self, session: "Session", upload: "daklib.archive.ArchiveUpload", suite: Suite
821 ) -> tuple[Literal[True], str, str] | tuple[Literal[False], None, None]:
822 # Try to catch hijacks.
823 # This doesn't work correctly. Uploads to experimental can still
824 # "hijack" binaries from unstable. Also one can hijack packages
825 # via buildds (but people who try this should not be DMs).
826 for binary_name in upload.changes.binary_names:
827 binaries_query = (
828 select(DBBinary)
829 .join(DBBinary.source)
830 .where(DBBinary.suites.contains(suite))
831 .where(DBBinary.package == binary_name)
832 )
833 for binary in session.scalars(binaries_query):
834 if binary.source.source != upload.changes.changes["Source"]: 834 ↛ 835line 834 didn't jump to line 835 because the condition on line 834 was never true
835 return True, binary.package, binary.source.source
836 return False, None, None
838 def _check_acl(
839 self, session: "Session", upload: "daklib.archive.ArchiveUpload", acl: ACL
840 ) -> tuple[Literal[False] | None, str] | tuple[Literal[True], None]:
841 source_name = upload.changes.source_name
842 fingerprint = upload.authorized_by_fingerprint
844 if acl.match_fingerprint and fingerprint not in acl.fingerprints: 844 ↛ 845line 844 didn't jump to line 845 because the condition on line 844 was never true
845 return None, "Fingerprint not in ACL"
846 if acl.match_keyring is not None and fingerprint.keyring != acl.match_keyring: 846 ↛ 847line 846 didn't jump to line 847 because the condition on line 846 was never true
847 return None, "Fingerprint not in ACL's keyring"
849 if not acl.allow_new:
850 if upload.new:
851 return False, "NEW uploads are not allowed"
852 for f in upload.changes.files.values():
853 assert f.section is not None
854 if f.section == "byhand" or f.section.startswith("raw-"): 854 ↛ 855line 854 didn't jump to line 855 because the condition on line 854 was never true
855 return False, "BYHAND uploads are not allowed"
856 if not acl.allow_source and upload.changes.source is not None: 856 ↛ 857line 856 didn't jump to line 857 because the condition on line 856 was never true
857 return False, "sourceful uploads are not allowed"
858 binaries = upload.changes.binaries
859 if len(binaries) != 0:
860 if not acl.allow_binary: 860 ↛ 861line 860 didn't jump to line 861 because the condition on line 860 was never true
861 return False, "binary uploads are not allowed"
862 if upload.changes.source is None and not acl.allow_binary_only: 862 ↛ 863line 862 didn't jump to line 863 because the condition on line 862 was never true
863 return False, "binary-only uploads are not allowed"
864 if not acl.allow_binary_all: 864 ↛ 865line 864 didn't jump to line 865 because the condition on line 864 was never true
865 uploaded_arches = set(upload.changes.architectures)
866 uploaded_arches.discard("source")
867 allowed_arches = {a.arch_string for a in acl.architectures}
868 forbidden_arches = uploaded_arches - allowed_arches
869 if len(forbidden_arches) != 0:
870 return (
871 False,
872 "uploads for architecture(s) {0} are not allowed".format(
873 ", ".join(forbidden_arches)
874 ),
875 )
876 if not acl.allow_hijack:
877 assert upload.final_suites is not None
878 for suite in upload.final_suites:
879 does_hijack, hijacked_binary, hijacked_from = self._does_hijack(
880 session, upload, suite
881 )
882 if does_hijack: 882 ↛ 883line 882 didn't jump to line 883 because the condition on line 882 was never true
883 return (
884 False,
885 "hijacks are not allowed (binary={0}, other-source={1})".format(
886 hijacked_binary, hijacked_from
887 ),
888 )
890 acl_per_source = session.scalars(
891 select(ACLPerSource)
892 .filter_by(acl=acl, fingerprint=fingerprint, source=source_name)
893 .limit(1)
894 ).first()
895 if acl.allow_per_source and acl_per_source is None:
896 return False, "not allowed to upload source package '{0}'".format(
897 source_name
898 )
899 if acl.deny_per_source and acl_per_source is not None: 899 ↛ 900line 899 didn't jump to line 900 because the condition on line 899 was never true
900 return (
901 False,
902 acl_per_source.reason
903 or "forbidden to upload source package '{0}'".format(source_name),
904 )
906 return True, None
908 @override
909 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
910 session = upload.session
911 fingerprint = upload.authorized_by_fingerprint
912 keyring = fingerprint.keyring
914 if keyring is None: 914 ↛ 915line 914 didn't jump to line 915 because the condition on line 914 was never true
915 raise Reject(
916 "No keyring for fingerprint {0}".format(fingerprint.fingerprint)
917 )
918 if not keyring.active: 918 ↛ 919line 918 didn't jump to line 919 because the condition on line 918 was never true
919 raise Reject("Keyring {0} is not active".format(keyring.keyring_name))
921 acl = fingerprint.acl or keyring.acl
922 if acl is None: 922 ↛ 923line 922 didn't jump to line 923 because the condition on line 922 was never true
923 raise Reject("No ACL for fingerprint {0}".format(fingerprint.fingerprint))
924 result, reason = self._check_acl(session, upload, acl)
925 if not result:
926 assert reason is not None
927 raise RejectACL(acl, reason)
929 for acl in session.scalars(select(ACL).filter_by(is_global=True)):
930 result, reason = self._check_acl(session, upload, acl)
931 if result is False: 931 ↛ 932line 931 didn't jump to line 932 because the condition on line 931 was never true
932 assert reason is not None
933 raise RejectACL(acl, reason)
935 return True
937 @override
938 def per_suite_check(
939 self, upload: "daklib.archive.ArchiveUpload", suite: Suite
940 ) -> bool:
941 acls = suite.acls
942 if len(acls) != 0: 942 ↛ 943line 942 didn't jump to line 943 because the condition on line 942 was never true
943 accept = False
944 for acl in acls:
945 result, reason = self._check_acl(upload.session, upload, acl)
946 if result is False:
947 raise Reject(reason)
948 accept = accept or bool(result)
949 if not accept:
950 raise Reject(
951 "Not accepted by any per-suite acl (suite={0})".format(
952 suite.suite_name
953 )
954 )
955 return True
958class TransitionCheck(Check):
959 """check for a transition"""
961 @override
962 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
963 if not upload.changes.sourceful:
964 return True
966 transitions = self.get_transitions()
967 if transitions is None: 967 ↛ 970line 967 didn't jump to line 970 because the condition on line 967 was always true
968 return True
970 session = upload.session
972 control = upload.changes.changes
973 source_match = re_field_source.match(control["Source"])
974 if source_match is None:
975 raise Reject(
976 f"{upload.changes.filename}: Source field does not match re_field_source"
977 )
978 source = source_match.group("package")
980 for trans in transitions:
981 t = transitions[trans]
982 transition_source = t["source"]
983 expected = t["new"]
985 # Will be None if nothing is in testing.
986 current = get_source_in_suite(transition_source, "testing", session)
987 if current is not None:
988 compare = apt_pkg.version_compare(current.version, expected)
990 # This is still valid, the current version in testing is older than
991 # the new version we wait for, or there is none in testing yet.
992 # Check if the source we look at is affected by this.
993 if current is None or compare < 0 and source in t["packages"]:
994 # The source is affected, lets reject it.
996 rejectmsg = "{0}: part of the {1} transition.\n\n".format(source, trans)
998 if current is not None:
999 currentlymsg = "at version {0}".format(current.version)
1000 else:
1001 currentlymsg = "not present in testing"
1003 rejectmsg += "Transition description: {0}\n\n".format(t["reason"])
1005 rejectmsg += "\n".join(
1006 textwrap.wrap(
1007 """Your package
1008is part of a testing transition designed to get {0} migrated (it is
1009currently {1}, we need version {2}). This transition is managed by the
1010Release Team, and {3} is the Release-Team member responsible for it.
1011Please mail debian-release@lists.debian.org or contact {3} directly if you
1012need further assistance. You might want to upload to experimental until this
1013transition is done.""".format(
1014 transition_source, currentlymsg, expected, t["rm"]
1015 )
1016 )
1017 )
1019 raise Reject(rejectmsg)
1021 return True
1023 def get_transitions(self):
1024 cnf = Config()
1025 path = cnf.get("Dinstall::ReleaseTransitions", "")
1026 if path == "" or not os.path.exists(path): 1026 ↛ 1029line 1026 didn't jump to line 1029 because the condition on line 1026 was always true
1027 return None
1029 with open(path, "r") as fd:
1030 contents = fd.read()
1031 try:
1032 transitions = yaml.safe_load(contents)
1033 return transitions
1034 except yaml.YAMLError as msg:
1035 utils.warn(
1036 "Not checking transitions, the transitions file is broken: {0}".format(
1037 msg
1038 )
1039 )
1041 return None
1044class NoSourceOnlyCheck(Check):
1045 def is_source_only_upload(self, upload: "daklib.archive.ArchiveUpload") -> bool:
1046 changes = upload.changes
1047 return bool(changes.source is not None and len(changes.binaries) == 0)
1049 """Check for source-only upload
1051 Source-only uploads are only allowed if Dinstall::AllowSourceOnlyUploads is
1052 set. Otherwise they are rejected.
1054 Source-only uploads are only accepted for source packages having a
1055 Package-List field that also lists architectures per package. This
1056 check can be disabled via
1057 Dinstall::AllowSourceOnlyUploadsWithoutPackageList.
1059 Source-only uploads to NEW are only allowed if
1060 Dinstall::AllowSourceOnlyNew is set.
1062 Uploads not including architecture-independent packages are only
1063 allowed if Dinstall::AllowNoArchIndepUploads is set.
1065 """
1067 @override
1068 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
1069 if not self.is_source_only_upload(upload):
1070 return True
1071 changes = upload.changes
1072 assert changes.source is not None
1074 allow_source_only_uploads = Config().find_b("Dinstall::AllowSourceOnlyUploads")
1075 allow_source_only_uploads_without_package_list = Config().find_b(
1076 "Dinstall::AllowSourceOnlyUploadsWithoutPackageList"
1077 )
1078 allow_source_only_new = Config().find_b("Dinstall::AllowSourceOnlyNew")
1079 allow_source_only_new_keys = Config().value_list(
1080 "Dinstall::AllowSourceOnlyNewKeys"
1081 )
1082 allow_source_only_new_sources = Config().value_list(
1083 "Dinstall::AllowSourceOnlyNewSources"
1084 )
1085 allow_no_arch_indep_uploads = Config().find_b(
1086 "Dinstall::AllowNoArchIndepUploads", True
1087 )
1089 if not allow_source_only_uploads: 1089 ↛ 1090line 1089 didn't jump to line 1090 because the condition on line 1089 was never true
1090 raise Reject("Source-only uploads are not allowed.")
1091 if ( 1091 ↛ 1095line 1091 didn't jump to line 1095
1092 not allow_source_only_uploads_without_package_list
1093 and changes.source.package_list.fallback
1094 ):
1095 raise Reject(
1096 "Source-only uploads are only allowed if a Package-List field that also list architectures is included in the source package. dpkg (>= 1.17.7) includes this information."
1097 )
1098 if ( 1098 ↛ 1104line 1098 didn't jump to line 1104
1099 not allow_source_only_new
1100 and upload.new
1101 and changes.primary_fingerprint not in allow_source_only_new_keys
1102 and changes.source_name not in allow_source_only_new_sources
1103 ):
1104 raise Reject("Source-only uploads to NEW are not allowed.")
1106 if ( 1106 ↛ 1111line 1106 didn't jump to line 1111
1107 "all" not in changes.architectures
1108 and changes.source.package_list.has_arch_indep_packages()
1109 and not allow_no_arch_indep_uploads
1110 ):
1111 raise Reject("Uploads must include architecture-independent packages.")
1113 return True
1116class NewOverrideCheck(Check):
1117 """Override NEW requirement"""
1119 @override
1120 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
1121 if not upload.new:
1122 return True
1124 new_override_keys = Config().value_list("Dinstall::NewOverrideKeys")
1125 changes = upload.changes
1127 if changes.primary_fingerprint in new_override_keys: 1127 ↛ 1128line 1127 didn't jump to line 1128 because the condition on line 1127 was never true
1128 upload.new = False
1130 return True
1133class ArchAllBinNMUCheck(Check):
1134 """Check for arch:all binNMUs"""
1136 @override
1137 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
1138 changes = upload.changes
1140 if ( 1140 ↛ 1144line 1140 didn't jump to line 1144
1141 "all" in changes.architectures
1142 and changes.changes.get("Binary-Only") == "yes"
1143 ):
1144 raise Reject("arch:all binNMUs are not allowed.")
1146 return True
1149class LintianCheck(Check):
1150 """Check package using lintian"""
1152 @override
1153 def check(self, upload: "daklib.archive.ArchiveUpload") -> bool:
1154 changes = upload.changes
1156 # Only check sourceful uploads.
1157 if changes.source is None:
1158 return True
1159 # Only check uploads to unstable or experimental.
1160 if ( 1160 ↛ 1164line 1160 didn't jump to line 1164
1161 "unstable" not in changes.distributions
1162 and "experimental" not in changes.distributions
1163 ):
1164 return True
1166 cnf = Config()
1167 if "Dinstall::LintianTags" not in cnf:
1168 return True
1169 tagfile = cnf["Dinstall::LintianTags"]
1171 with open(tagfile, "r") as sourcefile:
1172 sourcecontent = sourcefile.read()
1173 try:
1174 lintiantags = yaml.safe_load(sourcecontent)["lintian"]
1175 except yaml.YAMLError as msg:
1176 raise Exception(
1177 "Could not read lintian tags file {0}, YAML error: {1}".format(
1178 tagfile, msg
1179 )
1180 )
1182 with tempfile.NamedTemporaryFile(mode="w+t") as temptagfile:
1183 os.fchmod(temptagfile.fileno(), 0o644)
1184 for tags in lintiantags.values():
1185 for tag in tags:
1186 print(tag, file=temptagfile)
1187 temptagfile.flush()
1189 changespath = os.path.join(upload.directory, changes.filename)
1191 tempdir = cnf.get("Dir::TempPath") or os.environ.get("TMPDIR", "/tmp")
1192 cmd = []
1193 user = cnf.get("Dinstall::UnprivUser") or None
1194 if user is not None: 1194 ↛ 1195line 1194 didn't jump to line 1195 because the condition on line 1194 was never true
1195 cmd.extend(["sudo", "-H", "-u", user, "TMPDIR={0}".format(tempdir)])
1196 cmd.extend(
1197 [
1198 "/usr/bin/lintian",
1199 "--show-overrides",
1200 "--tags-from-file",
1201 temptagfile.name,
1202 changespath,
1203 ]
1204 )
1205 process = subprocess.run(
1206 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8"
1207 )
1208 output = process.stdout
1209 result = process.returncode
1211 if result == 2: 1211 ↛ 1212line 1211 didn't jump to line 1212 because the condition on line 1211 was never true
1212 utils.warn(
1213 "lintian failed for %s [return code: %s]." % (changespath, result)
1214 )
1215 utils.warn(utils.prefix_multi_line_string(output, " [possible output:] "))
1217 parsed_tags = lintian.parse_lintian_output(output)
1218 rejects = list(lintian.generate_reject_messages(parsed_tags, lintiantags))
1219 if len(rejects) != 0: 1219 ↛ 1220line 1219 didn't jump to line 1220 because the condition on line 1219 was never true
1220 raise Reject("\n".join(rejects))
1222 return True
1225class SourceFormatCheck(Check):
1226 """Check source format is allowed in the target suite"""
1228 @override
1229 def per_suite_check(
1230 self, upload: "daklib.archive.ArchiveUpload", suite: Suite
1231 ) -> bool:
1232 source = upload.changes.source
1233 session = upload.session
1234 if source is None:
1235 return True
1237 source_format = source.dsc["Format"]
1238 query = (
1239 select(SrcFormat)
1240 .where(SrcFormat.format_name == source_format)
1241 .where(SrcFormat.suites.contains(suite))
1242 .limit(1)
1243 )
1244 if session.scalars(query).first() is None:
1245 raise Reject(
1246 "source format {0} is not allowed in suite {1}".format(
1247 source_format, suite.suite_name
1248 )
1249 )
1251 return True
1254class SuiteCheck(Check):
1255 @override
1256 def per_suite_check(
1257 self, upload: "daklib.archive.ArchiveUpload", suite: Suite
1258 ) -> bool:
1259 if not suite.accept_source_uploads and upload.changes.source is not None: 1259 ↛ 1260line 1259 didn't jump to line 1260 because the condition on line 1259 was never true
1260 raise Reject(
1261 'The suite "{0}" does not accept source uploads.'.format(
1262 suite.suite_name
1263 )
1264 )
1265 if not suite.accept_binary_uploads and len(upload.changes.binaries) != 0: 1265 ↛ 1266line 1265 didn't jump to line 1266 because the condition on line 1265 was never true
1266 raise Reject(
1267 'The suite "{0}" does not accept binary uploads.'.format(
1268 suite.suite_name
1269 )
1270 )
1271 return True
1274class SuiteArchitectureCheck(Check):
1275 @override
1276 def per_suite_check(
1277 self, upload: "daklib.archive.ArchiveUpload", suite: Suite
1278 ) -> bool:
1279 session = upload.session
1280 for arch in upload.changes.architectures:
1281 query = (
1282 select(Architecture)
1283 .where(Architecture.arch_string == arch)
1284 .where(Architecture.suites.contains(suite))
1285 .limit(1)
1286 )
1287 if session.scalars(query).first() is None:
1288 raise Reject(
1289 "Architecture {0} is not allowed in suite {1}".format(
1290 arch, suite.suite_name
1291 )
1292 )
1294 return True
1297class VersionCheck(Check):
1298 """Check version constraints"""
1300 def _highest_source_version(
1301 self, session: "Session", source_name: str, suite: Suite
1302 ) -> str | None:
1303 db_source = session.scalars(
1304 select(DBSource)
1305 .where(DBSource.source == source_name)
1306 .where(DBSource.suites.contains(suite))
1307 .order_by(DBSource.version.desc())
1308 .limit(1)
1309 ).first()
1310 if db_source is None:
1311 return None
1312 else:
1313 return db_source.version
1315 def _highest_binary_version(
1316 self, session: "Session", binary_name: str, suite: Suite, architecture: str
1317 ) -> str | None:
1318 db_binary = session.scalars(
1319 select(DBBinary)
1320 .where(DBBinary.package == binary_name)
1321 .where(DBBinary.suites.contains(suite))
1322 .join(DBBinary.architecture)
1323 .where(Architecture.arch_string.in_(["all", architecture]))
1324 .order_by(DBBinary.version.desc())
1325 .limit(1)
1326 ).first()
1327 if db_binary is None:
1328 return None
1329 else:
1330 return db_binary.version
1332 def _version_checks(
1333 self,
1334 upload: "daklib.archive.ArchiveUpload",
1335 suite: Suite,
1336 other_suite: Suite,
1337 op: Callable[[int], bool],
1338 op_name: str,
1339 ) -> None:
1340 session = upload.session
1342 if upload.changes.source is not None:
1343 source_name = upload.changes.source.dsc["Source"]
1344 source_version = upload.changes.source.dsc["Version"]
1345 v = self._highest_source_version(session, source_name, other_suite)
1346 if v is not None and not op(version_compare(source_version, v)): 1346 ↛ 1347line 1346 didn't jump to line 1347 because the condition on line 1346 was never true
1347 raise Reject(
1348 "Version check failed:\n"
1349 "Your upload included the source package {0}, version {1},\n"
1350 "however {3} already has version {2}.\n"
1351 "Uploads to {5} must have a {4} version than present in {3}.".format(
1352 source_name,
1353 source_version,
1354 v,
1355 other_suite.suite_name,
1356 op_name,
1357 suite.suite_name,
1358 )
1359 )
1361 for binary in upload.changes.binaries:
1362 binary_name = binary.control["Package"]
1363 binary_version = binary.control["Version"]
1364 architecture = binary.control["Architecture"]
1365 v = self._highest_binary_version(
1366 session, binary_name, other_suite, architecture
1367 )
1368 if v is not None and not op(version_compare(binary_version, v)): 1368 ↛ 1369line 1368 didn't jump to line 1369 because the condition on line 1368 was never true
1369 raise Reject(
1370 "Version check failed:\n"
1371 "Your upload included the binary package {0}, version {1}, for {2},\n"
1372 "however {4} already has version {3}.\n"
1373 "Uploads to {6} must have a {5} version than present in {4}.".format(
1374 binary_name,
1375 binary_version,
1376 architecture,
1377 v,
1378 other_suite.suite_name,
1379 op_name,
1380 suite.suite_name,
1381 )
1382 )
1384 @override
1385 def per_suite_check(
1386 self, upload: "daklib.archive.ArchiveUpload", suite: Suite
1387 ) -> bool:
1388 session = upload.session
1390 vc_newer = session.scalars(
1391 select(dbconn.VersionCheck)
1392 .filter_by(suite=suite)
1393 .where(dbconn.VersionCheck.check.in_(["MustBeNewerThan", "Enhances"]))
1394 )
1395 must_be_newer_than = [vc.reference for vc in vc_newer]
1396 # Must be newer than old versions in `suite`
1397 must_be_newer_than.append(suite)
1399 for s in must_be_newer_than:
1400 self._version_checks(upload, suite, s, lambda result: result > 0, "higher")
1402 vc_older = session.scalars(
1403 select(dbconn.VersionCheck).filter_by(suite=suite, check="MustBeOlderThan")
1404 )
1405 must_be_older_than = [vc.reference for vc in vc_older]
1407 for s in must_be_older_than: 1407 ↛ 1408line 1407 didn't jump to line 1408 because the loop on line 1407 never started
1408 self._version_checks(upload, suite, s, lambda result: result < 0, "lower")
1410 return True
1412 @property
1413 @override
1414 def forcable(self) -> bool:
1415 return True