Use COPY method instead of GET and PUT
This commit is contained in:
@@ -82,15 +82,12 @@ class Migrator
|
|||||||
|
|
||||||
def copy_document(directory, document)
|
def copy_document(directory, document)
|
||||||
old_document_url = "#{url_for_directory(@username, directory)}/#{escape(document)}"
|
old_document_url = "#{url_for_directory(@username, directory)}/#{escape(document)}"
|
||||||
new_document_url = "#{new_url_for_directory(@username, directory)}/#{escape(document)}"
|
|
||||||
|
|
||||||
logger.debug "Copying document from #{old_document_url} to #{new_document_url}"
|
full_path = [directory, document].reject(&:empty?).join('/')
|
||||||
|
new_document_path = "rs:documents:#{environment.to_s.downcase}/#{@username}/#{escape(full_path)}"
|
||||||
|
|
||||||
response = do_get_request(old_document_url)
|
logger.debug "Copying document from #{old_document_url} to #{new_document_path}"
|
||||||
|
do_copy_request(old_document_url, new_document_path) unless dry_run
|
||||||
unless dry_run
|
|
||||||
do_put_request(new_document_url, response.body, response.headers[:content_type])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def redis
|
def redis
|
||||||
@@ -123,6 +120,14 @@ class Migrator
|
|||||||
RestClient.put(url, data, default_headers.merge({content_type: content_type}))
|
RestClient.put(url, data, default_headers.merge({content_type: content_type}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def do_copy_request(url, destination_path)
|
||||||
|
RestClient::Request.execute(
|
||||||
|
method: :copy,
|
||||||
|
url: url,
|
||||||
|
headers: default_headers.merge({destination: destination_path})
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def default_headers
|
def default_headers
|
||||||
{"x-auth-token" => @swift_token}
|
{"x-auth-token" => @swift_token}
|
||||||
end
|
end
|
||||||
@@ -139,18 +144,6 @@ class Migrator
|
|||||||
"#{base_url}/#{container_for(user)}"
|
"#{base_url}/#{container_for(user)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_container_url_for(user)
|
|
||||||
"#{base_url}/rs:documents:#{environment.to_s.downcase}/#{user}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def new_url_for_directory(user, directory)
|
|
||||||
if directory.empty?
|
|
||||||
new_container_url_for(user)
|
|
||||||
else
|
|
||||||
"#{new_container_url_for(user)}/#{escape(directory)}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def base_url
|
def base_url
|
||||||
@base_url ||= @swift_host
|
@base_url ||= @swift_host
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user