From 307ade9f2fb1979a97b868d9de8119c6e3720db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vanicat?= Date: Sun, 4 Mar 2018 12:52:16 +0100 Subject: [PATCH] Check for shutil.SameFileError When copying a mail for MailMover, shutil.copy2 may failed because the origin and source file are the same. In such a case, we should just ignore the exception. Fix #182 --- afew/MailMover.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/afew/MailMover.py b/afew/MailMover.py index 6e55a56..f3c749f 100644 --- a/afew/MailMover.py +++ b/afew/MailMover.py @@ -73,6 +73,9 @@ def move(self, maildir, rules): try: shutil.copy2(fname, self.get_new_name(fname, destination)) to_delete_fnames.append(fname) + except shutil.SameFileError: + logging.warn("trying to move '{}' onto itself".format(fname)) + continue except shutil.Error as e: # this is ugly, but shutil does not provide more # finely individuated errors