Use tempfiles while rebuilding group and doc alias files. Fixes #3521. Commit ready for merge.

- Legacy-Id: 19949
This commit is contained in:
Robert Sparks 2022-02-18 16:27:00 +00:00
parent 358132dbfe
commit d6298adacb
2 changed files with 26 additions and 5 deletions

View file

@ -10,6 +10,8 @@ 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)
@ -161,3 +168,7 @@ 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

@ -9,6 +9,8 @@ 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)
@ -87,3 +94,6 @@ class Command(BaseCommand):
afile.close() afile.close()
vfile.close() vfile.close()
os.rename(aname, settings.GROUP_ALIASES_PATH)
os.rename(vname, settings.GROUP_VIRTUAL_PATH)