summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarsaw2001-11-24 00:02:56 +0000
committerbwarsaw2001-11-24 00:02:56 +0000
commit478a6c511c86c00f8f5183502997911860a30918 (patch)
tree5c4c020bef8a77dc9628341b15766f774af7aeda
parent016c9e93002d056b331eeb1eb01b55ecd43071a1 (diff)
downloadmailman-478a6c511c86c00f8f5183502997911860a30918.tar.gz
mailman-478a6c511c86c00f8f5183502997911860a30918.tar.zst
mailman-478a6c511c86c00f8f5183502997911860a30918.zip
zapfile(): Zero out a file without messing with the file permissions.
main(): Collate lists first by host_name, zap the aliases file, and then each of the virtual files for each domain. Then we can just use Postfix.create() to write the appropriate entries to all the files.
-rw-r--r--bin/genaliases36
1 files changed, 21 insertions, 15 deletions
diff --git a/bin/genaliases b/bin/genaliases
index 7fb1b73ce..172ae66ad 100644
--- a/bin/genaliases
+++ b/bin/genaliases
@@ -60,6 +60,13 @@ def usage(code, msg=''):
+def zapfile(filename):
+ # Truncate the file w/o messing with the file permissions
+ fp = open(filename, 'w')
+ fp.close()
+
+
+
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 'h', ['help'])
@@ -79,27 +86,26 @@ def main():
lock = Postfix.makelock()
lock.lock()
lockfp = None
+ # Group lists by virtual hostname
+ mlists = {}
+ for listname in Utils.list_names():
+ mlist = MailList.MailList(listname, lock=0)
+ mlists.setdefault(mlist.host_name, []).append(mlist)
# Make sure the files are created rw-rw-xxx; it should be okay to be world
# readable.
omask = os.umask(002)
try:
- # Overwrite the current file contents, since we're going to be adding
- # all new entries. See the discussion in Mailman/MTA/Postfix.py for
- # why we do the locking this way.
- lockfp = open(Postfix.DBFILE, 'w')
- fcntl.flock(lockfp.fileno(), fcntl.LOCK_EX)
- db = bsddb.hashopen(Postfix.DBFILE, 'n')
- fp = open(Postfix.TEXTFILE, 'w')
- for listname in Utils.list_names():
- mlist = MailList.MailList(listname, lock=0)
- Postfix.addlist(mlist, db, fp)
- db.sync()
- fp.close()
+ # Remove the original files
+ zapfile(Postfix.DBFILE)
+ zapfile(Postfix.TEXTFILE)
+ for hostname, vlists in mlists.items():
+ dbfile, textfile = Postfix.virtual_files(hostname)
+ zapfile(dbfile)
+ zapfile(textfile)
+ for mlist in vlists:
+ Postfix.create(mlist, nolock=1)
finally:
os.umask(omask)
- if lockfp:
- fcntl.flock(lockfp.fileno(), fcntl.LOCK_UN)
- lockfp.close()
lock.unlock(unconditionally=1)