From 282c4b8f267464261f70b9e6975959ea241be7de Mon Sep 17 00:00:00 2001 From: imperosol Date: Sun, 9 Nov 2025 17:00:44 +0100 Subject: [PATCH] remove `SithFile._check_fs` and `SithFile.repair_fs` --- core/management/commands/check_fs.py | 40 ---------------- core/management/commands/repair_fs.py | 41 ---------------- core/models.py | 67 --------------------------- 3 files changed, 148 deletions(-) delete mode 100644 core/management/commands/check_fs.py delete mode 100644 core/management/commands/repair_fs.py diff --git a/core/management/commands/check_fs.py b/core/management/commands/check_fs.py deleted file mode 100644 index 8e970ced..00000000 --- a/core/management/commands/check_fs.py +++ /dev/null @@ -1,40 +0,0 @@ -# -# Copyright 2018 -# - Skia -# -# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM, -# http://ae.utbm.fr. -# -# This program is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License a published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple -# Place - Suite 330, Boston, MA 02111-1307, USA. -# -# - -from django.core.management.base import BaseCommand - -from core.models import SithFile - - -class Command(BaseCommand): - help = "Recursively check the file system with respect to the DB" - - def add_arguments(self, parser): - parser.add_argument( - "ids", metavar="ID", type=int, nargs="+", help="The file IDs to process" - ) - - def handle(self, *args, **options): - files = SithFile.objects.filter(id__in=options["ids"]).all() - for f in files: - f._check_fs() diff --git a/core/management/commands/repair_fs.py b/core/management/commands/repair_fs.py deleted file mode 100644 index cf88d108..00000000 --- a/core/management/commands/repair_fs.py +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright 2018 -# - Skia -# -# Ce fichier fait partie du site de l'Association des Étudiants de l'UTBM, -# http://ae.utbm.fr. -# -# This program is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License a published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# this program; if not, write to the Free Sofware Foundation, Inc., 59 Temple -# Place - Suite 330, Boston, MA 02111-1307, USA. -# -# - - -from django.core.management.base import BaseCommand - -from core.models import SithFile - - -class Command(BaseCommand): - help = "Recursively repair the file system with respect to the DB" - - def add_arguments(self, parser): - parser.add_argument( - "ids", metavar="ID", type=int, nargs="+", help="The file IDs to process" - ) - - def handle(self, *args, **options): - files = SithFile.objects.filter(id__in=options["ids"]).all() - for f in files: - f._repair_fs() diff --git a/core/models.py b/core/models.py index bf54a33a..d635b5af 100644 --- a/core/models.py +++ b/core/models.py @@ -23,8 +23,6 @@ # from __future__ import annotations -import logging -import os import string import unicodedata from datetime import timedelta @@ -454,14 +452,6 @@ class User(AbstractUser): else: raise ValidationError(_("A user with that username already exists")) - def get_profile(self): - return { - "last_name": self.last_name, - "first_name": self.first_name, - "nick_name": self.nick_name, - "date_of_birth": self.date_of_birth, - } - def get_short_name(self): """Returns the short name for the user.""" if self.nick_name: @@ -1016,63 +1006,6 @@ class SithFile(models.Model): self.clean() self.save() - def _repair_fs(self): - """Rebuilds recursively the filesystem as it should be regarding the DB tree.""" - if self.is_folder: - for c in self.children.all(): - c._repair_fs() - return - elif not self._check_path_consistence(): - # First get future parent path and the old file name - # Prepend "." so that we match all relative handling of Django's - # file storage - parent_path = "." + self.parent.get_full_path() - parent_full_path = settings.MEDIA_ROOT + parent_path - os.makedirs(parent_full_path, exist_ok=True) - old_path = self.file.name # Should be relative: "./users/skia/bleh.jpg" - new_path = "." + self.get_full_path() - try: - # Make this atomic, so that a FS problem rolls back the DB change - with transaction.atomic(): - # Set the new filesystem path - self.file.name = new_path - self.save() - # Really move at the FS level - if os.path.exists(parent_full_path): - os.rename( - settings.MEDIA_ROOT + old_path, - settings.MEDIA_ROOT + new_path, - ) - # Empty directories may remain, but that's not really a - # problem, and that can be solved with a simple shell - # command: `find . -type d -empty -delete` - except Exception as e: - logging.error(e) - - def _check_path_consistence(self): - file_path = str(self.file) - file_full_path = settings.MEDIA_ROOT + file_path - db_path = ".%s" % self.get_full_path() - if not os.path.exists(file_full_path): - print("%s: WARNING: real file does not exists!" % self.id) # noqa T201 - print("file path: %s" % file_path, end="") # noqa T201 - print(" db path: %s" % db_path) # noqa T201 - return False - if file_path != db_path: - print("%s: " % self.id, end="") # noqa T201 - print("file path: %s" % file_path, end="") # noqa T201 - print(" db path: %s" % db_path) # noqa T201 - return False - return True - - def _check_fs(self): - if self.is_folder: - for c in self.children.all(): - c._check_fs() - return - else: - self._check_path_consistence() - @property def is_file(self): return not self.is_folder