]> code.delx.au - offlineimap/commitdiff
/offlineimap/head: changeset 352
authorjgoerzen <jgoerzen>
Thu, 30 Jan 2003 01:19:53 +0000 (02:19 +0100)
committerjgoerzen <jgoerzen>
Thu, 30 Jan 2003 01:19:53 +0000 (02:19 +0100)
Added check to make sure that two processes do not run in the same
directory at once.

offlineimap/head/debian/changelog
offlineimap/head/offlineimap/init.py
offlineimap/head/offlineimap/ui/UIBase.py

index 416cd4fbc6e536ffc4a63b25895814f18333bbb5..f331f393668844b88d4362340913ee39534fa3b1 100644 (file)
@@ -1,3 +1,10 @@
+offlineimap (3.99.9) unstable; urgency=low
+
+  * Added check to make sure that two processes do not run in the same
+    directory at once.
+
+ -- John Goerzen <jgoerzen@complete.org>  Wed, 29 Jan 2003 13:19:14 -0600
+
 offlineimap (3.99.8) unstable; urgency=low
 
   * This is a 4.0 TRACK release, and may be unstable or in flux!
index 2ba9bbc9ccde08ca45abff8b238cf52e96332c01..4faffd9e7d64cc4c54ad8db84399c31fd75da091 100644 (file)
@@ -20,11 +20,22 @@ from offlineimap import imaplib, imapserver, repository, folder, mbnames, thread
 from offlineimap.localeval import LocalEval
 from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
 from offlineimap.ui import UIBase
-import re, os, os.path, offlineimap, sys
+import re, os, os.path, offlineimap, sys, fcntl
 from offlineimap.CustomConfig import CustomConfigParser
 from threading import *
 from getopt import getopt
 
+lockfd = None
+
+def lock(config, ui):
+    global lockfd
+    lockfd = open(config.getmetadatadir() + "/lock", "w")
+    try:
+        fcntl.flock(lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
+    except IOError:
+        ui.locked()
+        ui.terminate(1)
+
 def startup(versionno):
     assert versionno == version.versionstr, "Revision of main program (%d) does not match that of library (%d).  Please double-check your PYTHONPATH and installation locations." % (revno, version.revno)
     options = {}
@@ -72,6 +83,8 @@ def startup(versionno):
         for section in config.getaccountlist():
             config.remove_option(section, "autorefresh")
 
+    lock(config, ui)
+
     accounts = config.get("general", "accounts")
     if '-a' in options:
         accounts = options['-a']
index 776275aeea8b4f48a095d9a3959ba169b8fe44fe..0eae1a2e54d9828b10a5912a10045705915e9a14 100644 (file)
@@ -101,6 +101,9 @@ class UIBase:
     def invaliddebug(s, debugtype):
         s.warn("Invalid debug type: %s" % debugtype)
 
+    def locked(s):
+        s.warn("Another OfflineIMAP is running with the same metadatadir; exiting.")
+
     def getnicename(s, object):
         prelimname = str(object.__class__).split('.')[-1]
         # Strip off extra stuff.