]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
ignore macOS specific files
authorjonaswinkler <17569239+jonaswinkler@users.noreply.github.com>
Wed, 19 May 2021 17:56:01 +0000 (19:56 +0200)
committerjonaswinkler <17569239+jonaswinkler@users.noreply.github.com>
Wed, 19 May 2021 17:56:01 +0000 (19:56 +0200)
src/documents/management/commands/document_consumer.py
src/documents/tests/test_management_consumer.py

index 969941af9c8cfe261d04cfe4443dc1d4c9123250..9f0ce79c340d3b8be912d24ee59d7967e696af0a 100644 (file)
@@ -36,8 +36,19 @@ def _tags_from_path(filepath):
     return tag_ids
 
 
+def _is_ignored(filepath):
+    # https://github.com/jonaswinkler/paperless-ng/discussions/1037
+    basename = os.path.basename(filepath)
+    if basename == ".DS_STORE":
+        return True
+    if basename.startswith("._"):
+        return True
+
+    return False
+
+
 def _consume(filepath):
-    if os.path.isdir(filepath):
+    if os.path.isdir(filepath) or _is_ignored(filepath):
         return
 
     if not os.path.isfile(filepath):
@@ -71,6 +82,9 @@ def _consume(filepath):
 
 
 def _consume_wait_unmodified(file):
+    if _is_ignored(file):
+        return
+
     logger.debug(f"Waiting for file {file} to remain unmodified")
     mtime = -1
     current_try = 0
index 2111705e0d996943ef9e7758b23758dec98b3b6b..ec5a8dc0b63e5d379605da2d677cb5476d0276c3 100644 (file)
@@ -60,10 +60,10 @@ class ConsumerMixin:
 
         super(ConsumerMixin, self).tearDown()
 
-    def wait_for_task_mock_call(self):
+    def wait_for_task_mock_call(self, excpeted_call_count=1):
         n = 0
         while n < 100:
-            if self.task_mock.call_count > 0:
+            if self.task_mock.call_count >= excpeted_call_count:
                 # give task_mock some time to finish and raise errors
                 sleep(1)
                 return
@@ -202,6 +202,26 @@ class TestConsumer(DirectoriesMixin, ConsumerMixin, TransactionTestCase):
 
         self.assertRaises(CommandError, call_command, 'document_consumer', '--oneshot')
 
+    def test_mac_write(self):
+        self.task_mock.side_effect = self.bogus_task
+
+        self.t_start()
+
+        shutil.copy(self.sample_file, os.path.join(self.dirs.consumption_dir, ".DS_STORE"))
+        shutil.copy(self.sample_file, os.path.join(self.dirs.consumption_dir, "my_file.pdf"))
+        shutil.copy(self.sample_file, os.path.join(self.dirs.consumption_dir, "._my_file.pdf"))
+        shutil.copy(self.sample_file, os.path.join(self.dirs.consumption_dir, "my_second_file.pdf"))
+        shutil.copy(self.sample_file, os.path.join(self.dirs.consumption_dir, "._my_second_file.pdf"))
+
+        sleep(5)
+
+        self.wait_for_task_mock_call(excpeted_call_count=2)
+
+        self.assertEqual(2, self.task_mock.call_count)
+
+        fnames = [os.path.basename(args[1]) for args, _ in self.task_mock.call_args_list]
+        self.assertCountEqual(fnames, ["my_file.pdf", "my_second_file.pdf"])
+
 
 @override_settings(CONSUMER_POLLING=1, CONSUMER_POLLING_DELAY=1, CONSUMER_POLLING_RETRY_COUNT=20)
 class TestConsumerPolling(TestConsumer):