Index: bin/update =================================================================== RCS file: /cvsroot/mailman/mailman/bin/update,v retrieving revision 2.22.2.6 diff -u -r2.22.2.6 update --- bin/update 24 Apr 2004 12:25:57 -0000 2.22.2.6 +++ bin/update 17 Feb 2005 05:16:13 -0000 @@ -528,6 +528,54 @@ + +# These pending_* functions adapted from Mailman/Pending.py versions + +def pending_load(pendfile): + try: + fp = open(pendfile) + except IOError, e: + if e.errno <> errno.ENOENT: raise + return {'evictions': {}} + try: + return cPickle.load(fp) + finally: + fp.close() + +def pending_save(pendfile, db): + evictions = db['evictions'] + now = time.time() + for cookie, data in db.items(): + if cookie in ('evictions', 'version'): + continue + timestamp = evictions[cookie] + if now > timestamp: + # The entry is stale, so remove it. + del db[cookie] + del evictions[cookie] + # Clean out any bogus eviction entries. + for cookie in evictions.keys(): + if not db.has_key(cookie): + del evictions[cookie] + db['version'] = mm_cfg.PENDING_FILE_SCHEMA_VERSION + tmpfile = '%s.tmp.%d.%d' % (pendfile, os.getpid(), now) + omask = os.umask(007) + try: + fp = open(tmpfile, 'w') + try: + cPickle.dump(db, fp) + fp.flush() + os.fsync(fp.fileno()) + finally: + fp.close() + os.rename(tmpfile, pendfile) + finally: + os.umask(omask) + +def pending_repend(db, cookie, data): + db[cookie] = data + db['evictions'][cookie] = time.time() + mm_cfg.PENDING_REQUEST_LIFE + def update_pending(): file20 = os.path.join(mm_cfg.DATA_DIR, 'pending_subscriptions.db') file214 = os.path.join(mm_cfg.DATA_DIR, 'pending.pck') @@ -596,12 +644,15 @@ # requests. Note that this will reset all the expiration dates, but that # should be fine. for listname in Utils.list_names(): + print _("Updating pending requests for %(listname)s...") mlist = MailList.MailList(listname) - # This is not the most efficient way to do this because it loads and - # saves the pending.pck file each time. :( + # Adapted from __load from the Pending class. + assert mlist.Locked() + pendfile = os.path.join(mlist.fullpath(), 'pending.pck') + db = pending_load(pendfile) try: for cookie, data in reenables_by_list.get(listname, []): - mlist.pend_repend(cookie, data) + pending_repend(db, cookie, data) for id, (cookie, data) in holds_by_id.items(): try: rec = mlist.GetRecord(id) @@ -609,7 +660,7 @@ # Not for this list pass else: - mlist.pend_repend(cookie, data) + pending_repend(db, cookie, data) del holds_by_id[id] for addr, recs in subs_by_address.items(): # We shouldn't have a subscription confirmation if the address @@ -617,14 +668,15 @@ if mlist.isMember(addr): continue for cookie, data in recs: - mlist.pend_repend(cookie, data) + pending_repend(db, cookie, data) for addr, recs in addrops_by_address.items(): # We shouldn't have unsubscriptions or change of address # requests for addresses which aren't members of the list. if not mlist.isMember(addr): continue for cookie, data in recs: - mlist.pend_repend(cookie, data) + pending_repend(db, cookie, data) + pending_save(pendfile, db) mlist.Save() finally: mlist.Unlock()