##// END OF EJS Templates
Validate attachment's hash after downloading
neko259 -
r1518:a5fee885 decentral
parent child Browse files
Show More
@@ -1,7 +1,7 b''
1 import xml.etree.ElementTree as et
1 import xml.etree.ElementTree as et
2
2
3 from boards.models.attachment.downloaders import download
3 from boards.models.attachment.downloaders import download
4 from boards.utils import get_file_mimetype
4 from boards.utils import get_file_mimetype, get_file_hash
5 from django.db import transaction
5 from django.db import transaction
6 from boards.models import KeyPair, GlobalId, Signature, Post, Tag
6 from boards.models import KeyPair, GlobalId, Signature, Post, Tag
7
7
@@ -178,16 +178,20 b' class SyncManager:'
178 attached_file = download(hostname + url)
178 attached_file = download(hostname + url)
179 if attached_file is None:
179 if attached_file is None:
180 raise SyncException('File was not dowloaded')
180 raise SyncException('File was not dowloaded')
181
182 hash = get_file_hash(file)
183 if hash != attachment.text:
184 raise SyncException('File hash does not match attachment hash')
185
181 files.append(attached_file)
186 files.append(attached_file)
182 # TODO Check hash
183
187
184 Post.objects.import_post(
188 Post.objects.import_post(
185 title=title, text=text, pub_time=pub_time,
189 title=title, text=text, pub_time=pub_time,
186 opening_post=opening_post, tags=tags,
190 opening_post=opening_post, tags=tags,
187 global_id=global_id, files=files)
191 global_id=global_id, files=files)
188 else:
192 else:
189 # TODO Throw an exception?
193 raise SyncException('Sync node returned an error: {}'.format(
190 pass
194 tag_status.text))
191
195
192 @staticmethod
196 @staticmethod
193 def generate_response_pull():
197 def generate_response_pull():
General Comments 0
You need to be logged in to leave comments. Login now