From 28bcbd33b9f1203c8161988a30ad008c5490d064 Mon Sep 17 00:00:00 2001 From: rr- Date: Sat, 20 Aug 2016 13:04:49 +0200 Subject: [PATCH] server/posts: use SHA1 checksums This changes the checksums to ones that are compatible with 1.x, which relieves the migration script from recalculating the checksums for all the posts. --- server/szurubooru/func/posts.py | 2 +- server/szurubooru/func/util.py | 8 ++++++++ server/szurubooru/tests/func/test_posts.py | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index e79f149..31ab8d1 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -263,7 +263,7 @@ def update_post_content(post, content): raise InvalidPostContentError( 'Unhandled file type: %r' % post.mime_type) - post.checksum = util.get_md5(content) + post.checksum = util.get_sha1(content) other_post = db.session \ .query(db.Post) \ .filter(db.Post.checksum == post.checksum) \ diff --git a/server/szurubooru/func/util.py b/server/szurubooru/func/util.py index 32e36a6..ed2777c 100644 --- a/server/szurubooru/func/util.py +++ b/server/szurubooru/func/util.py @@ -73,6 +73,14 @@ def get_md5(source): return md5.hexdigest() +def get_sha1(source): + if not isinstance(source, bytes): + source = source.encode('utf-8') + sha1 = hashlib.sha1() + sha1.update(source) + return sha1.hexdigest() + + def flip(source): return {v: k for k, v in source.items()} diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index 43581b6..4429c0f 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -288,8 +288,8 @@ def test_update_post_content( expected_mime_type, expected_type, output_file_name): - with patch('szurubooru.func.util.get_md5'): - util.get_md5.return_value = 'crc' + with patch('szurubooru.func.util.get_sha1'): + util.get_sha1.return_value = 'crc' config_injector({ 'data_dir': str(tmpdir.mkdir('data')), 'thumbnails': {