X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fclean_suites.py;h=314c6121727a843427bde0c22cbcabe06df6e7e8;hb=245c6549dbacaeab5ee36ec74372b1df8675b477;hp=4fe2c5fdf12cf9822061f06b8e38a79cff75155a;hpb=0d52859a59eec1f7bda3cdbd9cf2894ca280fa66;p=dak.git diff --git a/dak/clean_suites.py b/dak/clean_suites.py index 4fe2c5fd..314c6121 100755 --- a/dak/clean_suites.py +++ b/dak/clean_suites.py @@ -34,6 +34,7 @@ ################################################################################ +import errno import os import stat import sys @@ -296,7 +297,7 @@ def clean(now_date, archives, max_delete, session): dest_filename = dest + '/' + os.path.basename(filename) # If the destination file exists; try to find another filename to use - if os.path.exists(dest_filename): + if os.path.lexists(dest_filename): dest_filename = utils.find_next_free(dest_filename) if not Options["No-Action"]: @@ -384,6 +385,39 @@ SELECT f.id, f.fingerprint FROM fingerprint f ################################################################################ +def clean_byhash(now_date, session): + cnf = Config() + suite_suffix = cnf.find("Dinstall::SuiteSuffix", "") + + Logger.log(["Cleaning out unused by-hash files..."]) + + q = session.execute(""" + DELETE FROM hashfile h + USING suite s, archive a + WHERE s.id = h.suite_id + AND a.id = s.archive_id + AND h.unreferenced + a.stayofexecution < CURRENT_TIMESTAMP + RETURNING a.path, s.suite_name, h.path""") + count = q.rowcount + + if not Options["No-Action"]: + for base, suite, path in q: + filename = os.path.join(base, 'dists', suite, suite_suffix, path) + try: + os.unlink(filename) + except OSError as exc: + if exc.errno != errno.ENOENT: + raise + Logger.log(['database referred to non-existing file', filename]) + else: + Logger.log(['delete hashfile', suite, path]) + session.commit() + + if count > 0: + Logger.log(["total", count]) + +################################################################################ + def clean_empty_directories(session): """ Removes empty directories from pool directories. @@ -486,6 +520,7 @@ def main(): clean(now_date, archives, max_delete, session) clean_maintainers(now_date, session) clean_fingerprints(now_date, session) + clean_byhash(now_date, session) clean_empty_directories(session) session.rollback()