winrm-fs 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 959e097cf30b655d2e95f26e6ec808e9f99b5606
4
- data.tar.gz: cff6d9bc348a2ac845ed9c4ae16890ea55ce509e
3
+ metadata.gz: 73ccc66738cd3d2154cdebcaf723ce05f8856cc9
4
+ data.tar.gz: b1495a0c00c6dd45dd1d590a6af8cef13217fe0a
5
5
  SHA512:
6
- metadata.gz: 35047acdb0750d38697dd484dfcdbaa48972471b653a07f222cf7490746e913acb2da62dc47055c55cd7997158ca311d732e5b4cfcd933a5a9257706735087f7
7
- data.tar.gz: dd3abe06a552686fb4cea084a056898f6012b2acceb9202226f5568f59d6cab1da0d839e25d7ae9328d5f2c7ae93aecf87d78be08428059b8dabc50cee616483
6
+ metadata.gz: 5bb6b796cc8b459f5f8c42b72df1e05c65978289d237d0aaa4d4b871473caac73324d91da73ac3fa13a0568b740e048195b72e29298e6241b96c26c621e73e59
7
+ data.tar.gz: 186861cd7b45f773f350b781e2f2563f820e7db3ae01696fa011e8856ec2b1caabe1e5d36729c0bf93d0ed5dff6eda1480e63b876aacb4b913481fd3422e54f3
data/README.md CHANGED
@@ -10,11 +10,15 @@ require 'winrm-fs'
10
10
 
11
11
  service = WinRM::WinRMWebService.new(...
12
12
  file_manager = WinRM::FS::FileManager.new(service)
13
- file_manager.upload('c:/dev/my_dir', '$env:AppData')
14
- ```
15
- Or an array of several files and/or directories can be included:
16
- ```ruby
17
- file_manager.upload(['c:/dev/file1.txt','c:/dev/dir1'], '$env:AppData')
13
+
14
+ # upload file.txt from the current working directory
15
+ file_manager.upload('file.txt', 'c:/file.txt')
16
+
17
+ # upload the entire contents of my_dir to c:/foo/my_dir
18
+ file_manager.upload('/Users/sneal/my_dir', 'c:/foo/my_dir')
19
+
20
+ # upload the entire directory contents of foo to c:\program files\bar
21
+ file_manager.upload('/Users/sneal/foo', '$env:ProgramFiles/bar')
18
22
  ```
19
23
 
20
24
  ### Handling progress events
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/benchmark.rb ADDED
@@ -0,0 +1,20 @@
1
+ # encoding: UTF-8
2
+ require 'winrm-fs'
3
+ require 'benchmark'
4
+
5
+ def files
6
+ # This is a fairly short list of small files, may also want a benchmark with larger files
7
+ `git ls-files`.lines.map(&:strip)
8
+ end
9
+
10
+ def create_zip(factory, file)
11
+ WinRM::FS::Core::TempZipFile.new(Dir.pwd, zip_file: file, via: factory, X: true) do | temp_zip |
12
+ temp_zip.add(*files)
13
+ end
14
+ end
15
+
16
+ Benchmark.bm do | benchmark |
17
+ benchmark.report('zip cmd') { `git ls-files | zip zip_command.zip -X --names-stdin` }
18
+ benchmark.report('shell') { create_zip(:shell, 'shell.zip') }
19
+ benchmark.report('ruby') { create_zip(:rubyzip, 'ruby.zip') }
20
+ end
data/bin/rwinrmcp CHANGED
@@ -36,7 +36,7 @@ def parse_options
36
36
  fail "Cannot find source file: #{options[:source_path]}" unless \
37
37
  File.exist?(options[:source_path])
38
38
 
39
- m = /^(?<user>\w+)@{1}(?<host>[a-zA-Z0-9\.]+)(?<port>:[0-9]+)?:{1}(?<file>.+)/.match(ARGV[1])
39
+ m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?:{1}(?<file>.+)/i.match(ARGV[1])
40
40
  fail "#{ARGV[1]} is an invalid destination" unless m
41
41
  options[:user] = m[:user]
42
42
  options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
data/changelog.md CHANGED
@@ -1 +1,10 @@
1
- 0.1.0 - Initial alpha quality release
1
+ # WinRM-fs Gem Changelog
2
+
3
+ # 0.2.0
4
+ - Redesigned temp zip file creation system
5
+ - Fixed lots of small edge case issues especially with directory uploads
6
+ - Simplified file manager upload method API to take only a single source file or directory
7
+ - Expanded acceptable username and hostnames for rwinrmcp
8
+
9
+ # 0.1.0
10
+ - Initial alpha quality release
data/lib/winrm-fs.rb CHANGED
@@ -16,6 +16,7 @@
16
16
 
17
17
  require 'winrm'
18
18
  require 'logger'
19
+ require 'pathname'
19
20
  require_relative 'winrm-fs/exceptions'
20
21
  require_relative 'winrm-fs/file_manager'
21
22
 
@@ -14,72 +14,163 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
+ require 'English'
17
18
  require 'zip'
19
+ require 'fileutils'
20
+ require 'pathname'
18
21
 
19
22
  module WinRM
20
23
  module FS
21
24
  module Core
22
25
  # Temporary zip file on the local system
23
26
  class TempZipFile
24
- attr_reader :path
27
+ attr_reader :zip_file, :path, :paths, :basedir, :options
25
28
 
26
- def initialize
27
- @logger = Logging.logger[self]
28
- @zip_file = Tempfile.new(['winrm_upload', '.zip'])
29
- @zip_file.close
30
- @path = @zip_file.path
29
+ # Creates a new local temporary zip file
30
+ # @param [String] Base directory to use when expanding out files passed to add
31
+ # @param [Hash] Options: zip_file, via, recurse_paths
32
+ def initialize(basedir = Dir.pwd, options = {})
33
+ @basedir = Pathname.new(basedir)
34
+ @options = options
35
+ @zip_file = options[:zip_file] || Tempfile.new(['winrm_upload', '.zip'])
36
+ @path = Pathname.new(@zip_file)
31
37
  end
32
38
 
33
39
  # Adds a file or directory to the temporary zip file
34
- # @param [String] Directory or file path to add into zip
35
- def add(path)
36
- if File.directory?(path)
37
- add_directory(path)
38
- elsif File.file?(path)
39
- add_file(path)
40
- else
41
- fail "#{path} doesn't exist"
40
+ # @param [String] Directory or file path relative to basedir to add into zip
41
+ def add(*new_paths)
42
+ new_paths.each do | path |
43
+ absolute_path = File.expand_path(path, basedir)
44
+ fail "#{path} must exist relative to #{basedir}" unless File.exist? absolute_path
45
+ paths << Pathname.new(absolute_path).relative_path_from(basedir)
42
46
  end
43
47
  end
44
48
 
45
- # Adds all files in the specified directory recursively into the zip file
46
- # @param [String] Directory to add into zip
47
- def add_directory(dir)
48
- fail "#{dir} isn't a directory" unless File.directory?(dir)
49
- glob = File.join(dir, '**/*')
50
- Dir.glob(glob).each do |file|
51
- add_file_entry(file, dir)
52
- end
53
- end
54
-
55
- def add_file(file)
56
- fail "#{file} isn't a file" unless File.file?(file)
57
- add_file_entry(file, File.dirname(file))
49
+ def paths
50
+ @paths ||= []
58
51
  end
59
52
 
60
53
  def delete
61
54
  @zip_file.delete
62
55
  end
63
56
 
57
+ def build
58
+ factory.new(self).build
59
+ end
60
+
61
+ private
62
+
63
+ def factory
64
+ @factory ||= case options[:via]
65
+ when nil, :rubyzip
66
+ RubyZipFactory
67
+ when :shell
68
+ ShellZipFactory
69
+ else
70
+ fail "Unknown zip factory: #{factory}"
71
+ end
72
+ end
73
+ end
74
+
75
+ # Creates a zip file by shelling out to the zip command
76
+ class ShellZipFactory
77
+ attr_reader :zip_definition, :basedir, :zip_file, :paths, :options
78
+
79
+ def initialize(zip_definition)
80
+ @zip_definition = zip_definition
81
+ @zip_file = zip_definition.zip_file
82
+ @basedir = zip_definition.basedir
83
+ @paths = zip_definition.paths
84
+ @options = build_options.push('--names-stdin').join(' ')
85
+ end
86
+
87
+ def build
88
+ Dir.chdir(basedir) do
89
+ # zip doesn't like the file that already exists
90
+ output = `zip #{zip_definition.path}.tmp #{options} < #{write_file_list.path}`
91
+ fail "zip command failed: #{output}" unless $CHILD_STATUS.success?
92
+
93
+ FileUtils.mv("#{zip_definition.path}.tmp", "#{zip_definition.path}")
94
+ end
95
+ end
96
+
64
97
  private
65
98
 
66
- def add_file_entry(file, base_dir)
67
- base_dir = "#{base_dir}/" unless base_dir.end_with?('/')
68
- file_entry_path = file[base_dir.length..-1]
69
- write_zip_entry(file, file_entry_path)
99
+ def write_file_list
100
+ file_list = Tempfile.new('file_list')
101
+ file_list.puts paths.join("\n")
102
+ file_list.close
103
+ file_list
70
104
  end
71
105
 
72
- def write_zip_entry(file, file_entry_path)
73
- @logger.debug("adding zip entry: #{file_entry_path}")
74
- Zip::File.open(@path, 'w') do |zipfile|
75
- entry = new_zip_entry(file_entry_path)
76
- zipfile.add(entry, file)
106
+ def build_options
107
+ zip_definition.options.map do | key, value |
108
+ prefix = key.length > 1 ? '--' : '-'
109
+ if value == true
110
+ "#{prefix}#{key}"
111
+ else
112
+ "#{prefix}#{key} #{value}"
113
+ end
77
114
  end
78
115
  end
116
+ end
117
+
118
+ # Creates a zip file using RubyZip
119
+ class RubyZipFactory
120
+ attr_reader :zip_definition, :basedir
121
+
122
+ def initialize(zip_definition)
123
+ @zip_definition = zip_definition
124
+ @basedir = zip_definition.basedir
125
+ @zip = Zip::File.open(zip_definition.path, Zip::File::CREATE)
126
+ end
127
+
128
+ def build
129
+ @zip_definition.paths.each do | path |
130
+ absolute_path = File.expand_path(path, basedir)
131
+ fail "#{path} doesn't exist" unless File.exist? absolute_path
132
+
133
+ if File.directory?(absolute_path)
134
+ add_directory(path)
135
+ else
136
+ add_file(path)
137
+ end
138
+ end
139
+ close
140
+ end
141
+
142
+ def close
143
+ @zip.close if @zip
144
+ end
145
+
146
+ private
147
+
148
+ # Adds all files in the specified directory recursively into the zip file
149
+ # @param [String] Directory to add into zip
150
+ def add_directory(dir)
151
+ glob_pattern = '*'
152
+ glob_pattern = '**/*' if zip_definition.options[:recurse_paths]
153
+
154
+ glob = File.join(basedir, dir, glob_pattern)
155
+ Dir.glob(glob).each do |file|
156
+ add_file(file)
157
+ end
158
+ end
159
+
160
+ def add_file(file)
161
+ write_zip_entry(file, basedir)
162
+ end
163
+
164
+ def write_zip_entry(file, _file_entry_path)
165
+ absolute_file = File.expand_path(file, basedir)
166
+ relative_file = Pathname.new(absolute_file).relative_path_from(basedir).to_s
167
+ entry = new_zip_entry(relative_file)
168
+ @zip.add(entry, absolute_file)
169
+ end
79
170
 
80
171
  def new_zip_entry(file_entry_path)
81
172
  Zip::Entry.new(
82
- @path,
173
+ @zip,
83
174
  file_entry_path,
84
175
  nil,
85
176
  nil,
@@ -42,8 +42,8 @@ module WinRM
42
42
  end
43
43
  end
44
44
 
45
- def upload_directory(local_paths, remote_path)
46
- with_local_zip(local_paths) do |local_zip|
45
+ def upload_directory(local_path, remote_path)
46
+ with_local_zip(local_path) do |local_zip|
47
47
  temp_path = temp_file_path(local_zip.path)
48
48
  with_command_executor do |cmd_executor|
49
49
  return 0 unless out_of_date?(cmd_executor, local_zip.path, temp_path)
@@ -74,8 +74,8 @@ module WinRM
74
74
  cmd_executor.close
75
75
  end
76
76
 
77
- def with_local_zip(local_paths)
78
- local_zip = create_temp_zip_file(local_paths)
77
+ def with_local_zip(local_path)
78
+ local_zip = create_temp_zip_file(local_path)
79
79
  yield local_zip
80
80
  ensure
81
81
  local_zip.delete if local_zip
@@ -107,10 +107,11 @@ module WinRM
107
107
  "$env:TEMP/winrm-upload/#{local_checksum(local_path)}#{ext}"
108
108
  end
109
109
 
110
- def create_temp_zip_file(local_paths)
111
- temp_zip = WinRM::FS::Core::TempZipFile.new
112
- local_paths.each { |p| temp_zip.add(p) }
113
- temp_zip
110
+ def create_temp_zip_file(local_path)
111
+ zip = WinRM::FS::Core::TempZipFile.new(local_path, recurse_paths: true)
112
+ zip.add(local_path)
113
+ zip.build
114
+ zip
114
115
  end
115
116
  end
116
117
  end
@@ -86,16 +86,16 @@ module WinRM
86
86
  end
87
87
 
88
88
  # Upload one or more local files and directories to a remote directory
89
- # @example copy a single directory to a winrm endpoint
89
+ # @example copy a single file to a winrm endpoint
90
90
  #
91
- # file_manager.upload('c:/dev/my_dir', '$env:AppData')
91
+ # file_manager.upload('/Users/sneal/myfile.txt', 'c:/foo/myfile.txt')
92
92
  #
93
- # @example copy several paths to the winrm endpoint
93
+ # @example copy a single directory to a winrm endpoint
94
94
  #
95
- # file_manager.upload(['c:/dev/file1.txt','c:/dev/dir1'], '$env:AppData')
95
+ # file_manager.upload('c:/dev/my_dir', '$env:AppData')
96
96
  #
97
- # @param [Array<String>] One or more paths that will be copied to the remote path.
98
- # These can be files or directories to be deeply copied
97
+ # @param [String] A path to a local directory or file that will be copied
98
+ # to the remote Windows box.
99
99
  # @param [String] The target directory or file
100
100
  # This path may contain powershell style environment variables
101
101
  # @yieldparam [Fixnum] Number of bytes copied in current payload sent to the winrm endpoint
@@ -103,21 +103,16 @@ module WinRM
103
103
  # @yieldparam [String] Path of file being copied
104
104
  # @yieldparam [String] Target path on the winrm endpoint
105
105
  # @return [Fixnum] The total number of bytes copied
106
- def upload(local_paths, remote_path, &block)
107
- @logger.debug("uploading: #{local_paths} -> #{remote_path}")
108
- local_paths = [local_paths] if local_paths.is_a? String
106
+ def upload(local_path, remote_path, &block)
107
+ @logger.debug("uploading: #{local_path} -> #{remote_path}")
109
108
 
110
109
  upload_orchestrator = WinRM::FS::Core::UploadOrchestrator.new(@service)
111
- if FileManager.src_is_single_file?(local_paths)
112
- upload_orchestrator.upload_file(local_paths[0], remote_path, &block)
110
+ if File.file?(local_path)
111
+ upload_orchestrator.upload_file(local_path, remote_path, &block)
113
112
  else
114
- upload_orchestrator.upload_directory(local_paths, remote_path, &block)
113
+ upload_orchestrator.upload_directory(local_path, remote_path, &block)
115
114
  end
116
115
  end
117
-
118
- def self.src_is_single_file?(local_paths)
119
- local_paths.count == 1 && File.file?(local_paths[0])
120
- end
121
116
  end
122
117
  end
123
118
  end
@@ -1,8 +1,11 @@
1
1
  # encoding: UTF-8
2
+ require 'pathname'
3
+
2
4
  describe WinRM::FS::FileManager, integration: true do
3
5
  let(:dest_dir) { File.join(subject.temp_dir, "winrm_#{rand(2**16)}") }
4
6
  let(:temp_upload_dir) { '$env:TEMP/winrm-upload' }
5
- let(:src_dir) { File.expand_path(File.dirname(__FILE__)) }
7
+ let(:this_dir) { File.expand_path(File.dirname(__FILE__)) }
8
+ let(:this_file) { __FILE__ }
6
9
  let(:service) { winrm_connection }
7
10
 
8
11
  subject { WinRM::FS::FileManager.new(service) }
@@ -37,57 +40,73 @@ describe WinRM::FS::FileManager, integration: true do
37
40
  end
38
41
 
39
42
  context 'upload file' do
40
- let(:src_file) { __FILE__ }
41
- let(:dest_file) { File.join(dest_dir, File.basename(src_file)) }
43
+ let(:dest_file) { File.join(dest_dir, File.basename(this_file)) }
42
44
 
43
45
  before(:each) do
44
46
  expect(subject.delete(dest_dir)).to be true
45
47
  end
46
48
 
47
- it 'should upload the file to the specified file' do
48
- subject.upload(src_file, dest_file)
49
- expect(subject).to have_created(dest_file).with_content(src_file)
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/file_manager_spec.rb', dest_file)
62
+ expect(subject).to have_created(dest_file).with_content(this_file)
50
63
  end
51
64
 
52
- it 'should upload the file to the specified directory' do
53
- subject.upload(src_file, dest_dir)
54
- expect(subject).to have_created(dest_file).with_content(src_file)
65
+ it 'should upload to the specified directory' do
66
+ subject.upload(this_file, dest_dir)
67
+ expect(subject).to have_created(dest_file).with_content(this_file)
55
68
  end
56
69
 
57
- it 'should upload the file to the specified directory with env var' do
58
- subject.upload(src_file, '$env:Temp')
59
- expected_dest_file = File.join(subject.temp_dir, File.basename(src_file))
60
- expect(subject).to have_created(expected_dest_file).with_content(src_file)
70
+ it 'should upload to the specified directory with env var' do
71
+ subject.upload(this_file, '$env:Temp')
72
+ expected_dest_file = File.join(subject.temp_dir, File.basename(this_file))
73
+ expect(subject).to have_created(expected_dest_file).with_content(this_file)
61
74
  end
62
75
 
63
- it 'should upload the file to the specified nested directory' do
76
+ it 'should upload to Program Files sub dir' do
77
+ subject.upload(this_file, '$env:ProgramFiles/foo')
78
+ expect(subject).to have_created('c:/Program Files/foo/file_manager_spec.rb') \
79
+ .with_content(this_file)
80
+ end
81
+
82
+ it 'should upload to the specified nested directory' do
64
83
  dest_sub_dir = File.join(dest_dir, 'subdir')
65
- dest_sub_dir_file = File.join(dest_sub_dir, File.basename(src_file))
66
- subject.upload(src_file, dest_sub_dir)
67
- expect(subject).to have_created(dest_sub_dir_file).with_content(src_file)
84
+ dest_sub_dir_file = File.join(dest_sub_dir, File.basename(this_file))
85
+ subject.upload(this_file, dest_sub_dir)
86
+ expect(subject).to have_created(dest_sub_dir_file).with_content(this_file)
68
87
  end
69
88
 
70
89
  it 'yields progress data' do
71
- total = subject.upload(src_file, dest_file) do \
90
+ total = subject.upload(this_file, dest_file) do \
72
91
  |bytes_copied, total_bytes, local_path, remote_path|
73
92
  expect(total_bytes).to be > 0
74
93
  expect(bytes_copied).to eq(total_bytes)
75
- expect(local_path).to eq(src_file)
94
+ expect(local_path).to eq(this_file)
76
95
  expect(remote_path).to eq(dest_file)
77
96
  end
78
97
  expect(total).to be > 0
79
98
  end
80
99
 
81
- it 'should not upload the file when content matches' do
82
- subject.upload(src_file, dest_dir)
83
- bytes_uploaded = subject.upload(src_file, dest_dir)
100
+ it 'should not upload when content matches' do
101
+ subject.upload(this_file, dest_dir)
102
+ bytes_uploaded = subject.upload(this_file, dest_dir)
84
103
  expect(bytes_uploaded).to eq 0
85
104
  end
86
105
 
87
- it 'should upload file when content differs' do
88
- another_src_file = File.join(src_dir, 'matchers.rb')
89
- subject.upload(another_src_file, dest_file)
90
- bytes_uploaded = subject.upload(src_file, dest_file)
106
+ it 'should upload when content differs' do
107
+ matchers_file = File.join(this_dir, 'matchers.rb')
108
+ subject.upload(matchers_file, dest_file)
109
+ bytes_uploaded = subject.upload(this_file, dest_file)
91
110
  expect(bytes_uploaded).to be > 0
92
111
  end
93
112
 
@@ -97,7 +116,6 @@ describe WinRM::FS::FileManager, integration: true do
97
116
  end
98
117
 
99
118
  context 'upload empty file' do
100
- let(:src_file) { __FILE__ }
101
119
  let(:empty_src_file) { Tempfile.new('empty').path }
102
120
  let(:dest_file) { File.join(dest_dir, 'emptyfile.txt') }
103
121
 
@@ -107,33 +125,37 @@ describe WinRM::FS::FileManager, integration: true do
107
125
  end
108
126
 
109
127
  it 'overwrites an existing file' do
110
- expect(subject.upload(src_file, dest_file)).to be > 0
128
+ expect(subject.upload(this_file, dest_file)).to be > 0
111
129
  expect(subject.upload(empty_src_file, dest_file)).to be 0
112
130
  expect(subject).to have_created(dest_file).with_content('')
113
131
  end
114
132
  end
115
133
 
116
134
  context 'upload directory' do
117
- it 'copies the entire directory' do
118
- bytes_uploaded = subject.upload(src_dir, dest_dir)
135
+ let(:root_dir) { File.expand_path('../', File.dirname(__FILE__)) }
136
+ let(:winrm_fs_dir) { File.join(root_dir, 'lib/winrm-fs') }
137
+ let(:core_dir) { File.join(root_dir, 'lib/winrm-fs/core') }
138
+
139
+ it 'copies the entire directory recursively' do
140
+ bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
119
141
  expect(bytes_uploaded).to be > 0
120
- Dir.glob(src_dir + '/*.rb').each do |host_file|
121
- host_file_rel = host_file[src_dir.length..-1]
142
+
143
+ Dir.glob(winrm_fs_dir + '/**/*.rb').each do |host_file|
144
+ host_file_rel = Pathname.new(host_file).relative_path_from(Pathname.new(winrm_fs_dir)).to_s
122
145
  remote_file = File.join(dest_dir, host_file_rel)
123
146
  expect(subject).to have_created(remote_file).with_content(host_file)
124
147
  end
125
148
  end
126
149
 
127
150
  it 'does not copy the directory when content is the same' do
128
- subject.upload(src_dir, dest_dir)
129
- bytes_uploaded = subject.upload(src_dir, dest_dir)
151
+ subject.upload(winrm_fs_dir, dest_dir)
152
+ bytes_uploaded = subject.upload(winrm_fs_dir, dest_dir)
130
153
  expect(bytes_uploaded).to eq 0
131
154
  end
132
155
 
133
156
  it 'copies the directory when content differs' do
134
- subject.upload(src_dir, dest_dir)
135
- another_dir = File.dirname(src_dir)
136
- bytes_uploaded = subject.upload(another_dir, dest_dir)
157
+ subject.upload(winrm_fs_dir, dest_dir)
158
+ bytes_uploaded = subject.upload(core_dir, dest_dir)
137
159
  expect(bytes_uploaded).to be > 0
138
160
  end
139
161
  end
data/spec/matchers.rb CHANGED
@@ -41,14 +41,18 @@ end
41
41
  RSpec::Matchers.define :contain_zip_entries do |zip_entries|
42
42
  match do |temp_zip_file|
43
43
  zip_entries = [zip_entries] if zip_entries.is_a? String
44
- zip_file = Zip::File.open(temp_zip_file.path)
44
+ @zip_file = Zip::File.open(temp_zip_file.path)
45
45
  @missing_entries = []
46
46
  zip_entries.each do |entry|
47
- @missing_entries << entry unless zip_file.find_entry(entry)
47
+ @missing_entries << entry unless @zip_file.find_entry(entry)
48
48
  end
49
49
  @missing_entries.empty?
50
50
  end
51
51
  failure_message do |temp_zip_file|
52
- "Expected #{temp_zip_file.path} to contain zip entries: #{@missing_entries}"
52
+ msg = "Expected #{temp_zip_file.path} to contain zip entries: #{@missing_entries}\n Got: "
53
+ @zip_file.each do |entry|
54
+ msg << entry.name << ', '
55
+ end
56
+ msg
53
57
  end
54
58
  end
@@ -1,13 +1,12 @@
1
1
  # encoding: UTF-8
2
- require 'zip'
3
2
  require_relative '../lib/winrm-fs/core/temp_zip_file'
4
3
 
5
4
  describe WinRM::FS::Core::TempZipFile, integration: true do
6
- let(:src_dir) { File.expand_path('../lib/winrm-fs', File.dirname(__FILE__)) }
7
- let(:src_file) { __FILE__ }
5
+ let(:winrm_fs_dir) { File.expand_path('../lib/winrm-fs', File.dirname(__FILE__)) }
6
+ let(:temp_zip_file_spec) { __FILE__ }
7
+ let(:spec_helper) { File.expand_path('spec_helper.rb', File.dirname(__FILE__)) }
8
8
 
9
9
  subject { WinRM::FS::Core::TempZipFile.new }
10
- after(:each) { subject.delete }
11
10
 
12
11
  context 'temp file creation' do
13
12
  it 'should create a temp file on disk' do
@@ -17,55 +16,40 @@ describe WinRM::FS::Core::TempZipFile, integration: true do
17
16
  end
18
17
  end
19
18
 
20
- context 'add_file' do
19
+ context 'create zip' do
21
20
  it 'should raise error when file doesn not exist' do
22
- expect { subject.add_file('/etc/foo/does/not/exist') }.to \
23
- raise_error('/etc/foo/does/not/exist isn\'t a file')
24
- end
25
-
26
- it 'should raise error when file is a directory' do
27
- dir = File.dirname(subject.path)
28
- expect { subject.add_file(dir) }.to \
29
- raise_error("#{dir} isn\'t a file")
21
+ expect { subject.add('/etc/foo/does/not/exist') }.to raise_error
30
22
  end
31
23
 
32
24
  it 'should add a file to the zip' do
33
- subject.add_file(src_file)
34
- expect(subject).to contain_zip_entries(File.basename(src_file))
25
+ subject.add(temp_zip_file_spec)
26
+ subject.build
27
+ expect(subject).to contain_zip_entries('spec/temp_zip_file_spec.rb')
35
28
  end
36
- end
37
29
 
38
- context 'add_directory' do
39
- it 'should raise error when directory does not exist' do
40
- expect { subject.add_directory('/etc/does/not/exist') }.to \
41
- raise_error('/etc/does/not/exist isn\'t a directory')
30
+ it 'should add multiple files to the zip' do
31
+ subject.add(temp_zip_file_spec)
32
+ subject.add(spec_helper)
33
+ subject.build
34
+ expect(subject).to contain_zip_entries([
35
+ 'spec/temp_zip_file_spec.rb',
36
+ 'spec/spec_helper.rb'])
42
37
  end
43
38
 
44
- it 'should raise error when directory is a file' do
45
- expect { subject.add_directory(subject.path) }.to \
46
- raise_error("#{subject.path} isn\'t a directory")
39
+ it 'should add all files in directory' do
40
+ subject.add(winrm_fs_dir)
41
+ subject.build
42
+ expect(subject).to contain_zip_entries('lib/winrm-fs/exceptions.rb')
47
43
  end
48
44
 
49
45
  it 'should add all files in directory to the zip recursively' do
50
- subject.add_directory(src_dir)
51
- expect(subject).to contain_zip_entries(['exceptions.rb', 'core/temp_zip_file.rb'])
52
- end
53
- end
54
-
55
- context 'add' do
56
- it 'should add all files when given a directory' do
57
- subject.add(src_dir)
58
- expect(subject).to contain_zip_entries(['exceptions.rb', 'core/temp_zip_file.rb'])
59
- end
60
-
61
- it 'should add a file when given only a file' do
62
- subject.add(src_file)
63
- expect(subject).to contain_zip_entries(File.basename(src_file))
64
- end
65
-
66
- it 'should raise error when given a non-path' do
67
- expect { subject.add('garbage') }.to \
68
- raise_error("garbage doesn't exist")
46
+ subject = WinRM::FS::Core::TempZipFile.new(Dir.pwd, recurse_paths: true)
47
+ subject.add(winrm_fs_dir)
48
+ subject.build
49
+ expect(subject).to contain_zip_entries([
50
+ 'lib/winrm-fs/exceptions.rb',
51
+ 'lib/winrm-fs/core/temp_zip_file.rb',
52
+ 'lib/winrm-fs/scripts/checksum.ps1.erb'])
69
53
  end
70
54
  end
71
55
  end
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: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Neal
@@ -9,110 +9,110 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-20 00:00:00.000000000 Z
12
+ date: 2015-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: erubis
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '2.7'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '2.7'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: logging
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '1.6'
35
- - - '>='
35
+ - - ">="
36
36
  - !ruby/object:Gem::Version
37
37
  version: 1.6.1
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - ~>
42
+ - - "~>"
43
43
  - !ruby/object:Gem::Version
44
44
  version: '1.6'
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.6.1
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rubyzip
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.1'
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.1'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: winrm
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.3.0
69
69
  type: :runtime
70
70
  prerelease: false
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.3.0
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: rspec
78
78
  requirement: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 3.0.0
83
83
  type: :development
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 3.0.0
90
90
  - !ruby/object:Gem::Dependency
91
91
  name: rake
92
92
  requirement: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 10.3.2
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: 10.3.2
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rubocop
106
106
  requirement: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.28.0
111
111
  type: :development
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: 0.28.0
118
118
  description: |2
@@ -127,16 +127,17 @@ extra_rdoc_files:
127
127
  - README.md
128
128
  - LICENSE
129
129
  files:
130
- - .gitignore
131
- - .rspec
132
- - .rubocop.yml
133
- - .travis.yml
130
+ - ".gitignore"
131
+ - ".rspec"
132
+ - ".rubocop.yml"
133
+ - ".travis.yml"
134
134
  - Gemfile
135
135
  - LICENSE
136
136
  - README.md
137
137
  - Rakefile
138
138
  - VERSION
139
139
  - Vagrantfile
140
+ - benchmark.rb
140
141
  - bin/rwinrmcp
141
142
  - changelog.md
142
143
  - lib/winrm-fs.rb
@@ -164,25 +165,25 @@ licenses: []
164
165
  metadata: {}
165
166
  post_install_message:
166
167
  rdoc_options:
167
- - -x
168
+ - "-x"
168
169
  - test/
169
- - -x
170
+ - "-x"
170
171
  - examples/
171
172
  require_paths:
172
173
  - lib
173
174
  required_ruby_version: !ruby/object:Gem::Requirement
174
175
  requirements:
175
- - - '>='
176
+ - - ">="
176
177
  - !ruby/object:Gem::Version
177
178
  version: 1.9.0
178
179
  required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  requirements:
180
- - - '>='
181
+ - - ">="
181
182
  - !ruby/object:Gem::Version
182
183
  version: '0'
183
184
  requirements: []
184
185
  rubyforge_project:
185
- rubygems_version: 2.0.14
186
+ rubygems_version: 2.2.2
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: WinRM File System