From 24cdba3221193f18955c8f9c9e53055ccf72162b Mon Sep 17 00:00:00 2001 From: John Goerzen Date: Fri, 19 Oct 2007 20:29:34 +0100 Subject: [PATCH] Undo 'Fix Maildir race' patch This was causing OfflineIMAP to hang --- offlineimap/folder/Maildir.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py index c5d5092..56a63e4 100644 --- a/offlineimap/folder/Maildir.py +++ b/offlineimap/folder/Maildir.py @@ -158,8 +158,7 @@ class MaildirFolder(BaseFolder): # Otherwise, save the message in tmp/ and then call savemessageflags() # to give it a permanent home. tmpdir = os.path.join(self.getfullname(), 'tmp') - file = fd = None - messagename = tmpmessaename = None + messagename = None attempts = 0 while 1: if attempts > 15: @@ -172,24 +171,19 @@ class MaildirFolder(BaseFolder): socket.gethostname(), uid, md5.new(self.getvisiblename()).hexdigest()) - tmpmessagename = messagename.split(',')[0] - try: - fd = os.open(os.path.join(tmpdir, tmpmessagename), - os.O_WRONLY + os.O_CREAT + os.O_EXCL) - file = os.fdopen(fd, 'w') - ui.debug('maildir', 'savemessage: using temporary name %s' % tmpmessagename) - except OSError, e: - if e.errno == 17: - time.sleep(2) - attempts += 1 - continue - raise - + if os.path.exists(os.path.join(tmpdir, messagename)): + time.sleep(2) + attempts += 1 + else: + break + tmpmessagename = messagename.split(',')[0] + ui.debug('maildir', 'savemessage: using temporary name %s' % tmpmessagename) + file = open(os.path.join(tmpdir, tmpmessagename), "wt") file.write(content) # Make sure the data hits the disk file.flush() - os.fsync(fd) + os.fsync(file.fileno()) file.close() if rtime != None: