Skip to content

Commit

Permalink
fix clean opencast folder method (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbild authored Apr 12, 2024
1 parent a43930c commit 5e4a16d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pod/recorder/plugins/type_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from django.conf import settings

from ..utils import add_comment, studio_clean_old_files
from ..utils import add_comment, studio_clean_old_entries
from pod.video.models import Video, get_storage_path_video
from pod.video_encode_transcript import encode
from django.template.defaultfilters import slugify
Expand Down Expand Up @@ -93,7 +93,7 @@ def save_basic_video(recording, video_src):
# Rename the XML file
# os.rename(recording.source_file, recording.source_file + "_treated")

studio_clean_old_files()
studio_clean_old_entries()

return video

Expand Down
24 changes: 13 additions & 11 deletions pod/recorder/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Esup-Pod recorder utilities."""

import shutil
import time
import os
import uuid
Expand All @@ -20,21 +20,23 @@ def add_comment(recording_id, comment):
recording.save()


def studio_clean_old_files():
def studio_clean_old_entries():
"""
Clean up old files in the "opencast-files" folder.
Clean up old entries in the opencast folder.
The function removes files that are older than 7 days
from the "opencast-files" folder in the media root.
The function removes entries that are older than 7 days
from the opencast folder in the media root.
"""
folder_to_clean = os.path.join(settings.MEDIA_ROOT, "opencast-files")
folder_to_clean = os.path.join(settings.MEDIA_ROOT, OPENCAST_FILES_DIR)
now = time.time()

for f in os.listdir(folder_to_clean):
f = os.path.join(folder_to_clean, f)
if os.stat(f).st_mtime < now - 7 * 86400:
if os.path.isfile(f):
os.remove(f)
for entry in os.listdir(folder_to_clean):
entry_path = os.path.join(folder_to_clean, entry)
if os.stat(entry_path).st_mtime < now - 7 * 86400:
if os.path.isdir(entry_path):
shutil.rmtree(entry_path)
else:
os.remove(entry_path)


def handle_upload_file(request, element_name, mimetype, tag_name):
Expand Down

0 comments on commit 5e4a16d

Please sign in to comment.