+# 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
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
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."
# 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)}"