X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a1379fdd1f825c22a3ada0a2c085a1b0121ce89a..efeca068c2c25ee075ee8907a1937a5d4119775c:/services/api/lib/salvage_collection.rb diff --git a/services/api/lib/salvage_collection.rb b/services/api/lib/salvage_collection.rb index 2ffe0f4463..3813f41864 100755 --- a/services/api/lib/salvage_collection.rb +++ b/services/api/lib/salvage_collection.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + module SalvageCollection # Take two input parameters: a collection uuid and reason # Get "src_collection" with the given uuid @@ -14,7 +18,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 +27,25 @@ module SalvageCollection end end - LOCATOR_REGEXP = /^([[:xdigit:]]{32})(\+(.*))?\z/ - def self.salvage_collection_locator_data manifest - # Get all the locators from the original manifest - locators = [] - size = 0 - manifest.each_line do |line| - line.split(' ').each do |word| - if match = LOCATOR_REGEXP.match(word) - if match.size > 3 and match[3] - size_str = match[3].split('+')[0] - if size_str.to_i.to_s == size_str - word = match[1] + '+' + size_str # get rid of any hints - size += size_str.to_i - else - word = match[1] - end - else - word = match[1] - 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." @@ -70,6 +65,7 @@ module SalvageCollection # create new collection using 'arv-put' with original manifest_text as the data temp_file = Tempfile.new('temp') temp_file.write(src_manifest) + temp_file.close new_manifest = salvage_collection_arv_put "arv-put --as-stream --use-filename invalid_manifest_text.txt #{Shellwords::shellescape(temp_file.path)}"