Merge pull request #9688 from cchurch/fix_win_fetch

Fixes for fetch module when connecting to Windows hosts
This commit is contained in:
Chris Church 2014-12-02 15:15:06 -05:00
commit 2bf269568b
4 changed files with 21 additions and 8 deletions

View file

@ -1207,7 +1207,7 @@ class Runner(object):
return path
if len(split_path) > 1:
return os.path.join(initial_fragment, *split_path[1:])
return conn.shell.join_path(initial_fragment, *split_path[1:])
else:
return initial_fragment

View file

@ -193,7 +193,7 @@ class Connection(object):
def fetch_file(self, in_path, out_path):
out_path = out_path.replace('\\', '/')
vvv("FETCH %s TO %s" % (in_path, out_path), host=self.host)
buffer_size = 2**20 # 1MB chunks
buffer_size = 2**19 # 0.5MB chunks
if not os.path.exists(os.path.dirname(out_path)):
os.makedirs(os.path.dirname(out_path))
out_file = None

View file

@ -84,12 +84,24 @@ class ShellModule(object):
# FIXME: Support system temp path!
return _encode_script('''(New-Item -Type Directory -Path $env:temp -Name "%s").FullName | Write-Host -Separator '';''' % basefile)
def md5(self, path):
def expand_user(self, user_home_path):
# PowerShell only supports "~" (not "~username"). Resolve-Path ~ does
# not seem to work remotely, though by default we are always starting
# in the user's home directory.
if user_home_path == '~':
script = 'Write-Host (Get-Location).Path'
elif user_home_path.startswith('~\\'):
script = 'Write-Host ((Get-Location).Path + "%s")' % _escape(user_home_path[1:])
else:
script = 'Write-Host "%s"' % _escape(user_home_path)
return _encode_script(script)
def checksum(self, path, python_interp):
path = _escape(path)
script = '''
If (Test-Path -PathType Leaf "%(path)s")
{
$sp = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider;
$sp = new-object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider;
$fp = [System.IO.File]::Open("%(path)s", [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read);
[System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower();
$fp.Dispose();