2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 01:22:00 +00:00

Switch to mkstemp

Use mkstemp to more confidently reserve a filename as expected.
This commit is contained in:
Jarrod Johnson 2022-02-15 17:13:04 -05:00
parent 3f53cb939a
commit f10a27fd7a
3 changed files with 14 additions and 7 deletions

View File

@ -373,4 +373,4 @@ def install_to_disk(imgpath):
if __name__ == '__main__':
install_to_disk(os.environ['mountsrc'])
install_to_disk(os.environ['mountsrc'])

View File

@ -85,7 +85,8 @@ def assure_tls_ca():
if e.errno != 17:
raise
sslcfg = get_openssl_conf_location()
tmpconfig = tempfile.mktemp()
tmphdl, tmpconfig = tempfile.mkstemp()
os.close(tmphdl)
shutil.copy2(sslcfg, tmpconfig)
subprocess.check_call(
['openssl', 'ecparam', '-name', 'secp384r1', '-genkey', '-out',
@ -151,9 +152,12 @@ def create_certificate(keyout=None, certout=None):
#san.append('DNS:{0}'.format(longname))
san = ','.join(san)
sslcfg = get_openssl_conf_location()
tmpconfig = tempfile.mktemp()
extconfig = tempfile.mktemp()
csrout = tempfile.mktemp()
tmphdl, tmpconfig = tempfile.mkstemp()
os.close(tmphdl)
tmphdl, extconfig = tempfile.mkstemp()
os.close(tmphdl)
tmphdl, csrout = tempfile.mkstemp()
os.close(tmphdl)
shutil.copy2(sslcfg, tmpconfig)
serialnum = '0x' + ''.join(['{:02x}'.format(x) for x in bytearray(os.urandom(20))])
try:

View File

@ -254,8 +254,11 @@ def mkpathorlink(source, destination, appendexist=False):
else:
mkdirp(os.path.dirname(destination))
if appendexist and os.path.exists(destination):
tmpnam = tempfile.mktemp()
shutil.copy(destination, tmpnam)
tmphdl, tmpnam = tempfile.mkstemp()
try:
shutil.copy(destination, tmpnam)
finally:
os.close(tmphdl)
os.remove(destination)
with open(destination, 'w') as realdest:
with open(tmpnam) as olddest: