mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Fix PowerShell plugin issues affecting fetch module when used against Windows hosts.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user