diff --git a/offlineimap/head/debian/changelog b/offlineimap/head/debian/changelog index 416cd4f..f331f39 100644 --- a/offlineimap/head/debian/changelog +++ b/offlineimap/head/debian/changelog @@ -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 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! diff --git a/offlineimap/head/offlineimap/init.py b/offlineimap/head/offlineimap/init.py index 2ba9bbc..4faffd9 100644 --- a/offlineimap/head/offlineimap/init.py +++ b/offlineimap/head/offlineimap/init.py @@ -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'] diff --git a/offlineimap/head/offlineimap/ui/UIBase.py b/offlineimap/head/offlineimap/ui/UIBase.py index 776275a..0eae1a2 100644 --- a/offlineimap/head/offlineimap/ui/UIBase.py +++ b/offlineimap/head/offlineimap/ui/UIBase.py @@ -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.