pycontribs / pyrax

The Python SDK for the Rackspace Cloud
developer.rackspace.com
Apache License 2.0
237 stars 209 forks source link

Cloudfiles sync_folder_to_container() does not remove non existent source files #558

Open itsmemattchung opened 9 years ago

itsmemattchung commented 9 years ago

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:

  1. Create sample_container directory on local computer
  2. Under sample_container, create following files: 1.txt and 2.txt
  3. execute sync_folder_to_container()
  4. 1.txt and 2.txt are in the container
  5. delete 2.txt
  6. create 3.txt
  7. sync_folder_to_container()
  8. 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)
EdLeafe commented 9 years ago

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.

itsmemattchung commented 9 years ago

Cancelled first pull request since it was destined for "master" branch instead of "working"