+ all_marked_dsc_files[i[0]] = i[1];
+ projectB.query("BEGIN WORK");
+ for id in all_marked_dsc_files.keys():
+ if linked_sources.has_key(id):
+ # Can't imagine why this would happen, so warn about it for now.
+ print "W: %s has released %s from the target list." % (id, all_marked_sources[id]);
+ projectB.query("UPDATE files SET last_used = NULL WHERE id = %s" % (all_marked_sources[id]));
+ # Unmark all other files references by .dsc too
+ q = projectB.query("SELECT file FROM dsc_files WHERE source = %d" % (id));
+ ql = q.getresult();
+ for i in ql:
+ projectB.query("UPDATE files SET last_used = NULL WHERE id = %s" % (i[0]));
+ projectB.query("COMMIT WORK");
+
+def check_files():
+ global delete_date;
+
+ print "Checking for unused files..."
+
+ # Check for files not references in either binaries or dsc_files
+ used = {};
+ q = projectB.query("SELECT file FROM binaries");
+ for i in q.getresult():
+ used[i[0]] = "";
+ q = projectB.query("SELECT file FROM dsc_files");
+ for i in q.getresult():
+ used[i[0]] = "";
+
+ all = {};
+ q = projectB.query("SELECT f.id, l.path, f.filename FROM files f, location l WHERE f.location = l.id;");
+ for i in q.getresult():
+ all[i[0]] = i[1] + i[2];
+
+ projectB.query("BEGIN WORK");
+ for id in all.keys():
+ if not used.has_key(id):
+ projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s" % (delete_date, id));
+ projectB.query("COMMIT WORK");
+
+def clean_binaries():
+ global delete_date;
+
+ # We do this here so that the binaries we remove will have their
+ # source also removed (if possible).
+
+ print "Cleaning binaries from the DB..."
+ if not Cnf["Rhona::Options::No-Action"]:
+ before = time.time();
+ sys.stdout.write("[Deleting from binaries table... ");
+ projectB.query("DELETE FROM binaries WHERE EXISTS (SELECT id FROM files WHERE binaries.file = files.id AND files.last_used <= '%s')" % (delete_date));
+ sys.stdout.write("done. (%d)]\n" % (int(time.time()-before)));
+
+def clean():
+ global delete_date;
+ count = 0;
+ size = 0;
+
+ print "Cleaning out packages..."
+
+ # Ensure destination directory exists
+ dest = Cnf["Dir::Morgue"] + '/' + Cnf["Rhona::MorgueSubDir"];
+ if not os.path.exists(dest):
+ os.mkdir(dest);
+
+ # Delete from source (dsc_file should already be done!)
+ if not Cnf["Rhona::Options::No-Action"]:
+ before = time.time();
+ sys.stdout.write("[Deleting from source table... ");
+ projectB.query("DELETE FROM source WHERE EXISTS (SELECT id FROM files WHERE source.file = files.id AND files.last_used <= '%s')" % (delete_date));
+ sys.stdout.write("done. (%d)]\n" % (int(time.time()-before)));
+
+ # Delete files from the pool
+ q = projectB.query("SELECT l.path, f.filename FROM location l, files f WHERE f.last_used <= '%s' AND l.id = f.location" % (delete_date));
+ for i in q.getresult():