- 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