Commit 2ddab7af by Chris Church

Merge pull request #8793 from cchurch/powershell3_compat

Replace Get-FileHash with MD5 code that works on PowerShell 3.
parents b7082677 0d1197a9
...@@ -89,7 +89,10 @@ class ShellModule(object): ...@@ -89,7 +89,10 @@ class ShellModule(object):
script = ''' script = '''
If (Test-Path -PathType Leaf "%(path)s") If (Test-Path -PathType Leaf "%(path)s")
{ {
(Get-FileHash -Path "%(path)s" -Algorithm MD5).Hash.ToLower(); $sp = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider;
$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();
} }
ElseIf (Test-Path -PathType Container "%(path)s") ElseIf (Test-Path -PathType Container "%(path)s")
{ {
......
...@@ -53,8 +53,11 @@ Else ...@@ -53,8 +53,11 @@ Else
If ($get_md5 -and $result.stat.exists -and -not $result.stat.isdir) If ($get_md5 -and $result.stat.exists -and -not $result.stat.isdir)
{ {
$path_md5 = (Get-FileHash -Path $path -Algorithm MD5).Hash.ToLower(); $sp = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider;
Set-Attr $result.stat "md5" $path_md5; $fp = [System.IO.File]::Open($path, [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read);
$hash = [System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower();
$fp.Dispose();
Set-Attr $result.stat "md5" $hash;
} }
Exit-Json $result; Exit-Json $result;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment