Skip to content

Commit

Permalink
fix scan repo auto delete (#5789)
Browse files Browse the repository at this point in the history
  • Loading branch information
imwhatiam authored Nov 24, 2023
1 parent f0b2534 commit 0909025
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions seahub/base/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from seahub.share.models import ExtraSharePermission
from seahub.utils.auth import gen_user_virtual_id
from seahub.auth.models import SocialAuthUser
from seahub.repo_auto_delete.models import RepoAutoDelete

try:
from seahub.settings import CLOUD_MODE
Expand Down Expand Up @@ -86,8 +87,11 @@

UNUSABLE_PASSWORD = '!' # This will never be a valid hash


def default_ldap_role_mapping(role):
return role


ldap_role_mapping = default_ldap_role_mapping
if ENABLE_LDAP:
try:
Expand Down Expand Up @@ -594,6 +598,8 @@ def delete(self):
for r in owned_repos:
seafile_api.remove_repo(r.id)

RepoAutoDelete.objects.filter(repo_id__in=[r.id for r in owned_repos]).delete()

# remove shared in repos
shared_in_repos = []
if orgs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ def iterate_and_del_files_recursively(repo_id, path, days):
if cur_time - time_delta > mtime:
del_dirents.append(dirent.obj_name)
if del_dirents:
try:
seafile_api.del_file(repo_id, path, json.dumps(del_dirents), 'seafevents')
except Exception as e:
logger.error('Failed to delete files in repo: %s, path: %s, error: %s' % (repo_id, path, e))
seafile_api.del_file(repo_id, path, json.dumps(del_dirents), 'seafevents')


class Command(BaseCommand):
Expand All @@ -57,4 +54,8 @@ def handle(self, *args, **options):
def do_action(self, *args, **options):
repo_auto_deletes = RepoAutoDelete.objects.filter(days__gt=0)
for auto_del in repo_auto_deletes:
iterate_and_del_files_recursively(auto_del.repo_id, '/', auto_del.days)
try:
iterate_and_del_files_recursively(auto_del.repo_id, '/', auto_del.days)
except Exception as e:
logger.error(f'Failed to delete files in repo {auto_del.repo_id}, error: {e}')
continue

0 comments on commit 0909025

Please sign in to comment.