winrm-fs 1.3.0 → 1.3.1
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/VERSION +1 -1
- data/changelog.md +3 -0
- data/lib/winrm-fs/core/file_transporter.rb +1 -0
- data/lib/winrm-fs/core/tmp_zip.rb +1 -0
- data/lib/winrm-fs/file_manager.rb +38 -10
- data/lib/winrm-fs/scripts/download.ps1.erb +9 -3
- data/spec/integration/file_manager_spec.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4af545258de812839e8ff58480b26128f23b9335207bf62eafed48ef9220d0a
|
4
|
+
data.tar.gz: b77310f1de5e0d6a8eb1cd2df45948ac4b848684c4646d25e75045cd8967a235
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ba78d2418a7cab543ac316dced1053c935a07c56b052053f84dfaf8d676dd4600dffe51e5c040204e2ba6f83131fd90180513725135849e8eacda72e23e49bb
|
7
|
+
data.tar.gz: fbb8b91d4283677593d68391d1be8e5d168230a1d82cfecbf3cf06c9a7dfa55adf4bac02d53e39c78c9a83a7a408abb0d0235d8c71b223f99581280bb0451e8e
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.1
|
data/changelog.md
CHANGED
@@ -59,16 +59,44 @@ module WinRM
|
|
59
59
|
# Downloads the specified remote file to the specified local path
|
60
60
|
# @param [String] The full path on the remote machine
|
61
61
|
# @param [String] The full path to write the file to locally
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
return
|
68
|
-
|
69
|
-
|
62
|
+
# rubocop:disable Metrics/MethodLength
|
63
|
+
def download(remote_path, local_path, chunk_size = 1024 * 1024, first = true)
|
64
|
+
@logger.debug("downloading: #{remote_path} -> #{local_path} #{chunk_size}")
|
65
|
+
index = 0
|
66
|
+
output = _output_from_file(remote_path, chunk_size, index)
|
67
|
+
return download_dir(remote_path, local_path, chunk_size, first) if output.exitcode == 2
|
68
|
+
|
69
|
+
return false if output.exitcode >= 1
|
70
|
+
|
71
|
+
File.open(local_path, 'wb') do |fd|
|
72
|
+
out = _write_file(fd, output)
|
73
|
+
index += out.length
|
74
|
+
until out.empty?
|
75
|
+
output = _output_from_file(remote_path, chunk_size, index)
|
76
|
+
return false if output.exitcode >= 1
|
77
|
+
|
78
|
+
out = _write_file(fd, output)
|
79
|
+
index += out.length
|
80
|
+
end
|
81
|
+
end
|
70
82
|
true
|
71
83
|
end
|
84
|
+
# rubocop:enable Metrics/MethodLength
|
85
|
+
|
86
|
+
def _output_from_file(remote_path, chunk_size, index)
|
87
|
+
script = WinRM::FS::Scripts.render('download', path: remote_path, chunk_size: chunk_size, index: index)
|
88
|
+
@connection.shell(:powershell) { |e| e.run(script) }
|
89
|
+
end
|
90
|
+
|
91
|
+
def _write_file(tofd, output)
|
92
|
+
contents = output.stdout.gsub('\n\r', '')
|
93
|
+
out = Base64.decode64(contents)
|
94
|
+
out = out[0, out.length - 1] if out.end_with? "\x00"
|
95
|
+
return out if out.empty?
|
96
|
+
|
97
|
+
tofd.write(out)
|
98
|
+
out
|
99
|
+
end
|
72
100
|
|
73
101
|
# Checks to see if the given path exists on the target file system.
|
74
102
|
# @param [String] The full path to the directory or file
|
@@ -115,12 +143,12 @@ module WinRM
|
|
115
143
|
|
116
144
|
private
|
117
145
|
|
118
|
-
def download_dir(remote_path, local_path, first)
|
146
|
+
def download_dir(remote_path, local_path, chunk_size, first)
|
119
147
|
local_path = File.join(local_path, File.basename(remote_path.to_s)) if first
|
120
148
|
FileUtils.mkdir_p(local_path) unless File.directory?(local_path)
|
121
149
|
command = "Get-ChildItem #{remote_path} | Select-Object Name"
|
122
150
|
@connection.shell(:powershell) { |e| e.run(command) }.stdout.strip.split(/\n/).drop(2).each do |file|
|
123
|
-
download(File.join(remote_path.to_s, file.strip), File.join(local_path, file.strip),
|
151
|
+
download(File.join(remote_path.to_s, file.strip), File.join(local_path, file.strip), chunk_size, false)
|
124
152
|
end
|
125
153
|
end
|
126
154
|
end
|
@@ -1,11 +1,17 @@
|
|
1
1
|
$p = $ExecutionContext.SessionState.Path
|
2
2
|
$path = $p.GetUnresolvedProviderPathFromPSPath("<%= path %>")
|
3
|
-
|
4
|
-
|
3
|
+
$index = <%= index %>
|
4
|
+
$chunkSize = <%= chunk_size %>
|
5
|
+
if (Test-Path $path -PathType Leaf) {
|
6
|
+
$file = [System.IO.File]::OpenRead($path)
|
7
|
+
$seekedTo = $file.Seek($index, [System.IO.SeekOrigin]::Begin)
|
8
|
+
$chunk = New-Object byte[] $chunkSize
|
9
|
+
$bytesRead = $file.Read($chunk, 0, $chunkSize)
|
10
|
+
$bytes = [System.convert]::ToBase64String($chunk[0..$bytesRead])
|
5
11
|
Write-Host $bytes
|
6
12
|
exit 0
|
7
13
|
}
|
8
14
|
ElseIf (Test-Path $path -PathType Container) {
|
9
|
-
exit
|
15
|
+
exit 2
|
10
16
|
}
|
11
17
|
exit 1
|
@@ -58,6 +58,24 @@ describe WinRM::FS::FileManager do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
context 'download file chunked' do
|
62
|
+
let(:download_dir) { File.join(spec_dir, 'temp') }
|
63
|
+
let(:dest_file) { Pathname.new(File.join(dest_dir, File.basename(this_file))) }
|
64
|
+
let(:download_file) { Pathname.new(File.join(download_dir, File.basename(this_file))) }
|
65
|
+
|
66
|
+
before(:each) do
|
67
|
+
expect(subject.delete(dest_dir)).to be true
|
68
|
+
FileUtils.rm_rf(Dir.glob("#{download_dir}/*"))
|
69
|
+
FileUtils.mkdir_p(download_dir)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should download the specified file in 1000 byte chunks' do
|
73
|
+
subject.upload(this_file, dest_file)
|
74
|
+
subject.download(dest_file, download_file, 1000)
|
75
|
+
expect(File.open(download_file).read).to eq(File.open(this_file).read)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
61
79
|
context 'download directory' do
|
62
80
|
let(:download_dir) { File.join(spec_dir, 'temp') }
|
63
81
|
let(:dest_file) { Pathname.new(File.join(dest_dir, File.basename(this_file))) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winrm-fs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shawn Neal
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: erubis
|