[tor-commits] [sbws/master] Add function to delete files passed as arg

pastly at torproject.org pastly at torproject.org
Thu Aug 9 14:21:19 UTC 2018


commit 25f3fa9ccf3ad5d83cfd36ebf4f0e31b0cd191f6
Author: juga0 <juga at riseup.net>
Date:   Tue Jul 17 17:08:50 2018 +0000

    Add function to delete files passed as arg
---
 sbws/core/cleanup.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sbws/core/cleanup.py b/sbws/core/cleanup.py
index bd3300c..3deca57 100644
--- a/sbws/core/cleanup.py
+++ b/sbws/core/cleanup.py
@@ -1,3 +1,6 @@
+"""Util functions to cleanup disk space."""
+import types
+
 from sbws.util.filelock import DirectoryLock
 from sbws.globals import (fail_hard, is_initted)
 from sbws.util.timestamp import unixts_to_dt_obj
@@ -93,6 +96,17 @@ def _get_older_files_than(dname, num_days_ago, extensions):
                 yield fname
 
 
+def _delete_files(dname, files, dry_run=True):
+    """Delete the files passed as argument."""
+    assert os.path.isdir(dname)
+    assert isinstance(files, types.GeneratorType)
+    with DirectoryLock(dname):
+        for fname in files:
+            log.info('Deleting %s', fname)
+            if not dry_run:
+                os.remove(fname)
+
+
 def _remove_rotten_files(datadir, rotten_days, dry_run=True):
     assert os.path.isdir(datadir)
     assert isinstance(rotten_days, int)





More information about the tor-commits mailing list