From 7fb537add20a32fa33d8e740d5b7167de155de83 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 14 Apr 2017 11:44:14 +0300 Subject: Fix duplicate checking We must compare msg.as_string() to msg.as_string(), since it doesn't necessarily return the exact same data as the original string the msg was built from. --- distixlib/ticket_store.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/distixlib/ticket_store.py b/distixlib/ticket_store.py index 1a8b809..82ebc1e 100644 --- a/distixlib/ticket_store.py +++ b/distixlib/ticket_store.py @@ -16,6 +16,7 @@ # =*= License: GPL-3+ =*= +import email import os import distixlib @@ -197,12 +198,16 @@ class TicketStore(object): return message_filenames - def _file_contains(self, filename, data): # pragma: no cover - st = os.lstat(filename) - if st.st_size != len(data): - return False + def _file_contains(self, filename, data): # pragma: no cover Note + # that the email.Message class may reformat headers, so that + # msg.as_string() doesn't return the pristine original message + # text. Thus we can't just compare file content with data. + # Instead we load the file content into a message, let any + # reformatting happen, and then compare msg.as_string() with + # data. with open(filename) as f: - return f.read() == data + msg = email.message_from_file(f) + return msg.as_string() == data class _TicketCache(object): -- cgit v1.2.1