winrm-fs 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +86 -86
- data/Rakefile +28 -28
- data/VERSION +1 -1
- data/appveyor.yml +39 -39
- data/changelog.md +46 -43
- data/lib/winrm-fs/core/file_transporter.rb +529 -529
- data/lib/winrm-fs/core/tmp_zip.rb +166 -166
- data/lib/winrm-fs/file_manager.rb +117 -117
- data/lib/winrm-fs/scripts/check_files.ps1.erb +60 -60
- data/lib/winrm-fs/scripts/decode_files.ps1.erb +58 -58
- data/lib/winrm-fs/scripts/download.ps1.erb +8 -8
- data/lib/winrm-fs/scripts/exists.ps1.erb +10 -10
- data/spec/config-example.yml +4 -4
- data/spec/integration/file_manager_spec.rb +218 -218
- data/spec/integration/tmp_zip_spec.rb +26 -26
- data/spec/spec_helper.rb +72 -72
- data/spec/unit/file_transporter_spec.rb +839 -839
- data/spec/unit/tmp_zip_spec.rb +79 -79
- data/winrm-fs.gemspec +37 -37
- metadata +3 -3
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
$host.ui.RawUI.WindowSize.Width=256
|
|
2
|
-
$hash_file = "<%= hash_file %>"
|
|
3
|
-
|
|
4
|
-
Function Cleanup($o) { if (($o -ne $null) -and ($o.GetType().GetMethod("Dispose") -ne $null)) { $o.Dispose() } }
|
|
5
|
-
|
|
6
|
-
Function Decode-Base64File($src, $dst) {
|
|
7
|
-
Try {
|
|
8
|
-
$in = (Get-Item $src).OpenRead()
|
|
9
|
-
$b64 = New-Object -TypeName System.Security.Cryptography.FromBase64Transform
|
|
10
|
-
$m = [System.Security.Cryptography.CryptoStreamMode]::Read
|
|
11
|
-
$d = New-Object -TypeName System.Security.Cryptography.CryptoStream $in,$b64,$m
|
|
12
|
-
Copy-Stream $d ($out = [System.IO.File]::OpenWrite($dst))
|
|
13
|
-
} Finally { Cleanup $in; Cleanup $out; Cleanup $d }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
Function Copy-Stream($src, $dst) { $b = New-Object Byte[] 4096; while (($i = $src.Read($b, 0, $b.Length)) -ne 0) { $dst.Write($b, 0, $i) } }
|
|
17
|
-
|
|
18
|
-
Function Check-Files($h) {
|
|
19
|
-
return $h.GetEnumerator() | ForEach-Object {
|
|
20
|
-
$dst = Unresolve-Path $_.Value.target
|
|
21
|
-
$dst_changed = $false
|
|
22
|
-
if(Test-Path $dst -PathType Container) {
|
|
23
|
-
$dst_changed = $true
|
|
24
|
-
$dst = Join-Path $dst $_.Value.src_basename
|
|
25
|
-
}
|
|
26
|
-
New-Object psobject -Property @{
|
|
27
|
-
chk_exists = ($exists = Test-Path $dst -PathType Leaf)
|
|
28
|
-
src_md5 = ($sMd5 = $_.Key)
|
|
29
|
-
dst_md5 = ($dMd5 = if ($exists) { Get-MD5Sum $dst } else { $null })
|
|
30
|
-
chk_dirty = ($dirty = if ($sMd5 -ne $dMd5) { $true } else { $false })
|
|
31
|
-
verifies = if ($dirty -eq $false) { $true } else { $false }
|
|
32
|
-
target_is_folder = $dst_changed
|
|
33
|
-
}
|
|
34
|
-
} | Select-Object -Property chk_exists,src_md5,dst_md5,chk_dirty,verifies,target_is_folder
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
Function Get-MD5Sum($src) {
|
|
38
|
-
Try {
|
|
39
|
-
$c = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
|
|
40
|
-
$bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead()))
|
|
41
|
-
return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower()
|
|
42
|
-
} Finally { Cleanup $c; Cleanup $in }
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
Function Invoke-Input($in) {
|
|
46
|
-
$in = Unresolve-Path $in
|
|
47
|
-
Decode-Base64File $in ($decoded = "$($in).ps1")
|
|
48
|
-
$expr = Get-Content $decoded | Out-String
|
|
49
|
-
Remove-Item $in,$decoded -Force
|
|
50
|
-
try {
|
|
51
|
-
return Invoke-Expression "$expr"
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
throw "There was an error invoking '$expr': `n$($_ | Out-String)"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
Function Unresolve-Path($p) { if ($p -eq $null) { return $null } else { return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($p) } }
|
|
59
|
-
|
|
60
|
-
Check-Files (Invoke-Input $hash_file) | ConvertTo-Csv -NoTypeInformation
|
|
1
|
+
$host.ui.RawUI.WindowSize.Width=256
|
|
2
|
+
$hash_file = "<%= hash_file %>"
|
|
3
|
+
|
|
4
|
+
Function Cleanup($o) { if (($o -ne $null) -and ($o.GetType().GetMethod("Dispose") -ne $null)) { $o.Dispose() } }
|
|
5
|
+
|
|
6
|
+
Function Decode-Base64File($src, $dst) {
|
|
7
|
+
Try {
|
|
8
|
+
$in = (Get-Item $src).OpenRead()
|
|
9
|
+
$b64 = New-Object -TypeName System.Security.Cryptography.FromBase64Transform
|
|
10
|
+
$m = [System.Security.Cryptography.CryptoStreamMode]::Read
|
|
11
|
+
$d = New-Object -TypeName System.Security.Cryptography.CryptoStream $in,$b64,$m
|
|
12
|
+
Copy-Stream $d ($out = [System.IO.File]::OpenWrite($dst))
|
|
13
|
+
} Finally { Cleanup $in; Cleanup $out; Cleanup $d }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
Function Copy-Stream($src, $dst) { $b = New-Object Byte[] 4096; while (($i = $src.Read($b, 0, $b.Length)) -ne 0) { $dst.Write($b, 0, $i) } }
|
|
17
|
+
|
|
18
|
+
Function Check-Files($h) {
|
|
19
|
+
return $h.GetEnumerator() | ForEach-Object {
|
|
20
|
+
$dst = Unresolve-Path $_.Value.target
|
|
21
|
+
$dst_changed = $false
|
|
22
|
+
if(Test-Path $dst -PathType Container) {
|
|
23
|
+
$dst_changed = $true
|
|
24
|
+
$dst = Join-Path $dst $_.Value.src_basename
|
|
25
|
+
}
|
|
26
|
+
New-Object psobject -Property @{
|
|
27
|
+
chk_exists = ($exists = Test-Path $dst -PathType Leaf)
|
|
28
|
+
src_md5 = ($sMd5 = $_.Key)
|
|
29
|
+
dst_md5 = ($dMd5 = if ($exists) { Get-MD5Sum $dst } else { $null })
|
|
30
|
+
chk_dirty = ($dirty = if ($sMd5 -ne $dMd5) { $true } else { $false })
|
|
31
|
+
verifies = if ($dirty -eq $false) { $true } else { $false }
|
|
32
|
+
target_is_folder = $dst_changed
|
|
33
|
+
}
|
|
34
|
+
} | Select-Object -Property chk_exists,src_md5,dst_md5,chk_dirty,verifies,target_is_folder
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Function Get-MD5Sum($src) {
|
|
38
|
+
Try {
|
|
39
|
+
$c = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
|
|
40
|
+
$bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead()))
|
|
41
|
+
return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower()
|
|
42
|
+
} Finally { Cleanup $c; Cleanup $in }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Function Invoke-Input($in) {
|
|
46
|
+
$in = Unresolve-Path $in
|
|
47
|
+
Decode-Base64File $in ($decoded = "$($in).ps1")
|
|
48
|
+
$expr = Get-Content $decoded | Out-String
|
|
49
|
+
Remove-Item $in,$decoded -Force
|
|
50
|
+
try {
|
|
51
|
+
return Invoke-Expression "$expr"
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw "There was an error invoking '$expr': `n$($_ | Out-String)"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Function Unresolve-Path($p) { if ($p -eq $null) { return $null } else { return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($p) } }
|
|
59
|
+
|
|
60
|
+
Check-Files (Invoke-Input $hash_file) | ConvertTo-Csv -NoTypeInformation
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
trap {$e = $_.Exception; $e.InvocationInfo.ScriptName; do {$e.Message; $e = $e.InnerException} while ($e); break;}
|
|
2
|
-
function Decode-Base64File($src, $dst) {folder (split-path $dst);sc -force -Encoding Byte -Path $dst -Value ([Convert]::FromBase64String([IO.File]::ReadAllLines($src)))}
|
|
3
|
-
function Copy-Stream($src, $dst) {$b = New-Object Byte[] 4096; while (($i = $src.Read($b, 0, $b.Length)) -ne 0) { $dst.Write($b, 0, $i) } }
|
|
4
|
-
function Resolve-ProviderPath{ $input | % {if ($_){(Resolve-Path $_).ProviderPath} else{$null}} }
|
|
5
|
-
function Get-FrameworkVersion { "Full", "Client" | % {([version](gp "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\$_").Version)} | select -first 1}
|
|
6
|
-
function Test-NETStack($Version){ Get-FrameworkVersion -ge $Version }
|
|
7
|
-
function Test-IOCompression {($PSVersionTable.PSVersion.Major -ge 3) -and (Test-NETStack '4.5')}
|
|
8
|
-
function folder($path){ $path | ? {-not (test-path $_)} | % {$null = mkdir $_}}
|
|
9
|
-
function disposable($o){($o -is [IDisposable]) -and (($o | gm | %{$_.name}) -contains 'Dispose')}
|
|
10
|
-
function use($obj, [scriptblock]$sb){try {& $sb} catch [exception]{throw $_} finally {if (disposable $obj) {$obj.Dispose()}} }
|
|
11
|
-
set-alias RPP -Value Resolve-ProviderPath
|
|
12
|
-
|
|
13
|
-
Function Decode-Files($hash) {
|
|
14
|
-
foreach ($key in $hash.keys) {
|
|
15
|
-
$value = $hash[$key]
|
|
16
|
-
$tmp, $tzip, $dst = $Key, $Value["tmpzip"], $Value["dst"]
|
|
17
|
-
if(!$tmp.StartsWith("clean")) {
|
|
18
|
-
$sMd5 = (gi $tmp).BaseName.Replace("b64-", "")
|
|
19
|
-
$decoded = if ($tzip -ne $null) { $tzip } else { $dst }
|
|
20
|
-
Decode-Base64File $tmp $decoded
|
|
21
|
-
rm $tmp -Force
|
|
22
|
-
$dMd5 = Get-MD5Sum $decoded
|
|
23
|
-
$verifies = $sMd5 -like $dMd5
|
|
24
|
-
}
|
|
25
|
-
if ($tzip) {Unzip-File $tzip $dst}
|
|
26
|
-
New-Object psobject -Property @{dst=$dst;verifies=$verifies;src_md5=$sMd5;dst_md5=$dMd5;tmpfile=$tmp;tmpzip=$tzip}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
Function Get-MD5Sum($src) {
|
|
31
|
-
if ($src -and (test-path $src)) {
|
|
32
|
-
use ($c = New-Object -TypeName Security.Cryptography.MD5CryptoServiceProvider) {
|
|
33
|
-
use ($in = (gi $src).OpenRead()) {([BitConverter]::ToString($c.ComputeHash($in))).Replace("-", "").ToLower()}}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
Function Invoke-Input($in) {
|
|
38
|
-
$in = $in | rpp
|
|
39
|
-
$d = "$($in).ps1"
|
|
40
|
-
Decode-Base64File $in $d
|
|
41
|
-
$expr = gc $d | Out-String
|
|
42
|
-
rm $in,$d -Force
|
|
43
|
-
iex "$expr"
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
Function Unzip-File($src, $dst) {
|
|
47
|
-
$unpack = $src -replace '\.zip'
|
|
48
|
-
$dst_parent = Split-Path -Path $dst -Parent
|
|
49
|
-
if(!(Test-Path $dst_parent)) { $dst = $dst_parent }
|
|
50
|
-
folder $unpack, $dst
|
|
51
|
-
if (Test-IOCompression) {Add-Type -AN System.IO.Compression.FileSystem; [IO.Compression.ZipFile]::ExtractToDirectory($src, $unpack)}
|
|
52
|
-
else {Try {$s = New-Object -ComObject Shell.Application; ($s.NameSpace($unpack)).CopyHere(($s.NameSpace($src)).Items(), 0x610)} Finally {[void][Runtime.Interopservices.Marshal]::ReleaseComObject($s)}}
|
|
53
|
-
dir $unpack | cp -dest "$dst/" -force -recurse
|
|
54
|
-
rm $unpack -recurse -force
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
$hash_file = "<%= hash_file %>"
|
|
58
|
-
Decode-Files (Invoke-Input $hash_file) | ConvertTo-Csv -NoTypeInformation
|
|
1
|
+
trap {$e = $_.Exception; $e.InvocationInfo.ScriptName; do {$e.Message; $e = $e.InnerException} while ($e); break;}
|
|
2
|
+
function Decode-Base64File($src, $dst) {folder (split-path $dst);sc -force -Encoding Byte -Path $dst -Value ([Convert]::FromBase64String([IO.File]::ReadAllLines($src)))}
|
|
3
|
+
function Copy-Stream($src, $dst) {$b = New-Object Byte[] 4096; while (($i = $src.Read($b, 0, $b.Length)) -ne 0) { $dst.Write($b, 0, $i) } }
|
|
4
|
+
function Resolve-ProviderPath{ $input | % {if ($_){(Resolve-Path $_).ProviderPath} else{$null}} }
|
|
5
|
+
function Get-FrameworkVersion { "Full", "Client" | % {([version](gp "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\$_").Version)} | select -first 1}
|
|
6
|
+
function Test-NETStack($Version){ Get-FrameworkVersion -ge $Version }
|
|
7
|
+
function Test-IOCompression {($PSVersionTable.PSVersion.Major -ge 3) -and (Test-NETStack '4.5')}
|
|
8
|
+
function folder($path){ $path | ? {-not (test-path $_)} | % {$null = mkdir $_}}
|
|
9
|
+
function disposable($o){($o -is [IDisposable]) -and (($o | gm | %{$_.name}) -contains 'Dispose')}
|
|
10
|
+
function use($obj, [scriptblock]$sb){try {& $sb} catch [exception]{throw $_} finally {if (disposable $obj) {$obj.Dispose()}} }
|
|
11
|
+
set-alias RPP -Value Resolve-ProviderPath
|
|
12
|
+
|
|
13
|
+
Function Decode-Files($hash) {
|
|
14
|
+
foreach ($key in $hash.keys) {
|
|
15
|
+
$value = $hash[$key]
|
|
16
|
+
$tmp, $tzip, $dst = $Key, $Value["tmpzip"], $Value["dst"]
|
|
17
|
+
if(!$tmp.StartsWith("clean")) {
|
|
18
|
+
$sMd5 = (gi $tmp).BaseName.Replace("b64-", "")
|
|
19
|
+
$decoded = if ($tzip -ne $null) { $tzip } else { $dst }
|
|
20
|
+
Decode-Base64File $tmp $decoded
|
|
21
|
+
rm $tmp -Force
|
|
22
|
+
$dMd5 = Get-MD5Sum $decoded
|
|
23
|
+
$verifies = $sMd5 -like $dMd5
|
|
24
|
+
}
|
|
25
|
+
if ($tzip) {Unzip-File $tzip $dst}
|
|
26
|
+
New-Object psobject -Property @{dst=$dst;verifies=$verifies;src_md5=$sMd5;dst_md5=$dMd5;tmpfile=$tmp;tmpzip=$tzip}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Function Get-MD5Sum($src) {
|
|
31
|
+
if ($src -and (test-path $src)) {
|
|
32
|
+
use ($c = New-Object -TypeName Security.Cryptography.MD5CryptoServiceProvider) {
|
|
33
|
+
use ($in = (gi $src).OpenRead()) {([BitConverter]::ToString($c.ComputeHash($in))).Replace("-", "").ToLower()}}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
Function Invoke-Input($in) {
|
|
38
|
+
$in = $in | rpp
|
|
39
|
+
$d = "$($in).ps1"
|
|
40
|
+
Decode-Base64File $in $d
|
|
41
|
+
$expr = gc $d | Out-String
|
|
42
|
+
rm $in,$d -Force
|
|
43
|
+
iex "$expr"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Function Unzip-File($src, $dst) {
|
|
47
|
+
$unpack = $src -replace '\.zip'
|
|
48
|
+
$dst_parent = Split-Path -Path $dst -Parent
|
|
49
|
+
if(!(Test-Path $dst_parent)) { $dst = $dst_parent }
|
|
50
|
+
folder $unpack, $dst
|
|
51
|
+
if (Test-IOCompression) {Add-Type -AN System.IO.Compression.FileSystem; [IO.Compression.ZipFile]::ExtractToDirectory($src, $unpack)}
|
|
52
|
+
else {Try {$s = New-Object -ComObject Shell.Application; ($s.NameSpace($unpack)).CopyHere(($s.NameSpace($src)).Items(), 0x610)} Finally {[void][Runtime.Interopservices.Marshal]::ReleaseComObject($s)}}
|
|
53
|
+
dir $unpack | cp -dest "$dst/" -force -recurse
|
|
54
|
+
rm $unpack -recurse -force
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
$hash_file = "<%= hash_file %>"
|
|
58
|
+
Decode-Files (Invoke-Input $hash_file) | ConvertTo-Csv -NoTypeInformation
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
$p = $ExecutionContext.SessionState.Path
|
|
2
|
-
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
|
3
|
-
if (Test-Path $path -PathType Leaf) {
|
|
4
|
-
$bytes = [System.convert]::ToBase64String([System.IO.File]::ReadAllBytes($path))
|
|
5
|
-
Write-Host $bytes
|
|
6
|
-
exit 0
|
|
7
|
-
}
|
|
8
|
-
exit 1
|
|
1
|
+
$p = $ExecutionContext.SessionState.Path
|
|
2
|
+
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
|
3
|
+
if (Test-Path $path -PathType Leaf) {
|
|
4
|
+
$bytes = [System.convert]::ToBase64String([System.IO.File]::ReadAllBytes($path))
|
|
5
|
+
Write-Host $bytes
|
|
6
|
+
exit 0
|
|
7
|
+
}
|
|
8
|
+
exit 1
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
$p = $ExecutionContext.SessionState.Path
|
|
2
|
-
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
|
3
|
-
if (Test-Path $path) {
|
|
4
|
-
$true
|
|
5
|
-
exit 0
|
|
6
|
-
}
|
|
7
|
-
else {
|
|
8
|
-
$false
|
|
9
|
-
exit 1
|
|
10
|
-
}
|
|
1
|
+
$p = $ExecutionContext.SessionState.Path
|
|
2
|
+
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
|
3
|
+
if (Test-Path $path) {
|
|
4
|
+
$true
|
|
5
|
+
exit 0
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
$false
|
|
9
|
+
exit 1
|
|
10
|
+
}
|
data/spec/config-example.yml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
auth_type: plaintext
|
|
2
|
-
endpoint: "http://192.168.137.20:5985/wsman"
|
|
3
|
-
options:
|
|
4
|
-
user: vagrant
|
|
1
|
+
auth_type: plaintext
|
|
2
|
+
endpoint: "http://192.168.137.20:5985/wsman"
|
|
3
|
+
options:
|
|
4
|
+
user: vagrant
|
|
5
5
|
pass: vagrant
|
|
@@ -1,218 +1,218 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
require 'pathname'
|
|
3
|
-
|
|
4
|
-
describe WinRM::FS::FileManager do
|
|
5
|
-
let(:dest_dir) { File.join(subject.temp_dir, "winrm_#{rand(2**16)}") }
|
|
6
|
-
let(:temp_upload_dir) { '$env:TEMP/winrm-upload' }
|
|
7
|
-
let(:spec_dir) { File.expand_path(File.dirname(File.dirname(__FILE__))) }
|
|
8
|
-
let(:this_file) { __FILE__ }
|
|
9
|
-
let(:service) { winrm_connection }
|
|
10
|
-
|
|
11
|
-
subject { WinRM::FS::FileManager.new(service) }
|
|
12
|
-
|
|
13
|
-
before(:each) do
|
|
14
|
-
expect(subject.delete(dest_dir)).to be true
|
|
15
|
-
expect(subject.delete(temp_upload_dir)).to be true
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context 'exists?' do
|
|
19
|
-
it 'should exist' do
|
|
20
|
-
expect(subject.exists?('c:/windows')).to be true
|
|
21
|
-
expect(subject.exists?('c:/foobar')).to be false
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context 'create and delete dir' do
|
|
26
|
-
it 'should create the directory recursively' do
|
|
27
|
-
subdir = File.join(dest_dir, 'subdir1', 'subdir2')
|
|
28
|
-
expect(subject.create_dir(subdir)).to be true
|
|
29
|
-
expect(subject.exists?(subdir)).to be true
|
|
30
|
-
expect(subject.create_dir(subdir)).to be true
|
|
31
|
-
expect(subject.delete(subdir)).to be true
|
|
32
|
-
expect(subject.exists?(subdir)).to be false
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context 'temp_dir' do
|
|
37
|
-
it 'should return the remote users temp dir' do
|
|
38
|
-
expect(subject.temp_dir).to match(%r{C:/Users/\S+/AppData/Local/Temp})
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
context 'upload file' do
|
|
43
|
-
let(:dest_file) { File.join(dest_dir, File.basename(this_file)) }
|
|
44
|
-
|
|
45
|
-
before(:each) do
|
|
46
|
-
expect(subject.delete(dest_dir)).to be true
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'should upload the specified file' do
|
|
50
|
-
subject.upload(this_file, dest_file)
|
|
51
|
-
expect(subject).to have_created(dest_file).with_content(this_file)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'should upload to root of the c: drive' do
|
|
55
|
-
subject.upload(this_file, 'c:/winrmtest.rb')
|
|
56
|
-
expect(subject).to have_created('c:/winrmtest.rb').with_content(this_file)
|
|
57
|
-
subject.delete('c:/winrmtest.rb')
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'should upload using relative file path' do
|
|
61
|
-
subject.upload('./spec/integration/file_manager_spec.rb', dest_file)
|
|
62
|
-
expect(subject).to have_created(dest_file).with_content(this_file)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it 'should upload to the specified directory' do
|
|
66
|
-
subject.create_dir(dest_dir)
|
|
67
|
-
subject.upload(this_file, dest_dir)
|
|
68
|
-
expect(subject).to have_created(dest_file).with_content(this_file)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'should treat extensionless target as file if not an existing directory' do
|
|
72
|
-
subject.upload(this_file, dest_dir)
|
|
73
|
-
expect(subject).to have_created(dest_dir).with_content(this_file)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it 'should create extensionless source under target dir if target dir exists' do
|
|
77
|
-
subject.create_dir(dest_dir)
|
|
78
|
-
src_file = File.expand_path('../../Gemfile', File.dirname(__FILE__))
|
|
79
|
-
subject.upload(src_file, dest_dir)
|
|
80
|
-
expect(subject).to have_created(File.join(dest_dir, 'Gemfile')).with_content(src_file)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it 'should upload to the specified directory with env var' do
|
|
84
|
-
subject.upload(this_file, '$env:Temp')
|
|
85
|
-
expected_dest_file = File.join(subject.temp_dir, File.basename(this_file))
|
|
86
|
-
expect(subject).to have_created(expected_dest_file).with_content(this_file)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'should upload to Program Files sub dir' do
|
|
90
|
-
subject.create_dir('$env:ProgramFiles/foo')
|
|
91
|
-
subject.upload(this_file, '$env:ProgramFiles/foo')
|
|
92
|
-
expect(subject).to have_created('c:/Program Files/foo/file_manager_spec.rb') \
|
|
93
|
-
.with_content(this_file)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it 'should upload to the specified nested directory' do
|
|
97
|
-
dest_sub_dir = File.join(dest_dir, 'subdir')
|
|
98
|
-
subject.create_dir(dest_sub_dir)
|
|
99
|
-
dest_sub_dir_file = File.join(dest_sub_dir, File.basename(this_file))
|
|
100
|
-
subject.upload(this_file, dest_sub_dir)
|
|
101
|
-
expect(subject).to have_created(dest_sub_dir_file).with_content(this_file)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it 'yields progress data' do
|
|
105
|
-
block_called = false
|
|
106
|
-
total_bytes_copied = 0
|
|
107
|
-
total = subject.upload(this_file, dest_file) do \
|
|
108
|
-
|bytes_copied, total_bytes, local_path, remote_path|
|
|
109
|
-
expect(total_bytes).to be > 0
|
|
110
|
-
total_bytes_copied = bytes_copied
|
|
111
|
-
expect(local_path).to eq(this_file)
|
|
112
|
-
expect(remote_path).to eq(dest_file)
|
|
113
|
-
block_called = true
|
|
114
|
-
end
|
|
115
|
-
expect(total_bytes_copied).to eq(total)
|
|
116
|
-
expect(block_called).to be true
|
|
117
|
-
expect(total).to be > 0
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
it 'should not upload when content matches' do
|
|
121
|
-
subject.upload(this_file, dest_dir)
|
|
122
|
-
bytes_uploaded = subject.upload(this_file, dest_dir)
|
|
123
|
-
expect(bytes_uploaded).to eq 0
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
it 'should upload when content differs' do
|
|
127
|
-
matchers_file = File.join(spec_dir, 'matchers.rb')
|
|
128
|
-
subject.upload(matchers_file, dest_file)
|
|
129
|
-
bytes_uploaded = subject.upload(this_file, dest_file)
|
|
130
|
-
expect(bytes_uploaded).to be > 0
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
it 'raises WinRMUploadError when a bad source path is specified' do
|
|
134
|
-
expect { subject.upload('c:/some/non-existant/path/foo', dest_file) }.to raise_error
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
context 'upload empty file' do
|
|
139
|
-
let(:empty_src_file) { Tempfile.new('empty') }
|
|
140
|
-
let(:dest_file) { File.join(dest_dir, 'emptyfile.txt') }
|
|
141
|
-
|
|
142
|
-
it 'creates a new empty file' do
|
|
143
|
-
expect(subject.upload(empty_src_file.path, dest_file)).to be 0
|
|
144
|
-
expect(subject).to have_created(dest_file).with_content('')
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it 'overwrites an existing file' do
|
|
148
|
-
expect(subject.upload(this_file, dest_file)).to be > 0
|
|
149
|
-
expect(subject.upload(empty_src_file.path, dest_file)).to be 0
|
|
150
|
-
expect(subject).to have_created(dest_file).with_content('')
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
context 'upload directory' do
|
|
155
|
-
let(:root_dir) { File.expand_path('../../', File.dirname(__FILE__)) }
|
|
156
|
-
let(:winrm_fs_dir) { File.join(root_dir, 'lib/winrm-fs') }
|
|
157
|
-
let(:core_dir) { File.join(root_dir, 'lib/winrm-fs/core') }
|
|
158
|
-
let(:scripts_dir) { File.join(root_dir, 'lib/winrm-fs/scripts') }
|
|
159
|
-
|
|
160
|
-
it 'copies the directory contents recursively when directory does not exist' do
|
|
161
|
-
bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
|
|
162
|
-
expect(bytes_uploaded).to be > 0
|
|
163
|
-
|
|
164
|
-
Dir.glob(winrm_fs_dir + '/**/*.rb').each do |host_file|
|
|
165
|
-
host_file_rel = Pathname.new(host_file).relative_path_from(
|
|
166
|
-
Pathname.new(winrm_fs_dir)
|
|
167
|
-
).to_s
|
|
168
|
-
remote_file = File.join(dest_dir, host_file_rel)
|
|
169
|
-
expect(subject).to have_created(remote_file).with_content(host_file)
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
it 'copies the directory recursively when directory does exist' do
|
|
174
|
-
subject.create_dir(dest_dir)
|
|
175
|
-
bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
|
|
176
|
-
expect(bytes_uploaded).to be > 0
|
|
177
|
-
|
|
178
|
-
Dir.glob(winrm_fs_dir + '/**/*.rb').each do |host_file|
|
|
179
|
-
host_file_rel = Pathname.new(host_file).relative_path_from(
|
|
180
|
-
Pathname.new(winrm_fs_dir).dirname
|
|
181
|
-
).to_s
|
|
182
|
-
remote_file = File.join(dest_dir, host_file_rel)
|
|
183
|
-
expect(subject).to have_created(remote_file).with_content(host_file)
|
|
184
|
-
end
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
it 'does not copy the directory when content is the same' do
|
|
188
|
-
subject.upload(winrm_fs_dir, dest_dir)
|
|
189
|
-
bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
|
|
190
|
-
expect(bytes_uploaded).to eq 0
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
it 'unzips the directory when cached content is the same' do
|
|
194
|
-
subject.upload(winrm_fs_dir, dest_dir)
|
|
195
|
-
subject.delete(dest_dir)
|
|
196
|
-
expect(subject.exists?(dest_dir)).to be false
|
|
197
|
-
subject.upload(winrm_fs_dir, dest_dir)
|
|
198
|
-
expect(subject.exists?(dest_dir)).to be true
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
it 'unzips multiple directories when cached content is the same for all' do
|
|
202
|
-
subject.create_dir(dest_dir)
|
|
203
|
-
subject.upload([core_dir, scripts_dir], dest_dir)
|
|
204
|
-
subject.delete(dest_dir)
|
|
205
|
-
expect(subject.exists?(dest_dir)).to be false
|
|
206
|
-
subject.create_dir(dest_dir)
|
|
207
|
-
subject.upload([core_dir, scripts_dir], dest_dir)
|
|
208
|
-
expect(subject.exists?(File.join(dest_dir, 'core'))).to be true
|
|
209
|
-
expect(subject.exists?(File.join(dest_dir, 'scripts'))).to be true
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
it 'copies the directory when content differs' do
|
|
213
|
-
subject.upload(winrm_fs_dir, dest_dir)
|
|
214
|
-
bytes_uploaded = subject.upload(core_dir, dest_dir)
|
|
215
|
-
expect(bytes_uploaded).to be > 0
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
end
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
require 'pathname'
|
|
3
|
+
|
|
4
|
+
describe WinRM::FS::FileManager do
|
|
5
|
+
let(:dest_dir) { File.join(subject.temp_dir, "winrm_#{rand(2**16)}") }
|
|
6
|
+
let(:temp_upload_dir) { '$env:TEMP/winrm-upload' }
|
|
7
|
+
let(:spec_dir) { File.expand_path(File.dirname(File.dirname(__FILE__))) }
|
|
8
|
+
let(:this_file) { __FILE__ }
|
|
9
|
+
let(:service) { winrm_connection }
|
|
10
|
+
|
|
11
|
+
subject { WinRM::FS::FileManager.new(service) }
|
|
12
|
+
|
|
13
|
+
before(:each) do
|
|
14
|
+
expect(subject.delete(dest_dir)).to be true
|
|
15
|
+
expect(subject.delete(temp_upload_dir)).to be true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context 'exists?' do
|
|
19
|
+
it 'should exist' do
|
|
20
|
+
expect(subject.exists?('c:/windows')).to be true
|
|
21
|
+
expect(subject.exists?('c:/foobar')).to be false
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context 'create and delete dir' do
|
|
26
|
+
it 'should create the directory recursively' do
|
|
27
|
+
subdir = File.join(dest_dir, 'subdir1', 'subdir2')
|
|
28
|
+
expect(subject.create_dir(subdir)).to be true
|
|
29
|
+
expect(subject.exists?(subdir)).to be true
|
|
30
|
+
expect(subject.create_dir(subdir)).to be true
|
|
31
|
+
expect(subject.delete(subdir)).to be true
|
|
32
|
+
expect(subject.exists?(subdir)).to be false
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'temp_dir' do
|
|
37
|
+
it 'should return the remote users temp dir' do
|
|
38
|
+
expect(subject.temp_dir).to match(%r{C:/Users/\S+/AppData/Local/Temp})
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context 'upload file' do
|
|
43
|
+
let(:dest_file) { File.join(dest_dir, File.basename(this_file)) }
|
|
44
|
+
|
|
45
|
+
before(:each) do
|
|
46
|
+
expect(subject.delete(dest_dir)).to be true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'should upload the specified file' do
|
|
50
|
+
subject.upload(this_file, dest_file)
|
|
51
|
+
expect(subject).to have_created(dest_file).with_content(this_file)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'should upload to root of the c: drive' do
|
|
55
|
+
subject.upload(this_file, 'c:/winrmtest.rb')
|
|
56
|
+
expect(subject).to have_created('c:/winrmtest.rb').with_content(this_file)
|
|
57
|
+
subject.delete('c:/winrmtest.rb')
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'should upload using relative file path' do
|
|
61
|
+
subject.upload('./spec/integration/file_manager_spec.rb', dest_file)
|
|
62
|
+
expect(subject).to have_created(dest_file).with_content(this_file)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'should upload to the specified directory' do
|
|
66
|
+
subject.create_dir(dest_dir)
|
|
67
|
+
subject.upload(this_file, dest_dir)
|
|
68
|
+
expect(subject).to have_created(dest_file).with_content(this_file)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'should treat extensionless target as file if not an existing directory' do
|
|
72
|
+
subject.upload(this_file, dest_dir)
|
|
73
|
+
expect(subject).to have_created(dest_dir).with_content(this_file)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'should create extensionless source under target dir if target dir exists' do
|
|
77
|
+
subject.create_dir(dest_dir)
|
|
78
|
+
src_file = File.expand_path('../../Gemfile', File.dirname(__FILE__))
|
|
79
|
+
subject.upload(src_file, dest_dir)
|
|
80
|
+
expect(subject).to have_created(File.join(dest_dir, 'Gemfile')).with_content(src_file)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'should upload to the specified directory with env var' do
|
|
84
|
+
subject.upload(this_file, '$env:Temp')
|
|
85
|
+
expected_dest_file = File.join(subject.temp_dir, File.basename(this_file))
|
|
86
|
+
expect(subject).to have_created(expected_dest_file).with_content(this_file)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it 'should upload to Program Files sub dir' do
|
|
90
|
+
subject.create_dir('$env:ProgramFiles/foo')
|
|
91
|
+
subject.upload(this_file, '$env:ProgramFiles/foo')
|
|
92
|
+
expect(subject).to have_created('c:/Program Files/foo/file_manager_spec.rb') \
|
|
93
|
+
.with_content(this_file)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'should upload to the specified nested directory' do
|
|
97
|
+
dest_sub_dir = File.join(dest_dir, 'subdir')
|
|
98
|
+
subject.create_dir(dest_sub_dir)
|
|
99
|
+
dest_sub_dir_file = File.join(dest_sub_dir, File.basename(this_file))
|
|
100
|
+
subject.upload(this_file, dest_sub_dir)
|
|
101
|
+
expect(subject).to have_created(dest_sub_dir_file).with_content(this_file)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'yields progress data' do
|
|
105
|
+
block_called = false
|
|
106
|
+
total_bytes_copied = 0
|
|
107
|
+
total = subject.upload(this_file, dest_file) do \
|
|
108
|
+
|bytes_copied, total_bytes, local_path, remote_path|
|
|
109
|
+
expect(total_bytes).to be > 0
|
|
110
|
+
total_bytes_copied = bytes_copied
|
|
111
|
+
expect(local_path).to eq(this_file)
|
|
112
|
+
expect(remote_path).to eq(dest_file)
|
|
113
|
+
block_called = true
|
|
114
|
+
end
|
|
115
|
+
expect(total_bytes_copied).to eq(total)
|
|
116
|
+
expect(block_called).to be true
|
|
117
|
+
expect(total).to be > 0
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'should not upload when content matches' do
|
|
121
|
+
subject.upload(this_file, dest_dir)
|
|
122
|
+
bytes_uploaded = subject.upload(this_file, dest_dir)
|
|
123
|
+
expect(bytes_uploaded).to eq 0
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'should upload when content differs' do
|
|
127
|
+
matchers_file = File.join(spec_dir, 'matchers.rb')
|
|
128
|
+
subject.upload(matchers_file, dest_file)
|
|
129
|
+
bytes_uploaded = subject.upload(this_file, dest_file)
|
|
130
|
+
expect(bytes_uploaded).to be > 0
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it 'raises WinRMUploadError when a bad source path is specified' do
|
|
134
|
+
expect { subject.upload('c:/some/non-existant/path/foo', dest_file) }.to raise_error
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
context 'upload empty file' do
|
|
139
|
+
let(:empty_src_file) { Tempfile.new('empty') }
|
|
140
|
+
let(:dest_file) { File.join(dest_dir, 'emptyfile.txt') }
|
|
141
|
+
|
|
142
|
+
it 'creates a new empty file' do
|
|
143
|
+
expect(subject.upload(empty_src_file.path, dest_file)).to be 0
|
|
144
|
+
expect(subject).to have_created(dest_file).with_content('')
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'overwrites an existing file' do
|
|
148
|
+
expect(subject.upload(this_file, dest_file)).to be > 0
|
|
149
|
+
expect(subject.upload(empty_src_file.path, dest_file)).to be 0
|
|
150
|
+
expect(subject).to have_created(dest_file).with_content('')
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
context 'upload directory' do
|
|
155
|
+
let(:root_dir) { File.expand_path('../../', File.dirname(__FILE__)) }
|
|
156
|
+
let(:winrm_fs_dir) { File.join(root_dir, 'lib/winrm-fs') }
|
|
157
|
+
let(:core_dir) { File.join(root_dir, 'lib/winrm-fs/core') }
|
|
158
|
+
let(:scripts_dir) { File.join(root_dir, 'lib/winrm-fs/scripts') }
|
|
159
|
+
|
|
160
|
+
it 'copies the directory contents recursively when directory does not exist' do
|
|
161
|
+
bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
|
|
162
|
+
expect(bytes_uploaded).to be > 0
|
|
163
|
+
|
|
164
|
+
Dir.glob(winrm_fs_dir + '/**/*.rb').each do |host_file|
|
|
165
|
+
host_file_rel = Pathname.new(host_file).relative_path_from(
|
|
166
|
+
Pathname.new(winrm_fs_dir)
|
|
167
|
+
).to_s
|
|
168
|
+
remote_file = File.join(dest_dir, host_file_rel)
|
|
169
|
+
expect(subject).to have_created(remote_file).with_content(host_file)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it 'copies the directory recursively when directory does exist' do
|
|
174
|
+
subject.create_dir(dest_dir)
|
|
175
|
+
bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
|
|
176
|
+
expect(bytes_uploaded).to be > 0
|
|
177
|
+
|
|
178
|
+
Dir.glob(winrm_fs_dir + '/**/*.rb').each do |host_file|
|
|
179
|
+
host_file_rel = Pathname.new(host_file).relative_path_from(
|
|
180
|
+
Pathname.new(winrm_fs_dir).dirname
|
|
181
|
+
).to_s
|
|
182
|
+
remote_file = File.join(dest_dir, host_file_rel)
|
|
183
|
+
expect(subject).to have_created(remote_file).with_content(host_file)
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it 'does not copy the directory when content is the same' do
|
|
188
|
+
subject.upload(winrm_fs_dir, dest_dir)
|
|
189
|
+
bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
|
|
190
|
+
expect(bytes_uploaded).to eq 0
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
it 'unzips the directory when cached content is the same' do
|
|
194
|
+
subject.upload(winrm_fs_dir, dest_dir)
|
|
195
|
+
subject.delete(dest_dir)
|
|
196
|
+
expect(subject.exists?(dest_dir)).to be false
|
|
197
|
+
subject.upload(winrm_fs_dir, dest_dir)
|
|
198
|
+
expect(subject.exists?(dest_dir)).to be true
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it 'unzips multiple directories when cached content is the same for all' do
|
|
202
|
+
subject.create_dir(dest_dir)
|
|
203
|
+
subject.upload([core_dir, scripts_dir], dest_dir)
|
|
204
|
+
subject.delete(dest_dir)
|
|
205
|
+
expect(subject.exists?(dest_dir)).to be false
|
|
206
|
+
subject.create_dir(dest_dir)
|
|
207
|
+
subject.upload([core_dir, scripts_dir], dest_dir)
|
|
208
|
+
expect(subject.exists?(File.join(dest_dir, 'core'))).to be true
|
|
209
|
+
expect(subject.exists?(File.join(dest_dir, 'scripts'))).to be true
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it 'copies the directory when content differs' do
|
|
213
|
+
subject.upload(winrm_fs_dir, dest_dir)
|
|
214
|
+
bytes_uploaded = subject.upload(core_dir, dest_dir)
|
|
215
|
+
expect(bytes_uploaded).to be > 0
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|