Ensure, that document root is not deleted

This commit is contained in:
Wolf-Bastian Poettner 2020-03-28 20:57:57 +00:00
parent 7f1e1052fe
commit 845313db52
2 changed files with 6 additions and 2 deletions

View File

@ -415,7 +415,10 @@ class Document(models.Model):
def try_delete_empty_directories(directory): def try_delete_empty_directories(directory):
# Go up in the directory hierarchy and try to delete all directories # Go up in the directory hierarchy and try to delete all directories
while directory != Document.filename_to_path(""): directory = os.path.normpath(directory)
root = os.path.normpath(Document.filename_to_path(""))
while directory != root:
# Try to delete the current directory # Try to delete the current directory
try: try:
os.rmdir(directory) os.rmdir(directory)
@ -425,6 +428,7 @@ def try_delete_empty_directories(directory):
# Cut off actual directory and go one level up # Cut off actual directory and go one level up
directory, _ = os.path.split(directory) directory, _ = os.path.split(directory)
directory = os.path.normpath(directory)
@receiver(models.signals.m2m_changed, sender=Document.tags.through) @receiver(models.signals.m2m_changed, sender=Document.tags.through)

View File

@ -319,7 +319,7 @@ class TestDate(TestCase):
self.assertEqual(os.path.isdir(settings.MEDIA_ROOT + self.assertEqual(os.path.isdir(settings.MEDIA_ROOT +
"/documents/originals/none"), False) "/documents/originals/none"), False)
self.assertEqual(os.path.isdir(settings.MEDIA_ROOT + self.assertEqual(os.path.isdir(settings.MEDIA_ROOT +
"/documents/originals"), False) "/documents/originals"), True)
@override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}". @override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}".
format(str(uuid4())[:8])) format(str(uuid4())[:8]))