misc: create hashed subdir for attachments (#24211)
This commit is contained in:
parent
b6aa07137a
commit
d7b938d4d7
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue