diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-04-14 11:44:14 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-04-14 11:45:29 +0300 |
commit | 7fb537add20a32fa33d8e740d5b7167de155de83 (patch) | |
tree | f437b9bfd3a05cfa2b3c17cd87309766ba6adcf1 | |
parent | 80ddfc231c7c217e85b814eadd351c04c6a6a7bc (diff) | |
download | distix-7fb537add20a32fa33d8e740d5b7167de155de83.tar.gz |
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.
-rw-r--r-- | distixlib/ticket_store.py | 15 |
1 files 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): |