Merge pull request #47565 from rallytime/bp-47440

Back-port #47440 to 2018.3
This commit is contained in:
Nicole Thomas 2018-05-10 14:15:49 -04:00 committed by GitHub
commit b22657ff9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -13,6 +13,7 @@ import string
import shutil
import ftplib
from tornado.httputil import parse_response_start_line, HTTPHeaders, HTTPInputError
import salt.utils.atomicfile
# Import salt libs
from salt.exceptions import (
@ -1166,7 +1167,11 @@ class RemoteClient(Client):
destdir = os.path.dirname(dest)
if not os.path.isdir(destdir):
if makedirs:
os.makedirs(destdir)
try:
os.makedirs(destdir)
except OSError as exc:
if exc.errno != errno.EEXIST: # ignore if it was there already
raise
else:
return False
# We need an open filehandle here, that's why we're not using a
@ -1221,7 +1226,7 @@ class RemoteClient(Client):
# remove it to avoid a traceback trying to write the file
if os.path.isdir(dest):
salt.utils.files.rm_rf(dest)
fn_ = salt.utils.files.fopen(dest, 'wb+')
fn_ = salt.utils.atomicfile.atomic_open(dest, 'wb+')
if data.get('gzip', None):
data = salt.utils.gzip_util.uncompress(data['data'])
else:

View file

@ -464,6 +464,7 @@ def gen_min(cachedir, extra_mods='', overwrite=False, so_mods='',
'salt/__init__.py',
'salt/utils',
'salt/utils/__init__.py',
'salt/utils/atomicfile.py',
'salt/utils/validate',
'salt/utils/validate/__init__.py',
'salt/utils/validate/path.py',