forked from LBRYCommunity/lbry-sdk
return true/false if clean was performed
This commit is contained in:
parent
2535b8adef
commit
2cd5d75a2e
2 changed files with 6 additions and 2 deletions
|
@ -28,7 +28,7 @@ class DiskSpaceManager:
|
|||
|
||||
def clean(self):
|
||||
if not self.config.blob_storage_limit:
|
||||
return
|
||||
return False
|
||||
used = 0
|
||||
files = []
|
||||
data_dir = os.path.join(self.config.data_dir, 'blobfiles')
|
||||
|
@ -39,11 +39,14 @@ class DiskSpaceManager:
|
|||
files.append((file_stats.st_mtime, file_stats.st_size, file.path))
|
||||
files.sort()
|
||||
available = (self.config.blob_storage_limit*1024*1024) - used
|
||||
cleaned = False
|
||||
for _, file_size, file in files:
|
||||
available += file_size
|
||||
if available > 0:
|
||||
break
|
||||
os.remove(file)
|
||||
cleaned = True
|
||||
return cleaned
|
||||
|
||||
async def cleaning_loop(self):
|
||||
while self.running:
|
||||
|
|
|
@ -24,6 +24,7 @@ class ConfigurationTests(unittest.TestCase):
|
|||
with open(os.path.join(config.data_dir, 'blobfiles', f'3mb-{file_no}'), 'w') as blob:
|
||||
blob.write('0' * 1 * 1024 * 1024)
|
||||
self.assertEqual(10, dsm.space_used_mb)
|
||||
dsm.clean()
|
||||
self.assertTrue(dsm.clean())
|
||||
self.assertEqual(5, dsm.space_used_mb)
|
||||
self.assertFalse(dsm.clean())
|
||||
|
||||
|
|
Loading…
Reference in a new issue