Created
November 29, 2012 14:24
-
-
Save billymeltdown/4169422 to your computer and use it in GitHub Desktop.
Can run afoul of cross-device link error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSURL *remoteFileURL = [[self temporaryDocumentsURL] URLByAppendingPathComponent:ZTDropboxRemoteFileName]; | |
NSURL *databaseFileURL = [[self dropboxFolderURL] URLByAppendingPathComponent:self.dbFileName]; | |
NSError *error; | |
BOOL success = NO; | |
NSFileManager *fm = [NSFileManager defaultManager]; | |
// if this isn't our first time, use replaceItem... | |
if ([databaseFileURL checkResourceIsReachableAndReturnError:&error]) | |
{ | |
NSURL *newItemURL; | |
success = [fm replaceItemAtURL:databaseFileURL | |
withItemAtURL:remoteFileURL | |
backupItemName:nil | |
options:0 | |
resultingItemURL:&newItemURL | |
error:&error]; | |
} | |
else // just do a plain-ol' copy | |
{ | |
success = [fm copyItemAtURL: remoteFileURL | |
toURL: databaseFileURL | |
error: &error]; | |
// ... | |
} |
When replacing an item on an attached volume, you get:
NSUnderlyingError=0x105b0abd0 “The operation couldn’t be completed. Cross-device link”
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
self.dropboxFolderURL is chosen by the user with NSOpenPanel running in Sandbox, so it is security-scoped. It's either supplied directly by the user, or retrieved from a security-scoped bookmark stored as NSData in NSUserDefaults.