From: Michael Tremer Date: Mon, 23 Oct 2017 00:28:20 +0000 (+0100) Subject: Allow deleting files after a certain time from the filesystem X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5c9daa86409fe50088616a268cdebf4444a82420;p=people%2Fjschlag%2Fpbs.git Allow deleting files after a certain time from the filesystem Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index 36c7c0d..f703500 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -128,8 +128,13 @@ class Backend(object): return database.Connection(hostname, name, user=user, password=password) + def delete_file(self, path, not_before=None): + self.db.execute("INSERT INTO queue_delete(path, not_before) \ + VALUES(%s, %s)", path, not_before) + def cleanup_files(self): - query = self.db.query("SELECT * FROM queue_delete") + query = self.db.query("SELECT * FROM queue_delete \ + WHERE (not_before IS NULL OR not_before >= NOW())") for row in query: if not row.path: diff --git a/src/database.sql b/src/database.sql index 7e683dd..aef4344 100644 --- a/src/database.sql +++ b/src/database.sql @@ -1500,7 +1500,8 @@ ALTER SEQUENCE packages_properties_id_seq OWNED BY packages_properties.id; CREATE TABLE queue_delete ( id integer NOT NULL, - path text NOT NULL + path text NOT NULL, + not_before timestamp without time zone );