1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Add Object Storage container sync feature.

This commit is contained in:
Rupak Ganguly 2013-03-11 16:24:01 -04:00
parent fdf49245ee
commit 01d3c4df44

View file

@ -207,12 +207,33 @@ module Fog
end end
end end
def sync(target_dir, secret)
requires :key
# do not sync if dir is same as target dir
return false if target_dir.key == key
begin service.head_container(key)
if !target_dir.nil? && target_dir.is_a?(Fog::Storage::HP::Directory) && target_dir.respond_to?(:public_url) && !target_dir.public_url.nil?
# set sync metadata on source dir
self.sync_to = target_dir.public_url
self.sync_key = secret
# set sync metadata on target dir
target_dir.sync_key = secret
target_dir.save
true
else
false
end
rescue Fog::Storage::HP::NotFound
false
end
end
def save(options = {}) def save(options = {})
requires :key requires :key
# write out the acls into the headers before save # write out the acls into the headers before save
options.merge!(service.perm_acl_to_header(@read_acl, @write_acl)) options.merge!(service.perm_acl_to_header(@read_acl, @write_acl))
options.merge!({'X-Container-Sync-To' => sync_to}) unless sync_to.nil? options.merge!({'X-Container-Sync-To' => self.sync_to}) unless self.sync_to.nil?
options.merge!({'X-Container-Sync-Key' => sync_key}) unless sync_key.nil? options.merge!({'X-Container-Sync-Key' => self.sync_key}) unless self.sync_key.nil?
service.put_container(key, options) service.put_container(key, options)
# Added an extra check to see if CDN is enabled for the container # Added an extra check to see if CDN is enabled for the container
if (!service.cdn.nil? && service.cdn.enabled?) if (!service.cdn.nil? && service.cdn.enabled?)