-# 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):
+ rejmsg = []
+
+ # Make sure we recognise the format of the Files: field in the .changes
+ 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
+
+ # We need to deal with the original changes blob, as the fields we need
+ # might not be in the changes dict serialised into the .dak anymore.
+ orig_changes = parse_deb822(changes['filecontents'])
+
+ # Copy the checksums over to the current changes dict. This will keep
+ # the existing modifications to it intact.
+ for field in orig_changes:
+ if field.startswith('checksums-'):
+ changes[field] = orig_changes[field]
+
+ # Check for unsupported hashes
+ rejmsg.extend(check_hash_fields(".changes", changes))
+ rejmsg.extend(check_hash_fields(".dsc", dsc))
+
+ # 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
+ for hashname, hashfunc, version in known_hashes:
+ rejmsg.extend(_ensure_changes_hash(changes, format, version, files,
+ hashname, hashfunc))
+ if "source" in changes["architecture"]:
+ rejmsg.extend(_ensure_dsc_hash(dsc, dsc_files, hashname,
+ hashfunc))
+
+ return rejmsg
+
+def parse_checksums(where, files, manifest, hashname):
+ rejmsg = []
+ field = 'checksums-%s' % hashname
+ if not field in manifest:
+ return rejmsg
+ for line in manifest[field].split('\n'):
+ if not line:
+ break
+ checksum, size, checkfile = line.strip().split(' ')
+ if not files.has_key(checkfile):
+ # TODO: check for the file's entry in the original files dict, not
+ # the one modified by (auto)byhand and other weird stuff
+ # rejmsg.append("%s: not present in files but in checksums-%s in %s" %
+ # (file, hashname, where))
+ continue
+ if not files[checkfile]["size"] == size:
+ rejmsg.append("%s: size differs for files and checksums-%s entry "\
+ "in %s" % (checkfile, hashname, where))
+ continue
+ files[checkfile][hash_key(hashname)] = checksum
+ for f in files.keys():
+ if not files[f].has_key(hash_key(hashname)):
+ rejmsg.append("%s: no entry in checksums-%s in %s" % (checkfile,
+ hashname, where))
+ return rejmsg