handle edge cases in migration clean up

This commit is contained in:
Simon 2023-07-28 17:56:28 +07:00
parent 6f915a5733
commit ab8fed14bb
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -2,6 +2,7 @@
import json import json
import os import os
import shutil
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from home.src.es.connect import ElasticWrap, IndexPaginate from home.src.es.connect import ElasticWrap, IndexPaginate
@ -167,5 +168,8 @@ class FolderMigration:
all_folders = ignore_filelist(os.listdir(self.videos)) all_folders = ignore_filelist(os.listdir(self.videos))
for folder in all_folders: for folder in all_folders:
folder_path = os.path.join(self.videos, folder) folder_path = os.path.join(self.videos, folder)
if not os.path.isdir(folder_path):
continue
if not ignore_filelist(os.listdir(folder_path)): if not ignore_filelist(os.listdir(folder_path)):
os.rmdir(folder_path) shutil.rmtree(folder_path)