firespring_dev_commands 2.1.28 → 2.1.29.pre.alpha.1

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: 887cf6fa6942ca683459b0a7325fee216656f7575f750932a0236a3a67246f4c
4
- data.tar.gz: b238f37f30f93e543018915924c8a2aefde74b771400846804bf974649711a76
3
+ metadata.gz: 87729055135e487595d40ce6629354b1fc473ae963383965e2b5570c9938055c
4
+ data.tar.gz: adcc648f8bcbfd326b5aad54dc7868dc2ee93c3d18e7483f98eb8d5e98ff5d14
5
5
  SHA512:
6
- metadata.gz: b2e3bd5b15893d2397969c0cc5a7f1aa1c64603dec853b415f81d71fac90450126ee68ffa8a4f1d20093e44453a2ad1a501529c2defca1f8689b67456760ccf9
7
- data.tar.gz: a845da667386b9c289ce4dfc4f121a734271b8ef6347f1ab77aa08f179e77947c4c6c80176cae6407aacb068d0c6058c75d836ace68cf4b6cd97fb595bd22372
6
+ metadata.gz: 8ab9a8f2b52c1711e338917077aed4c32fa77b65da6518908c04f52e7f119a2abae8f5117e594d1e69597b889a385682d5e0e23d806ec56a3f328355185942e4
7
+ data.tar.gz: e8c21faaf030c75f1dccda8308ef15b5ada63e4ef6c2bd3f0a529f62b8300f062fc8286e948b74461ae442f89a893f43d8dfe36ca8e72a9a009ef44a6d3b9863
@@ -182,28 +182,53 @@ module Dev
182
182
  end
183
183
 
184
184
  # Copies the source path on your local machine to the destination path on the container
185
- def copy_to_container(container, source_path, dest_path)
186
- dest_path = File.join(working_dir(container), dest_path) unless dest_path.start_with?(File::SEPARATOR)
187
- LOG.info "Copying #{source_path} to #{dest_path}... "
188
-
189
- container.archive_in(source_path, dest_path, overwrite: true)
190
- return unless File.directory?(source_path)
191
-
192
- dest_file = File.basename(source_path)
193
- # TODO: Can we find a better solution for this? Seems pretty brittle
194
- retcode = container.exec(['bash', '-c', "cd #{dest_path}; tar -xf #{dest_file}; rm -f #{dest_file}"])[-1]
195
- raise 'Unable to unpack on container' unless retcode.zero?
185
+ def copy_to_container(container, source, destination)
186
+ # Add the working dir of the container onto the destination (if it doesn't start a path separator)
187
+ destination = File.join(working_dir(container), destination) unless destination.start_with?(File::SEPARATOR)
188
+ LOG.info "Copying #{source} to #{destination}..."
189
+
190
+ # Need to determine the type of the destination (file or directory or nonexistant)
191
+ noexist_code = 22
192
+ file_code = 33
193
+ directory_code = 44
194
+ unknown_code = 55
195
+ filetype_cmd = [
196
+ 'bash',
197
+ '-c',
198
+ "set -e; [ ! -e '#{destination}' ] && exit #{noexist_code}; [ -f '#{destination}' ] " \
199
+ "&& exit #{file_code}; [ -d '#{destination}' ] && exit #{directory_code}; exit #{unknown_code}"
200
+ ]
201
+ destination_filetype_code = container.exec(filetype_cmd).last
202
+
203
+ # If destination_filetype_code is a file - that means the user passed in a destination filename
204
+ # Unfortunately the archive_in command does not support that so we will strip it off and use it later (if needed)
205
+ source_filename = File.basename(source)
206
+ destination_filename = File.basename(source)
207
+ destination, _, destination_filename = destination.rpartition(File::SEPARATOR) if destination_filetype_code == file_code
208
+
209
+ container.archive_in(source, destination, overwrite: true)
210
+
211
+ if File.directory?(source)
212
+ # If the source was a directory, then the archive_in command leaves it as a tar on the system - so we need to unpack it
213
+ # TODO: Can we find a better solution for this? Seems pretty brittle
214
+ retcode = container.exec(['bash', '-c', "cd #{destination}; tar -xf #{destination_filename}; rm -f #{destination_filename}"]).last
215
+ raise 'Unable to unpack on container' unless retcode.zero?
216
+ elsif destination_filetype_code == file_code && source_filename != destination_filename
217
+ # If the destination was a file _and_ the filename is different than the source filename, then we need to rename it
218
+ retcode = container.exec(['bash', '-c', "cd #{destination}; mv #{source_filename} #{destination_filename}"]).last
219
+ raise "Unable to rename '#{source_filename}' to '#{destination_filename}' on container" unless retcode.zero?
220
+ end
196
221
  end
197
222
 
198
223
  # Copies the source path on the container to the destination path on your local machine
199
224
  # If required is set to true, the command will fail if the source path does not exist on the container
200
- def copy_from_container(container, source_path, dest_path, required: true)
201
- source_path = File.join(working_dir(container), source_path) unless source_path.start_with?(File::SEPARATOR)
202
- LOG.info "Copying #{source_path} to #{dest_path}... "
225
+ def copy_from_container(container, source, destination, required: true)
226
+ source = File.join(working_dir(container), source) unless source.start_with?(File::SEPARATOR)
227
+ LOG.info "Copying #{source} to #{destination}..."
203
228
 
204
229
  tar = StringIO.new
205
230
  begin
206
- container.archive_out(source_path) do |chunk|
231
+ container.archive_out(source) do |chunk|
207
232
  tar.write(chunk)
208
233
  end
209
234
  rescue => e
@@ -212,7 +237,7 @@ module Dev
212
237
  puts 'Not Found'
213
238
  end
214
239
 
215
- Dev::Tar.new(tar).unpack(source_path, dest_path)
240
+ Dev::Tar.new(tar).unpack(source, destination)
216
241
  end
217
242
 
218
243
  # rubocop:disable Metrics/ParameterLists
@@ -6,6 +6,6 @@ module Dev
6
6
  # Use 'v.v.v.pre.alpha.v' for pre-release vesions
7
7
  # Use 'v.v.v.beta.v for beta versions
8
8
  # Use semantic versioning for any releases (https://semver.org/)
9
- VERSION = '2.1.28'.freeze
9
+ VERSION = '2.1.29.pre.alpha.1'.freeze
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firespring_dev_commands
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.28
4
+ version: 2.1.29.pre.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-25 00:00:00.000000000 Z
11
+ date: 2024-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -412,9 +412,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
412
412
  version: '3.1'
413
413
  required_rubygems_version: !ruby/object:Gem::Requirement
414
414
  requirements:
415
- - - ">="
415
+ - - ">"
416
416
  - !ruby/object:Gem::Version
417
- version: '0'
417
+ version: 1.3.1
418
418
  requirements: []
419
419
  rubygems_version: 3.4.10
420
420
  signing_key: