diff --git a/src/documents/models.py b/src/documents/models.py index 39dcc4a37..17357c1a7 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -415,7 +415,10 @@ class Document(models.Model): def try_delete_empty_directories(directory): # 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: os.rmdir(directory) @@ -425,6 +428,7 @@ def try_delete_empty_directories(directory): # Cut off actual directory and go one level up directory, _ = os.path.split(directory) + directory = os.path.normpath(directory) @receiver(models.signals.m2m_changed, sender=Document.tags.through) diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.py index f6c8d0eba..fae1c0634 100644 --- a/src/documents/tests/test_file_handling.py +++ b/src/documents/tests/test_file_handling.py @@ -319,7 +319,7 @@ class TestDate(TestCase): self.assertEqual(os.path.isdir(settings.MEDIA_ROOT + "/documents/originals/none"), False) self.assertEqual(os.path.isdir(settings.MEDIA_ROOT + - "/documents/originals"), False) + "/documents/originals"), True) @override_settings(MEDIA_ROOT="/tmp/paperless-tests-{}". format(str(uuid4())[:8]))