From e9132cef48b908202e731fff779e7ddf3c4a1280 Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Fri, 1 Jun 2018 10:58:15 +0200 Subject: [PATCH] misc: create hashed subdir for attachments (#24211) --- tests/test_workflows.py | 6 ++++++ wcs/workflows.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 14e56798..2b4eb136 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -784,6 +784,9 @@ def test_register_comment_attachment(pub): fp=StringIO.StringIO('hello world'), varname='testfile')] formdata.store() assert len(os.listdir(os.path.join(get_publisher().app_dir, 'attachments'))) == 1 + for subdir in os.listdir(os.path.join(get_publisher().app_dir, 'attachments')): + assert len(subdir) == 4 + assert len(os.listdir(os.path.join(get_publisher().app_dir, 'attachments', subdir))) == 1 item.comment = '{{ attachments.testfile.url }}' @@ -797,6 +800,9 @@ def test_register_comment_attachment(pub): url2 = formdata.evolution[-1].parts[-1].content assert len(os.listdir(os.path.join(get_publisher().app_dir, 'attachments'))) == 1 + for subdir in os.listdir(os.path.join(get_publisher().app_dir, 'attachments')): + assert len(subdir) == 4 + assert len(os.listdir(os.path.join(get_publisher().app_dir, 'attachments', subdir))) == 1 assert url1 == url2 pub.substitutions.feed(formdata) diff --git a/wcs/workflows.py b/wcs/workflows.py index 613a5eba..4abc97b3 100644 --- a/wcs/workflows.py +++ b/wcs/workflows.py @@ -200,6 +200,9 @@ class AttachmentEvolutionPart: #pylint: disable=C1001 if not 'filename' in odict: filename = file_digest(self.fp) + dirname = os.path.join(dirname, filename[:4]) + if not os.path.exists(dirname): + os.mkdir(dirname) odict['filename'] = os.path.join(dirname, filename) self.filename = odict['filename'] self.fp.seek(0) -- 2.17.0