Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

ignore macOS specific files

jonaswinklerf8afbae2cd34
diff --git a/src/documents/management/commands/document_consumer.py b/src/documents/management/commands/document_consumer.py
index 969941af9..9f0ce79c3 100644
--- a/src/documents/management/commands/document_consumer.py
+++ b/src/documents/management/commands/document_consumer.py
@@ -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
diff --git a/src/documents/tests/test_management_consumer.py b/src/documents/tests/test_management_consumer.py
index 2111705e0..ec5a8dc0b 100644
--- a/src/documents/tests/test_management_consumer.py
+++ b/src/documents/tests/test_management_consumer.py
@@ -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):