PDA

View Full Version : [Resolved] Setting NSDocumentDirectory so it doesn't backup to iCloud




troop231
Aug 24, 2012, 11:30 AM
Hello, I'm trying to mark the entire folder of my app's NSDocumentDirectory so that it is excluded from the iCloud backup, but when I go to the terminal and run: xattr -plxv com.apple.MobileBackup <file name goes here> I get this error: No such xattr: com.apple.MobileBackup

Here is the code I'm using:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSURL *pathURL= [NSURL fileURLWithPath:documentsDirectory];

[self addSkipBackupAttributeToItemAtURL:pathURL];
}

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1
const char* filePath = [[URL path] fileSystemRepresentation];

const char* attrName = "com.apple.MobileBackup";
u_int8_t attrValue = 1;

int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
return result == 0;
} else { // iOS >= 5.1

NSLog(@"%d",[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil]);
return [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];
}
}



I appreciate any help offered.



chown33
Aug 24, 2012, 12:14 PM
Hello, I'm trying to mark the entire folder of my app's NSDocumentDirectory so that it is excluded from the iCloud backup, but when I go to the terminal and run: xattr -plxv com.apple.MobileBackup <file name goes here> I get this error: No such xattr: com.apple.MobileBackup

I suggest starting with a simple listing of all xattrs on the target file. This is a basic debugging principle: start broadly and narrow it down with evidence. If you start broadly by listing all xattrs, you can then proceed to narrow it down to a specific xattr's value. The key point is to get the initial evidence of ALL xattrs, instead of assuming one.

If the target file has no xattrs, then change your code to show the actual pathname, because the real pathname might not be what you expect. Confirm your expectations by getting evidence (another basic debugging principle).

troop231
Aug 24, 2012, 01:12 PM
I suggest starting with a simple listing of all xattrs on the target file. This is a basic debugging principle: start broadly and narrow it down with evidence. If you start broadly by listing all xattrs, you can then proceed to narrow it down to a specific xattr's value. The key point is to get the initial evidence of ALL xattrs, instead of assuming one.

If the target file has no xattrs, then change your code to show the actual pathname, because the real pathname might not be what you expect. Confirm your expectations by getting evidence (another basic debugging principle).

These are all the xattr's that are on the file:

com.apple.FinderInfo
com.apple.Preview.UIstate.v1
com.apple.metadata:kMDItemDownloadedDate
com.apple.metadata:kMDItemWhereFroms

chown33
Aug 24, 2012, 01:22 PM
These are all the xattr's that are on the file:

com.apple.FinderInfo
com.apple.Preview.UIstate.v1
com.apple.metadata:kMDItemDownloadedDate
com.apple.metadata:kMDItemWhereFroms

What pathname did you use in the xattr command-line?

What is the actual pathname used when the code runs?

What is the actual value being returned by addSkipBackupAttributeToItemAtURL? You go to some trouble to return a success/fail indicator, then you never check it. That's another elementary debugging principle: checking for errors instead of ignoring them.

What is the NSLog output when the code runs? I.e. what's the evidence that the sextattr() is being performed, vs. the setResourceValue:? You may think setResourceValue: does the same thing as setxattr(), but what's your evidence?