-# check if section/priority values are valid
-
-def check_valid (new):
- for pkg in new.keys():
- section = new[pkg]["section"]
- priority = new[pkg]["priority"]
- type = new[pkg]["type"]
- new[pkg]["section id"] = database.get_section_id(section)
- new[pkg]["priority id"] = database.get_priority_id(new[pkg]["priority"])
- # Sanity checks
- di = section.find("debian-installer") != -1
- if (di and type != "udeb") or (not di and type == "udeb"):
- new[pkg]["section id"] = -1
- if (priority == "source" and type != "dsc") or \
- (priority != "source" and type == "dsc"):
- new[pkg]["priority id"] = -1
+def ensure_hashes(changes, dsc, files, dsc_files):
+ # Make sure we recognise the format of the Files: field
+ format = changes.get("format", "0.0").split(".",1)
+ if len(format) == 2:
+ format = int(format[0]), int(format[1])
+ else:
+ format = int(float(format[0])), 0
+
+ rejmsg = []
+ for x in changes:
+ if x.startswith("checksum-"):
+ h = x.split("-",1)[1]
+ if h not in dict(known_hashes):
+ rejmsg.append("Unsupported checksum field in .changes" % (h))
+
+ for x in dsc:
+ if x.startswith("checksum-"):
+ h = x.split("-",1)[1]
+ if h not in dict(known_hashes):
+ rejmsg.append("Unsupported checksum field in .dsc" % (h))
+
+ # We have to calculate the hash if we have an earlier changes version than
+ # the hash appears in rather than require it exist in the changes file
+ # I hate backwards compatibility
+ for h,f,v in known_hashes:
+ try:
+ if format < v:
+ for m in create_hash(files, h, f, files):
+ rejmsg.append(m)
+ else:
+ for m in check_hash(".changes %s" % (h), files, h, f, files):
+ rejmsg.append(m)
+ except NoFilesFieldError:
+ rejmsg.append("No Checksums-%s: field in .changes" % (h))
+ except UnknownFormatError, format:
+ rejmsg.append("%s: unknown format of .changes" % (format))
+ except ParseChangesError, line:
+ rejmsg.append("parse error for Checksums-%s in .changes, can't grok: %s." % (h, line))
+
+ if "source" not in changes["architecture"]: continue
+
+ try:
+ if format < v:
+ for m in create_hash(dsc_files, h, f, dsc_files):
+ rejmsg.append(m)
+ else:
+ for m in check_hash(".dsc %s" % (h), dsc_files, h, f, dsc_files):
+ rejmsg.append(m)
+ except UnknownFormatError, format:
+ rejmsg.append("%s: unknown format of .dsc" % (format))
+ except NoFilesFieldError:
+ rejmsg.append("No Checksums-%s: field in .dsc" % (h))
+ except ParseChangesError, line:
+ rejmsg.append("parse error for Checksums-%s in .dsc, can't grok: %s." % (h, line))
+
+ return rejmsg