- end
-
- normalized = arv_normalize combined
- normalized_stripped = arv_normalize combined, '--strip'
-
- require 'digest/md5'
-
- d = Digest::MD5.new()
- d << normalized_stripped
- newuuid = "#{d.hexdigest}+#{normalized_stripped.length}"
-
- env = Hash[ENV].
- merge({
- 'ARVADOS_API_HOST' =>
- arvados_api_client.arvados_v1_base.
- sub(/\/arvados\/v1/, '').
- sub(/^https?:\/\//, ''),
- 'ARVADOS_API_TOKEN' => Thread.current[:arvados_api_token],
- 'ARVADOS_API_HOST_INSECURE' =>
- Rails.configuration.arvados_insecure_https ? 'true' : 'false'
- })
-
- IO.popen([env, 'arv-put', '--raw'], 'w+b') do |io|
- io.write normalized_stripped
- io.close_write
- while buf = io.read(2**16)
+ src_pathlist.each do |src_path|
+ src_path = src_path.sub(/^(\.\/|\/|)/, "./")
+ src_stream, _, basename = src_path.rpartition("/")
+ dst_stream = destdir || src_stream
+ # Generate a unique name by adding (1), (2), etc. to it.
+ # If the filename has a dot that's not at the beginning, insert the
+ # number just before that. Otherwise, append the number to the name.
+ if match = basename.match(/[^\.]\./)
+ suffix_start = match.begin(0) + 1
+ else
+ suffix_start = basename.size
+ end
+ suffix_size = 0
+ dst_path = nil
+ loop.each_with_index do |_, try_count|
+ dst_path = "#{dst_stream}/#{basename}"
+ break unless new_coll.exist?(dst_path)
+ uniq_suffix = "(#{try_count + 1})"
+ basename[suffix_start, suffix_size] = uniq_suffix
+ suffix_size = uniq_suffix.size
+ end
+ new_coll.cp_r(src_path, dst_path, src_coll)