copy from iCloud to sandbox fails
copy from iCloud to sandbox fails
- Subject: copy from iCloud to sandbox fails
- From: Roland King <email@hidden>
- Date: Mon, 09 Apr 2012 13:15:53 +0800
I allow my users to turn iCloud on and off. When they turn it off, it allows you to either move the contents of iCloud locally, removing it from the cloud, or copy it, so any other devices still using the cloud version can continue to use it. The move seems to work just fine using NSFileManager's setUbiquitous:itemAtURL:error, but I'm failing to get the copy working, here's the code ..
(void)copyICloudToSandbox:(id<HIPDatabaseDelegate>)delegate completion:(void (^)(void))completion
{
[ delegate message:@"copying iCloud to the local database" ];
NSURL *sandboxDocumentURL = [ self documentsURLUbiquitous:NO ];
NSURL *iCloudDocumentURL = [ self documentsURLUbiquitous:YES ];
dispatch_async( dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
NSError *error;
[ [ NSFileManager defaultManager ] copyItemAtURL:iCloudDocumentURL toURL:sandboxDocumentURL error:&error ];
dispatch_async( dispatch_get_main_queue(), ^{
[ delegate message:@"copied iCloud to local" ];
if( completion )
completion();
} );
} );
}
the sandboxDocumentURL and iCloudDocumentURL are what you'd expect them to be. The data in the documents directory is in subdirectories per document and the copy starts fine, it creates the first subdirectory, then creates the 'StoreContent' subdirectory under that, I can see that from Xcode showing me what's on the device. When it comes however to copy the data file, called topicStore, it fails with cocoa error 512, printing out the error message shows the following
(lldb) po sandboxDocumentURL
(NSURL *) $4 = 0x0022e350 file://localhost/var/mobile/Applications/84768B6A-1F63-4EFA-BEF2-2F64EB723085/Documents/
(lldb) po iCloudDocumentURL
(NSURL *) $5 = 0x0de24710 file://localhost/private/var/mobile/Library/Mobile Documents/LD65ZXD7W6~com~dotteddogsoft~hippocampus/Documents/
(lldb) po error
(NSError *) $14 = 0x0ee6bd70 Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0xee64050 {NSUserStringVariant=(
Copy
), NSFilePath=/private/var/mobile/Library/Mobile Documents/LD65ZXD7W6~com~dotteddogsoft~hippocampus/Documents/2525AED0-415B-49C8-9CFB-2E0361ADDACF.hippocampus/StoreContent/topicStore, NSDestinationFilePath=/var/mobile/Applications/77AF614B-90EE-4B71-8531-8E61076B0F83/Documents/2525AED0-415B-49C8-9CFB-2E0361ADDACF.hippocampus/StoreContent/topicStore, NSUnderlyingError=0xee69da0 "The operation couldn’t be completed. Bad file descriptor"}
This doesn't tell me very much. Directories work, but the files don't copy. Can I just not use copyItemAtURL: to copy a whole tree out of the private iCloud store, or is there something I need to do first? I didn't really want to write my own recursive copy routine. I did try wrapping the whole thing with an NSFileCoordinator block too but that didn't help.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden