return number of files deleted

This commit is contained in:
Lex Berezhny 2021-08-16 17:03:40 -04:00
parent 2cd5d75a2e
commit 3433c9e708

View file

@ -28,7 +28,7 @@ class DiskSpaceManager:
def clean(self): def clean(self):
if not self.config.blob_storage_limit: if not self.config.blob_storage_limit:
return False return 0
used = 0 used = 0
files = [] files = []
data_dir = os.path.join(self.config.data_dir, 'blobfiles') data_dir = os.path.join(self.config.data_dir, 'blobfiles')
@ -39,13 +39,13 @@ class DiskSpaceManager:
files.append((file_stats.st_mtime, file_stats.st_size, file.path)) files.append((file_stats.st_mtime, file_stats.st_size, file.path))
files.sort() files.sort()
available = (self.config.blob_storage_limit*1024*1024) - used available = (self.config.blob_storage_limit*1024*1024) - used
cleaned = False cleaned = 0
for _, file_size, file in files: for _, file_size, file in files:
available += file_size available += file_size
if available > 0: if available > 0:
break break
os.remove(file) os.remove(file)
cleaned = True cleaned += 1
return cleaned return cleaned
async def cleaning_loop(self): async def cleaning_loop(self):