mixlib-shellout 3.2.7-x64-mingw-ucrt → 3.3.3-x64-mingw-ucrt

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
  SHA256:
3
- metadata.gz: d140324dd4f8a87c44570cc6690f82dae2d3353760fc071a43cb54559b7f8919
4
- data.tar.gz: d174c6c863c2b90a5e4da267429d7f39450063c7fdf014d182e7329f94e79c77
3
+ metadata.gz: 35f15cebdb3714d50e21662d40191a54cefeb01cf7dd477650e01340193e4128
4
+ data.tar.gz: f738c4df369f8e5fc4df70bed9ae3e582e93d1bc4fa93770a525b81861e63d4f
5
5
  SHA512:
6
- metadata.gz: d89f6b1abb29fe830fc2f71b198dbd6391dc11064f03e5c6f1f6725bdb4d1de0746306dbe5e5890c56dfdfb23e4b7e3fed050f7fae2909045141d501e8a00bd0
7
- data.tar.gz: 4917605b79757ca815a1c329610aae1a5f767bc58782eecf50cd9c6a6b316591d70ec0d7d4dc4156e597676e795fd9d6433e0deb7b5cc88ec5c06d0ada4dbd6d
6
+ metadata.gz: 8901f19ff920f201c1213107c3b51b9bb52fe0ee367c51bec3873f089bf59883d0ece0ab13e2ecd6451467c4e72b4be0a65dfe18f2d5ae2231ee403ca3ec96ce
7
+ data.tar.gz: 13d2938c185e57ed9a6442d6ce2b9e94ee0d9368826497909f4ee27311f455872466343eda5efa9c38a260b989b7fc63467aa3d8dbd73fdf6602d7c21dbe45f2
@@ -141,9 +141,36 @@ module Mixlib
141
141
  args.flatten.compact.map(&:to_s)
142
142
  end
143
143
 
144
+ # Join arguments into a string.
145
+ #
146
+ # If the argument ends with a whitespace, use it as-is. Otherwise, add
147
+ # a space at the end
148
+ #
149
+ # @param args [String] variable number of string arguments
150
+ # @return [String] merged string
151
+ #
152
+ def __join_whitespace(*args)
153
+ args.flatten.map { |e| e + (e.rstrip == e ? " " : "") }.join
154
+ end
155
+
144
156
  def __shell_out_command(*args, **options)
145
157
  if __transport_connection
146
- FakeShellOut.new(args, options, __transport_connection.run_command(args.join(" "))) # FIXME: train should accept run_command(*args)
158
+ command = __join_whitespace(args)
159
+ unless ChefUtils.windows?
160
+ if options[:cwd]
161
+ # as `timeout` is used, commands need to be executed in a subshell
162
+ command = "sh -c 'cd #{options[:cwd]}; #{command}'"
163
+ end
164
+
165
+ if options[:input]
166
+ command.concat "<<'COMMANDINPUT'\n"
167
+ command.concat __join_whitespace(options[:input])
168
+ command.concat "COMMANDINPUT\n"
169
+ end
170
+ end
171
+
172
+ # FIXME: train should accept run_command(*args)
173
+ FakeShellOut.new(args, options, __transport_connection.run_command(command, options))
147
174
  else
148
175
  cmd = if options.empty?
149
176
  Mixlib::ShellOut.new(*args)
@@ -181,15 +208,16 @@ module Mixlib
181
208
  @stdout = result.stdout
182
209
  @stderr = result.stderr
183
210
  @exitstatus = result.exit_status
184
- @status = OpenStruct.new(success?: ( exitstatus == 0 ))
211
+ @valid_exit_codes = Array(options[:returns] || 0)
212
+ @status = OpenStruct.new(success?: (@valid_exit_codes.include? exitstatus))
185
213
  end
186
214
 
187
215
  def error?
188
- exitstatus != 0
216
+ @valid_exit_codes.none?(exitstatus)
189
217
  end
190
218
 
191
219
  def error!
192
- raise Mixlib::ShellOut::ShellCommandFailed, "Unexpected exit status of #{exitstatus} running #{@args}" if error?
220
+ raise Mixlib::ShellOut::ShellCommandFailed, "Unexpected exit status of #{exitstatus} running #{@args}: #{stderr}" if error?
193
221
  end
194
222
  end
195
223
  end
@@ -20,11 +20,6 @@ module Mixlib
20
20
  class ShellOut
21
21
  module Unix
22
22
 
23
- # "1.8.7" as a frozen string. We use this with a hack that disables GC to
24
- # avoid segfaults on Ruby 1.8.7, so we need to allocate the fewest
25
- # objects we possibly can.
26
- ONE_DOT_EIGHT_DOT_SEVEN = "1.8.7".freeze
27
-
28
23
  # Option validation that is unix specific
29
24
  def validate_options(opts)
30
25
  if opts[:elevated]
@@ -99,12 +94,6 @@ module Mixlib
99
94
 
100
95
  configure_parent_process_file_descriptors
101
96
 
102
- # Ruby 1.8.7 and 1.8.6 from mid 2009 try to allocate objects during GC
103
- # when calling IO.select and IO#read. Disabling GC works around the
104
- # segfault, but obviously it's a bad workaround. We no longer support
105
- # 1.8.6 so we only need this hack for 1.8.7.
106
- GC.disable if RUBY_VERSION == ONE_DOT_EIGHT_DOT_SEVEN
107
-
108
97
  # CHEF-3390: Marshall.load on Ruby < 1.8.7p369 also has a GC bug related
109
98
  # to Marshall.load, so try disabling GC first.
110
99
  propagate_pre_exec_failure
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class ShellOut
3
- VERSION = "3.2.7".freeze
3
+ VERSION = "3.3.3".freeze
4
4
  end
5
5
  end
@@ -60,6 +60,7 @@ module Mixlib
60
60
  stderr_read, stderr_write = IO.pipe
61
61
  stdin_read, stdin_write = IO.pipe
62
62
  open_streams = [ stdout_read, stderr_read ]
63
+ @execution_time = 0
63
64
 
64
65
  begin
65
66
 
@@ -105,6 +106,8 @@ module Mixlib
105
106
  wait_status = WaitForSingleObject(process.process_handle, 0)
106
107
  case wait_status
107
108
  when WAIT_OBJECT_0
109
+ # Save the execution time
110
+ @execution_time = Time.now - start_wait
108
111
  # Get process exit code
109
112
  exit_code = [0].pack("l")
110
113
  unless GetExitCodeProcess(process.process_handle, exit_code)
@@ -127,6 +130,9 @@ module Mixlib
127
130
  logger&.warn("Failed to kill timed out process #{process.process_id}")
128
131
  end
129
132
 
133
+ # Save the execution time
134
+ @execution_time = Time.now - start_wait
135
+
130
136
  raise Mixlib::ShellOut::CommandTimeout, [
131
137
  "command timed out:",
132
138
  format_for_exception,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-shellout
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.7
4
+ version: 3.3.3
5
5
  platform: x64-mingw-ucrt
6
6
  authors:
7
7
  - Chef Software Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-04 00:00:00.000000000 Z
11
+ date: 2024-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-utils
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubygems_version: 3.1.4
102
+ rubygems_version: 3.2.3
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: Run external commands on Unix or Windows