etna 0.1.39 → 0.1.40

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: c21212f38bbad3cf757eb84a9e453428c9d0b6f195fd34eb81f98aeff2746490
4
- data.tar.gz: 3581821244c087cbbfbac162f9a5c61911e06ab64923c603a144d36ca3bedff0
3
+ metadata.gz: e83d3c30c23693011d59b103f8b5a9372950eba1b3123376a288826204d47c62
4
+ data.tar.gz: c3b50952e71d91f4361a87e872ba5532849644abe42fbc9e480549726a6bbf93
5
5
  SHA512:
6
- metadata.gz: 3289530a2e874d2b79b0da66ea787e30b335b7a60626e4b67f1be9919067d4b79752db4e878ca8851dbce6c68a1e59a573bcbc60314bb7a35268cd37cc2eeaae
7
- data.tar.gz: 2758348f253992e08fbf589d2b5444844becf69e179872c630804a7e8885568189168edd056c56beabe4ed5dc3e0905f46c51595896bd7bdd1255fbe4ece71ec
6
+ metadata.gz: c3c561cdd7db4631c267f2edba8421b94baba5de790ca1ff9edd06cd21d039d7224d868eaa43ba7090b4114b595830ac777c1c4688ec15c9320cde90530be4e5
7
+ data.tar.gz: 7148582a82f7e90357ed6658c7337bce7b34dd532b4a899ac27a2d74f40f34224cb6c225b2aa4db4164c467aa8a5c189d7acf28a1c462097e619e9875fbdc4d1
@@ -192,7 +192,7 @@ module Etna::Application
192
192
  status = 'failed'
193
193
  raise
194
194
  ensure
195
- if Yabeda.configured?
195
+ if defined?(Yabeda) && Yabeda.configured?
196
196
  tags = { command: cmd.class.name, status: status, application: application }
197
197
  dur = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
198
198
 
@@ -210,34 +210,30 @@ module Etna
210
210
  }
211
211
  end
212
212
 
213
- def recursively_rename_folder(project_name:, source_bucket:, dest_bucket:, folder:)
214
- folder_contents = list_folder(
215
- Etna::Clients::Metis::ListFolderRequest.new(
216
- project_name: project_name,
217
- bucket_name: source_bucket,
218
- folder_path: folder.folder_path
219
- ))
213
+ def resolve_conflicts_and_verify_rename(project_name:, source_bucket:, dest_bucket:, folder:, file:)
214
+ parent_folder = ::File.dirname(file.file_path)
220
215
 
221
- folder_contents.folders.all.each do |sub_folder|
222
- recursively_rename_folder(
223
- project_name: project_name,
224
- source_bucket: source_bucket,
225
- dest_bucket: dest_bucket,
226
- folder: sub_folder
227
- )
228
- end
216
+ should_rename_original = true
229
217
 
230
- folder_contents.files.all.each do |file|
218
+ # If the destination folder already exists, check to see if
219
+ # the file also exists, otherwise we risk a
220
+ # rename conflict.
221
+ create_folder_request = CreateFolderRequest.new(
222
+ project_name: project_name,
223
+ bucket_name: dest_bucket,
224
+ folder_path: parent_folder
225
+ )
226
+
227
+ if folder_exists?(create_folder_request)
231
228
  # If file exists in destination, delete the older file.
232
229
  list_dest_folder_request = Etna::Clients::Metis::ListFolderRequest.new(
233
230
  bucket_name: dest_bucket,
234
231
  project_name: project_name,
235
- folder_path: ::File.dirname(file.file_path)
232
+ folder_path: parent_folder
236
233
  )
237
234
 
238
235
  dest_file = list_folder(list_dest_folder_request).files.all.find { |f| f.file_name == file.file_name }
239
236
 
240
- should_rename = true
241
237
  if (dest_file && file.updated_at <= dest_file.updated_at)
242
238
  # Delete source file if it's out of date
243
239
  delete_file(Etna::Clients::Metis::DeleteFileRequest.new(
@@ -246,7 +242,7 @@ module Etna
246
242
  file_path: file.file_path,
247
243
  ))
248
244
 
249
- should_rename = false
245
+ should_rename_original = false
250
246
  elsif (dest_file && file.updated_at > dest_file.updated_at)
251
247
  # Delete dest file if it's out of date
252
248
  delete_file(Etna::Clients::Metis::DeleteFileRequest.new(
@@ -255,17 +251,44 @@ module Etna
255
251
  file_path: dest_file.file_path,
256
252
  ))
257
253
  end
254
+ end
258
255
 
259
- if should_rename
260
- rename_file(Etna::Clients::Metis::RenameFileRequest.new(
261
- bucket_name: source_bucket,
262
- project_name: project_name,
263
- file_path: file.file_path,
264
- new_bucket_name: dest_bucket,
265
- new_file_path: file.file_path,
266
- create_parent: true)
267
- )
268
- end
256
+ should_rename_original
257
+ end
258
+
259
+ def recursively_rename_folder(project_name:, source_bucket:, dest_bucket:, folder:)
260
+ folder_contents = list_folder(
261
+ Etna::Clients::Metis::ListFolderRequest.new(
262
+ project_name: project_name,
263
+ bucket_name: source_bucket,
264
+ folder_path: folder.folder_path
265
+ ))
266
+
267
+ folder_contents.folders.all.each do |sub_folder|
268
+ recursively_rename_folder(
269
+ project_name: project_name,
270
+ source_bucket: source_bucket,
271
+ dest_bucket: dest_bucket,
272
+ folder: sub_folder
273
+ )
274
+ end
275
+
276
+ folder_contents.files.all.each do |file|
277
+ should_rename = resolve_conflicts_and_verify_rename(
278
+ project_name: project_name,
279
+ source_bucket: source_bucket,
280
+ dest_bucket: dest_bucket,
281
+ folder: folder,
282
+ file: file)
283
+
284
+ rename_file(Etna::Clients::Metis::RenameFileRequest.new(
285
+ bucket_name: source_bucket,
286
+ project_name: project_name,
287
+ file_path: file.file_path,
288
+ new_bucket_name: dest_bucket,
289
+ new_file_path: file.file_path,
290
+ create_parent: true)
291
+ ) if should_rename
269
292
  end
270
293
 
271
294
  # Now delete the source folder
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.39
4
+ version: 0.1.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saurabh Asthana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-22 00:00:00.000000000 Z
11
+ date: 2021-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack