Remove thread Lock() when saving UIDvalidity
Removing this lock makes the function not threadsafe, but then it is only ever called from one thread, the main account syncer. Also, it doesn't make it worse than most of the other functions in that class which are also not threadsafe. Removing this makes the code simpler, and removes the need to import the threading module. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
607eba178a
commit
fc03475b9e
@ -16,7 +16,6 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
from threading import *
|
|
||||||
from offlineimap import threadutil
|
from offlineimap import threadutil
|
||||||
from offlineimap.ui import getglobalui
|
from offlineimap.ui import getglobalui
|
||||||
import os.path
|
import os.path
|
||||||
@ -26,7 +25,6 @@ import traceback
|
|||||||
|
|
||||||
class BaseFolder:
|
class BaseFolder:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.uidlock = Lock()
|
|
||||||
self.ui = getglobalui()
|
self.ui = getglobalui()
|
||||||
|
|
||||||
def getname(self):
|
def getname(self):
|
||||||
@ -83,6 +81,11 @@ class BaseFolder:
|
|||||||
return foldername
|
return foldername
|
||||||
|
|
||||||
def isuidvalidityok(self):
|
def isuidvalidityok(self):
|
||||||
|
"""Does the cached UID match the real UID
|
||||||
|
|
||||||
|
If required it caches the UID. In this case the function is not
|
||||||
|
threadsafe. So don't attempt to call it from concurrent threads."""
|
||||||
|
|
||||||
if self.getsaveduidvalidity() != None:
|
if self.getsaveduidvalidity() != None:
|
||||||
return self.getsaveduidvalidity() == self.getuidvalidity()
|
return self.getsaveduidvalidity() == self.getuidvalidity()
|
||||||
else:
|
else:
|
||||||
@ -106,17 +109,18 @@ class BaseFolder:
|
|||||||
return self._base_saved_uidvalidity
|
return self._base_saved_uidvalidity
|
||||||
|
|
||||||
def saveuidvalidity(self):
|
def saveuidvalidity(self):
|
||||||
|
"""Save the UID value of the folder to the status
|
||||||
|
|
||||||
|
This function is not threadsafe, so don't attempt to call it
|
||||||
|
from concurrent threads."""
|
||||||
newval = self.getuidvalidity()
|
newval = self.getuidvalidity()
|
||||||
uidfilename = self._getuidfilename()
|
uidfilename = self._getuidfilename()
|
||||||
self.uidlock.acquire()
|
|
||||||
try:
|
file = open(uidfilename + ".tmp", "wt")
|
||||||
file = open(uidfilename + ".tmp", "wt")
|
file.write("%d\n" % newval)
|
||||||
file.write("%d\n" % newval)
|
file.close()
|
||||||
file.close()
|
os.rename(uidfilename + ".tmp", uidfilename)
|
||||||
os.rename(uidfilename + ".tmp", uidfilename)
|
self._base_saved_uidvalidity = newval
|
||||||
self._base_saved_uidvalidity = newval
|
|
||||||
finally:
|
|
||||||
self.uidlock.release()
|
|
||||||
|
|
||||||
def getuidvalidity(self):
|
def getuidvalidity(self):
|
||||||
raise NotImplementedException
|
raise NotImplementedException
|
||||||
@ -425,5 +429,3 @@ class BaseFolder:
|
|||||||
except:
|
except:
|
||||||
self.ui.warn("ERROR attempting to sync flags " \
|
self.ui.warn("ERROR attempting to sync flags " \
|
||||||
+ "for account " + self.getaccountname() + ":" + traceback.format_exc())
|
+ "for account " + self.getaccountname() + ":" + traceback.format_exc())
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user