X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7fc67e3f9bfd12058e6f3d86d995704ed8962a8b..b73985d8a0c9173aec57f6a81fe540b2813a5bff:/services/api/lib/salvage_collection.rb diff --git a/services/api/lib/salvage_collection.rb b/services/api/lib/salvage_collection.rb index 86c95c6772..2011f812d5 100755 --- a/services/api/lib/salvage_collection.rb +++ b/services/api/lib/salvage_collection.rb @@ -14,7 +14,7 @@ module SalvageCollection require 'tempfile' require 'shellwords' - def self.salvage_collection_arv_put cmd + def salvage_collection_arv_put cmd new_manifest = %x(#{cmd}) if $?.success? new_manifest @@ -23,34 +23,25 @@ module SalvageCollection end end - # Get all the locators from the original manifest - LOCATOR_REGEXP = /((.*))?([[:xdigit:]]{32})(\+(.*))?\z/ - def self.salvage_collection_locator_data manifest - locators = [] - size = 0 - manifest.each_line do |line| - line.split(' ').each do |word| - if match = LOCATOR_REGEXP.match(word) - if match.size == 6 and match[5] - size_str = match[5].split('+')[0] - if size_str.to_i.to_s == size_str - word = match[3] + '+' + size_str # get rid of any other hints - size += size_str.to_i - else - word = match[3] - end - else - word = match[3] - end - locators << word - end - end + # Get all the locators (and perhaps other strings that look a lot + # like a locators) from the original manifest, even if they don't + # appear in the correct positions with the correct space delimiters. + def salvage_collection_locator_data manifest + locators = [] + size = 0 + manifest.scan /(^|[^[:xdigit:]])([[:xdigit:]]{32})((\+\d+)(\+|\b))?/ do |_, hash, _, sizehint, _| + if sizehint + locators << hash.downcase + sizehint + size += sizehint.to_i + else + locators << hash.downcase end - locators << 'd41d8cd98f00b204e9800998ecf8427e+0' if !locators.any? - return [locators, size] + end + locators << 'd41d8cd98f00b204e9800998ecf8427e+0' if !locators.any? + return [locators, size] end - def self.salvage_collection uuid, reason='salvaged - see #6277, #6859' + def salvage_collection uuid, reason='salvaged - see #6277, #6859' act_as_system_user do if !ENV['ARVADOS_API_TOKEN'].present? or !ENV['ARVADOS_API_HOST'].present? raise "ARVADOS environment variables missing. Please set your admin user credentials as ARVADOS environment variables."