only run cleanup if folders exist

This commit is contained in:
j 2025-12-23 22:14:22 +01:00
commit bc4e715ce4

View file

@ -150,12 +150,15 @@ def extract_clip(public_id, in_, out, resolution, format, track=None):
def clear_cache(days=60): def clear_cache(days=60):
import subprocess import subprocess
path = os.path.join(settings.MEDIA_ROOT, 'media') path = os.path.join(settings.MEDIA_ROOT, 'media')
if os.path.exists(path):
cmd = ['find', path, '-iregex', '.*/frames/.*', '-atime', '+%s' % days, '-type', 'f', '-exec', 'rm', '{}', ';'] cmd = ['find', path, '-iregex', '.*/frames/.*', '-atime', '+%s' % days, '-type', 'f', '-exec', 'rm', '{}', ';']
subprocess.check_output(cmd) subprocess.check_output(cmd)
if os.path.exists(path):
path = os.path.join(settings.MEDIA_ROOT, 'items') path = os.path.join(settings.MEDIA_ROOT, 'items')
cmd = ['find', path, '-iregex', '.*/cache/.*', '-atime', '+%s' % days, '-type', 'f', '-exec', 'rm', '{}', ';'] cmd = ['find', path, '-iregex', '.*/cache/.*', '-atime', '+%s' % days, '-type', 'f', '-exec', 'rm', '{}', ';']
subprocess.check_output(cmd) subprocess.check_output(cmd)
path = settings.MEDIA_ROOT path = settings.MEDIA_ROOT
if os.path.exists(path):
cmd = ['find', path, '-type', 'd', '-size', '0', '-prune', '-exec', 'rmdir', '{}', ';'] cmd = ['find', path, '-type', 'd', '-size', '0', '-prune', '-exec', 'rmdir', '{}', ';']
subprocess.check_output(cmd) subprocess.check_output(cmd)