Merged in [19949] from rjsparks@nostrum.com:

Use tempfiles while rebuilding group and doc alias files. Fixes #3521.
 - Legacy-Id: 19958
Note: SVN reference [19949] has been migrated to Git commit d6298adacb
This commit is contained in:
Robert Sparks 2022-02-22 22:44:56 +00:00
commit 3fa90e7517
2 changed files with 26 additions and 5 deletions

View file

@ -9,6 +9,8 @@ import io
import os import os
import re import re
import time import time
from tempfile import mkstemp
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -102,8 +104,13 @@ class Command(BaseCommand):
date = time.strftime("%Y-%m-%d_%H:%M:%S") date = time.strftime("%Y-%m-%d_%H:%M:%S")
signature = '# Generated by %s at %s\n' % (os.path.abspath(__file__), date) signature = '# Generated by %s at %s\n' % (os.path.abspath(__file__), date)
afile = io.open(settings.DRAFT_ALIASES_PATH, "w") ahandle, aname = mkstemp()
vfile = io.open(settings.DRAFT_VIRTUAL_PATH, "w") os.close(ahandle)
afile = io.open(aname,"w")
vhandle, vname = mkstemp()
os.close(vhandle)
vfile = io.open(vname,"w")
afile.write(signature) afile.write(signature)
vfile.write(signature) vfile.write(signature)
@ -160,4 +167,8 @@ class Command(BaseCommand):
afile.close() afile.close()
vfile.close() vfile.close()
os.rename(aname, settings.DRAFT_ALIASES_PATH)
os.rename(vname, settings.DRAFT_VIRTUAL_PATH)

View file

@ -8,6 +8,8 @@ import datetime
import io import io
import os import os
import time import time
from tempfile import mkstemp
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -40,8 +42,13 @@ class Command(BaseCommand):
date = time.strftime("%Y-%m-%d_%H:%M:%S") date = time.strftime("%Y-%m-%d_%H:%M:%S")
signature = '# Generated by %s at %s\n' % (os.path.abspath(__file__), date) signature = '# Generated by %s at %s\n' % (os.path.abspath(__file__), date)
afile = io.open(settings.GROUP_ALIASES_PATH, "w") ahandle, aname = mkstemp()
vfile = io.open(settings.GROUP_VIRTUAL_PATH, "w") os.close(ahandle)
afile = io.open(aname,"w")
vhandle, vname = mkstemp()
os.close(vhandle)
vfile = io.open(vname,"w")
afile.write(signature) afile.write(signature)
vfile.write(signature) vfile.write(signature)
@ -86,4 +93,7 @@ class Command(BaseCommand):
dump_sublist(afile, vfile, group.acronym+'-chairs', IETF_DOMAIN, settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(group, ['chair', 'delegate'])) dump_sublist(afile, vfile, group.acronym+'-chairs', IETF_DOMAIN, settings.GROUP_VIRTUAL_DOMAIN, get_group_role_emails(group, ['chair', 'delegate']))
afile.close() afile.close()
vfile.close() vfile.close()
os.rename(aname, settings.GROUP_ALIASES_PATH)
os.rename(vname, settings.GROUP_VIRTUAL_PATH)