X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fchanges.py;h=48da0e580ae5c62ef4fa36b592a05601bd928f7d;hb=b4787f88ef10799017b6fbebd94119b127b5d683;hp=4fdf0a60995e4f124d659ea64059a4b234736c80;hpb=c0118300a7f7f9d17ce378caf05ee50ba85724d4;p=dak.git diff --git a/daklib/changes.py b/daklib/changes.py index 4fdf0a60..48da0e58 100644 --- a/daklib/changes.py +++ b/daklib/changes.py @@ -187,6 +187,36 @@ class Changes(object): if (not self.changes.has_key(key)) or (not self.changes[key]): self.changes[key]='missing' + def __get_file_from_pool(self, filename, entry, session): + cnf = Config() + + if cnf.has_key("Dinstall::SuiteSuffix"): + component = cnf["Dinstall::SuiteSuffix"] + entry["component"] + else: + component = entry["component"] + + poolname = poolify(entry["source"], component) + l = get_location(cnf["Dir::Pool"], component, session=session) + + found, poolfile = check_poolfile(os.path.join(poolname, filename), + entry['size'], + entry["md5sum"], + l.location_id, + session=session) + + if found is None: + Logger.log(["E: Found multiple files for pool (%s) for %s" % (filename, component)]) + return None + elif found is False and poolfile is not None: + Logger.log(["E: md5sum/size mismatch for %s in pool" % (filename)]) + return None + else: + if poolfile is None: + Logger.log(["E: Could not find %s in pool" % (filename)]) + return None + else: + return poolfile + @session_wrapper def add_known_changes(self, dirpath, in_queue=None, session=None): """add "missing" in fields which we will require for the known_changes table""" @@ -205,7 +235,7 @@ class Changes(object): multivalues[key] = self.changes[key] chg = DBChange() - chg.changesfile = self.changes_file + chg.changesname = self.changes_file chg.seen = filetime chg.in_queue_id = in_queue chg.source = self.changes["source"] @@ -218,24 +248,55 @@ class Changes(object): chg.fingerprint = self.changes["fingerprint"] chg.changedby = self.changes["changed-by"] chg.date = self.changes["date"] - - session.add(chg) - chg_files = [] - for chg_fn in self.files.keys(): - cpf = ChangePendingFile() - cpf.filename = chg_fn - cpf.size = self.files[chg_fn]['size'] - cpf.md5sum = self.files[chg_fn]['md5sum'] + session.add(chg) - session.add(cpf) - chg_files.append(cpf) + files = [] + for chg_fn, entry in self.files.items(): + try: + f = open(os.path.join(dirpath, chg_fn)) + cpf = ChangePendingFile() + cpf.filename = chg_fn + cpf.size = entry['size'] + cpf.md5sum = entry['md5sum'] + + if entry.has_key('sha1sum'): + cpf.sha1sum = entry['sha1sum'] + else: + f.seek(0) + cpf.sha1sum = apt_pkg.sha1sum(f) + + if entry.has_key('sha256sum'): + cpf.sha256sum = entry['sha256sum'] + else: + f.seek(0) + cpf.sha256sum = apt_pkg.sha256sum(f) + + session.add(cpf) + files.append(cpf) + f.close() + + except IOError: + # Can't find the file, try to look it up in the pool + poolfile = self.__get_file_from_pool(chg_fn, entry, session) + if poolfile: + chg.poolfiles.append(poolfile) + + chg.files = files + + # Add files referenced in .dsc, but not included in .changes + for name, entry in self.dsc_files.items(): + if self.files.has_key(name): + continue - chg.files = chg_files + entry['source'] = self.changes['source'] + poolfile = self.__get_file_from_pool(name, entry, session) + if poolfile: + chg.poolfiles.append(poolfile) session.commit() chg = session.query(DBChange).filter_by(changesname = self.changes_file).one(); - + return chg def unknown_files_fields(self, name):