Added ability to disable fsync()

Passed config to LocalStatus and Maildir folders so they can look
up the fsync status
This commit is contained in:
John Goerzen 2008-08-02 14:55:08 -05:00
parent e58cd67401
commit 2b23657db0
5 changed files with 35 additions and 14 deletions

View File

@ -98,6 +98,16 @@ ignore-readonly = no
#
# socktimeout = 60
# By default, OfflineIMAP will use fsync() to force data out to disk at
# opportune times to ensure consistency. This can, however, reduce
# performance. Users where /home is on SSD (Flash) may also wish to reduce
# write cycles. Therefore, you can disable OfflineIMAP's use of fsync().
# Doing so will come at the expense of greater risk of message duplication
# in the event of a system crash or power loss. Default is fsync = true.
# Set fsync = false ot disable fsync.
#
# fsync = true
##################################################
# Mailbox name recorder
##################################################

View File

@ -22,10 +22,12 @@ import os, threading
magicline = "OFFLINEIMAP LocalStatus CACHE DATA - DO NOT MODIFY - FORMAT 1"
class LocalStatusFolder(BaseFolder):
def __init__(self, root, name, repository, accountname):
def __init__(self, root, name, repository, accountname, config):
self.name = name
self.root = root
self.sep = '.'
self.config = config
self.dofsync = config.getdefaultboolean("general", "fsync")
self.filename = os.path.join(root, name)
self.filename = repository.getfolderfilename(name)
self.messagelist = None
@ -96,10 +98,12 @@ class LocalStatusFolder(BaseFolder):
flags = ''.join(flags)
file.write("%s:%s\n" % (msg['uid'], flags))
file.flush()
if self.dofsync:
os.fsync(file.fileno())
file.close()
os.rename(self.filename + ".tmp", self.filename)
if self.dofsync:
try:
fd = os.open(os.path.dirname(self.filename), os.O_RDONLY)
os.fsync(fd)

View File

@ -45,8 +45,10 @@ def gettimeseq():
timelock.release()
class MaildirFolder(BaseFolder):
def __init__(self, root, name, sep, repository, accountname):
def __init__(self, root, name, sep, repository, accountname, config):
self.name = name
self.config = config
self.dofsync = config.getdefaultboolean("general", "fsync")
self.root = root
self.sep = sep
self.messagelist = None
@ -183,6 +185,7 @@ class MaildirFolder(BaseFolder):
# Make sure the data hits the disk
file.flush()
if self.dofsync:
os.fsync(file.fileno())
file.close()

View File

@ -54,12 +54,14 @@ class LocalStatusRepository(BaseRepository):
retval = []
for folder in os.listdir(self.directory):
retval.append(folder.LocalStatus.LocalStatusFolder(self.directory,
folder, self, self.accountname))
folder, self, self.accountname,
self.config))
return retval
def getfolder(self, foldername):
return folder.LocalStatus.LocalStatusFolder(self.directory, foldername,
self, self.accountname)
self, self.accountname,
self.config)

View File

@ -113,7 +113,8 @@ class MaildirRepository(BaseRepository):
if self.config.has_option('Repository ' + self.name, 'restoreatime') and self.config.getboolean('Repository ' + self.name, 'restoreatime'):
self._append_folder_atimes(foldername)
return folder.Maildir.MaildirFolder(self.root, foldername,
self.getsep(), self, self.accountname)
self.getsep(), self,
self.accountname, self.config)
def _getfolders_scandir(self, root, extension = None):
self.debug("_GETFOLDERS_SCANDIR STARTING. root = %s, extension = %s" \
@ -159,7 +160,8 @@ class MaildirRepository(BaseRepository):
if self.config.has_option('Repository ' + self.name, 'restoreatime') and self.config.getboolean('Repository ' + self.name, 'restoreatime'):
self._append_folder_atimes(foldername)
retval.append(folder.Maildir.MaildirFolder(self.root, foldername,
self.getsep(), self, self.accountname))
self.getsep(), self, self.accountname,
self.config))
if self.getsep() == '/' and dirname != '.':
# Check sub-directories for folders.
retval.extend(self._getfolders_scandir(root, foldername))