pyrax
pyrax copied to clipboard
Cloudfiles sync_folder_to_container() does not remove non existent source files
When files are deleting from the "source", and sync_folder_to_container() executes, files at the destination but not at the source are not removed.
Example:
- Create
sample_containerdirectory on local computer - Under
sample_container, create following files: 1.txt and 2.txt - execute sync_folder_to_container()
- 1.txt and 2.txt are in the container
- delete 2.txt
- create 3.txt
- sync_folder_to_container()
- 2.txt still exists and 3.txt has been uploaded
(pyrax)matts-mbp-2:pyrax_cloud_sync mattchung$ rm sample_container/touch2.txt
(pyrax)matts-mbp-2:pyrax_cloud_sync mattchung$ touch sample_container/touch3.txt
#!/usr/bin/env python
import os
import pyrax
pyrax.set_setting('identity_type', 'rackspace')
pyrax.set_credentials(os.getenv('RAX_USERNAME') or os.getenv('OS_USERNAME'), os.getenv('RAX_API_KEY') or os.getenv('OS_PASSWORD'))
cf = pyrax.cloudfiles
local = 'sample_container'
remote = cf.create_container('sample_container')
cf.sync_folder_to_container(local, remote)
You need to include the parameter 'delete' if you want remote files to be deleted. The default is 'delete=False'; change that to 'delete=True' and it should work.
Cancelled first pull request since it was destined for "master" branch instead of "working"