Remove directory in Windows with runas

This commit is contained in:
twangboy 2016-09-26 18:03:21 -06:00
parent 25d52efeac
commit 377ced5c24

View file

@ -18,6 +18,7 @@ import subprocess
import sys
import time
import traceback
import tempfile
from salt.utils import vt
# Import salt libs
@ -25,7 +26,8 @@ import salt.utils
import salt.utils.timed_subprocess
import salt.grains.extra
import salt.ext.six as six
from salt.exceptions import CommandExecutionError, TimedProcTimeoutError
from salt.exceptions import CommandExecutionError, TimedProcTimeoutError, \
SaltInvocationError
from salt.log import LOG_LEVELS
from salt.ext.six.moves import range
from salt.ext.six.moves import shlex_quote as _cmd_quote
@ -1986,8 +1988,8 @@ def script(source,
def _cleanup_tempfile(path):
try:
os.remove(path)
except (IOError, OSError) as exc:
__salt__['file.remove'](path)
except (SaltInvocationError, CommandExecutionError) as exc:
log.error(
'cmd.script: Unable to clean tempfile \'{0}\': {1}'.format(
path,
@ -2005,10 +2007,8 @@ def script(source,
saltenv = __env__
if salt.utils.is_windows() and runas and cwd is None:
cwd = os.path.join(__opts__['cachedir'], 'wintmp')
if not os.path.isdir(cwd):
__salt__['file.mkdir'](cwd)
ret = __salt__['win_dacl.add_ace'](
cwd = tempfile.mkdtemp(dir=__opts__['cachedir'])
__salt__['win_dacl.add_ace'](
cwd, 'File', runas, 'READ&EXECUTE', 'ALLOW',
'FOLDER&SUBFOLDERS&FILES')
@ -2024,7 +2024,10 @@ def script(source,
saltenv,
**kwargs)
if not fn_:
_cleanup_tempfile(path)
if salt.utils.is_windows() and runas:
_cleanup_tempfile(cwd)
else:
_cleanup_tempfile(path)
return {'pid': 0,
'retcode': 1,
'stdout': '',
@ -2033,7 +2036,10 @@ def script(source,
else:
fn_ = __salt__['cp.cache_file'](source, saltenv)
if not fn_:
_cleanup_tempfile(path)
if salt.utils.is_windows() and runas:
_cleanup_tempfile(cwd)
else:
_cleanup_tempfile(path)
return {'pid': 0,
'retcode': 1,
'stdout': '',
@ -2061,7 +2067,10 @@ def script(source,
use_vt=use_vt,
bg=bg,
password=password)
_cleanup_tempfile(path)
if salt.utils.is_windows() and runas:
_cleanup_tempfile(cwd)
else:
_cleanup_tempfile(path)
return ret