mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[ninefold|storage] Update an existing file
This commit is contained in:
parent
ef44cd0b38
commit
86f8b2a20c
4 changed files with 44 additions and 3 deletions
|
@ -71,9 +71,14 @@ module Fog
|
||||||
directory.kind_of?(Directory) ? ns = directory.key : ns = directory
|
directory.kind_of?(Directory) ? ns = directory.key : ns = directory
|
||||||
ns += key
|
ns += key
|
||||||
options['Content-Type'] = content_type if content_type
|
options['Content-Type'] = content_type if content_type
|
||||||
data = connection.post_namespace(ns, :body => body)
|
if objectid
|
||||||
#p data
|
# pre-existing file, do a PUT
|
||||||
self.objectid = data.headers['location'].split('/')[-1]
|
data = connection.put_namespace(ns, :body => body)
|
||||||
|
else
|
||||||
|
# new file, POST
|
||||||
|
data = connection.post_namespace(ns, :body => body)
|
||||||
|
self.objectid = data.headers['location'].split('/')[-1]
|
||||||
|
end
|
||||||
merge_attributes(data.headers)
|
merge_attributes(data.headers)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,6 +21,7 @@ module Fog
|
||||||
# request :delete_container
|
# request :delete_container
|
||||||
request :get_namespace
|
request :get_namespace
|
||||||
request :post_namespace
|
request :post_namespace
|
||||||
|
request :put_namespace
|
||||||
request :delete_namespace
|
request :delete_namespace
|
||||||
|
|
||||||
module Utils
|
module Utils
|
||||||
|
|
20
lib/fog/storage/requests/ninefold/put_namespace.rb
Normal file
20
lib/fog/storage/requests/ninefold/put_namespace.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
module Fog
|
||||||
|
module Storage
|
||||||
|
class Ninefold
|
||||||
|
class Real
|
||||||
|
|
||||||
|
def put_namespace(namespace = '', options = {})
|
||||||
|
options = options.reject {|key, value| value.nil?}
|
||||||
|
request({
|
||||||
|
:expects => 200,
|
||||||
|
:method => 'PUT',
|
||||||
|
:path => "namespace/" + namespace,
|
||||||
|
:query => {},
|
||||||
|
:parse => true
|
||||||
|
}.merge(options))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
15
tests/storage/models/ninefold/file_update_tests.rb
Normal file
15
tests/storage/models/ninefold/file_update_tests.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
if storage_providers.keys.include? :ninefold
|
||||||
|
for provider, config in storage_providers
|
||||||
|
|
||||||
|
Shindo.tests("Storage[:ninefold] | nested directories", [provider]) do
|
||||||
|
ninefold = Fog::Storage[:ninefold]
|
||||||
|
tests("update a file").succeeds do
|
||||||
|
dir = ninefold.directories.create(:key => 'updatefiletests')
|
||||||
|
f = dir.files.create(:key => 'lorem.txt', :body => lorem_file)
|
||||||
|
f.body = "xxxxxx"
|
||||||
|
f.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue