mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Use os.write() on file descriptor instead of opening a filehandle
tempfile.mkstemp() already gives us an OS-level file descriptor, opening a separate filehandle for this is unnecessary.
This commit is contained in:
parent
f61e8d6366
commit
072fd823f7
@ -1805,12 +1805,11 @@ def scp_file(dest_path, contents=None, kwargs=None, local_file=None):
|
||||
file_to_upload = None
|
||||
else:
|
||||
try:
|
||||
tmpfh, file_to_upload = tempfile.mkstemp()
|
||||
with salt.utils.fopen(file_to_upload, 'w') as fp_:
|
||||
fp_.write(contents)
|
||||
tmpfd, file_to_upload = tempfile.mkstemp()
|
||||
os.write(tmpfd, contents)
|
||||
finally:
|
||||
try:
|
||||
os.close(tmpfh)
|
||||
os.close(tmpfd)
|
||||
except OSError as exc:
|
||||
if exc.errno != errno.EBADF:
|
||||
raise exc
|
||||
@ -1932,12 +1931,11 @@ def sftp_file(dest_path, contents=None, kwargs=None, local_file=None):
|
||||
file_to_upload = None
|
||||
else:
|
||||
try:
|
||||
tmpfh, file_to_upload = tempfile.mkstemp()
|
||||
with salt.utils.fopen(file_to_upload, 'w') as fp_:
|
||||
fp_.write(contents)
|
||||
tmpfd, file_to_upload = tempfile.mkstemp()
|
||||
os.write(tmpfd, contents)
|
||||
finally:
|
||||
try:
|
||||
os.close(tmpfh)
|
||||
os.close(tmpfd)
|
||||
except OSError as exc:
|
||||
if exc.errno != errno.EBADF:
|
||||
raise exc
|
||||
|
Loading…
Reference in New Issue
Block a user