X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9259c169b6254ea581fcdcb18e1cdbe9b9fbea1e..d6e0bfffc0e79ef129d89ae220dcbebb6dc474a7:/services/api/lib/salvage_collection.rb diff --git a/services/api/lib/salvage_collection.rb b/services/api/lib/salvage_collection.rb index 79a2d58bc6..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 @@ -23,31 +27,22 @@ module SalvageCollection end end - # Get all the locators from the original manifest - LOCATOR_REGEXP = /((.*))?([[:xdigit:]]{32})(\+(.*))?\z/ + # 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.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 + 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 salvage_collection uuid, reason='salvaged - see #6277, #6859'