firespring_dev_commands 2.1.28.pre.alpha.1 → 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: 7cdbf7bd3018268faebfd9301f055ea1ab48c2c98bb6a1327000f6677f45f3da
4
- data.tar.gz: 7b4cf7884dd2bbc167f4ec8434f5e07aaa6c8ee503a5fb3ac9fd13460deec80a
3
+ metadata.gz: 87729055135e487595d40ce6629354b1fc473ae963383965e2b5570c9938055c
4
+ data.tar.gz: adcc648f8bcbfd326b5aad54dc7868dc2ee93c3d18e7483f98eb8d5e98ff5d14
5
5
  SHA512:
6
- metadata.gz: 30e7bc37e599f73d3f01287600466ce84fdf8ec2bc5da20f99b50c6cea26c3d4ee6b8c156749ea89739b2ee96cee44ade8c53f079076bb3d455d31750e38e6ac
7
- data.tar.gz: 6c619223341b4379007a3c4826d9b2c6684a67c740847a528520931534b31d1296e871665b939c0ae99481fec6eff2e554afc7049901a832da6524fc3e8ece42
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.pre.alpha.1'.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.pre.alpha.1
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-22 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