class Google::Cloud::Storage::Service

def rewrite_file source_bucket_name,

destination bucket/object.
# Rewrite a file from source bucket/object to a
def rewrite_file source_bucket_name,
                 source_file_path,
                 destination_bucket_name,
                 destination_file_path,
                 file_gapi = nil,
                 source_key: nil,
                 destination_key: nil,
                 destination_kms_key: nil,
                 acl: nil,
                 generation: nil,
                 if_generation_match: nil,
                 if_generation_not_match: nil,
                 if_metageneration_match: nil,
                 if_metageneration_not_match: nil,
                 if_source_generation_match: nil,
                 if_source_generation_not_match: nil,
                 if_source_metageneration_match: nil,
                 if_source_metageneration_not_match: nil,
                 token: nil,
                 user_project: nil,
                 options: {}
  key_options = rewrite_key_options source_key, destination_key
  if options[:retries].nil?
    is_idempotent = retry? if_generation_match: if_generation_match
    options = is_idempotent ? key_options : key_options.merge(retries: 0)
  else
    options = key_options.merge options
  end
  execute do
    service.rewrite_object source_bucket_name,
                           source_file_path,
                           destination_bucket_name,
                           destination_file_path,
                           file_gapi,
                           destination_kms_key_name: destination_kms_key,
                           destination_predefined_acl: acl,
                           source_generation: generation,
                           if_generation_match: if_generation_match,
                           if_generation_not_match: if_generation_not_match,
                           if_metageneration_match: if_metageneration_match,
                           if_metageneration_not_match: if_metageneration_not_match,
                           if_source_generation_match: if_source_generation_match,
                           if_source_generation_not_match: if_source_generation_not_match,
                           if_source_metageneration_match: if_source_metageneration_match,
                           if_source_metageneration_not_match: if_source_metageneration_not_match,
                           rewrite_token: token,
                           user_project: user_project(user_project),
                           options: options
  end
end