Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding the "Do Not Backup" attribute to a folder hierarchy in iOS 5.0.1

Tags:

ios

iphone

Referencing iCloud + Storage of media in iPhone Documents folder, which shows how to set the iOS 5.0.1 "Do Not Backup" attribute for a file.

Is there an efficient way to do this for an entire folder/file hierarchy? E.g., my app creates /Library/PrivateDocs, and populates that with several folders, sub-folders, and files. Can I just set the do-not-backup attribute on the top-level folder, or must it be set on every individual file and folder under that also?

And, if it must be set on each file/subfolder, what's an efficient way to do so?

like image 433
Don Jones Avatar asked Jan 01 '12 16:01

Don Jones


1 Answers

You could put one specific directory inside the documents dir for this purpose, put everything inside and only mark that single directory as do-not-backup using the

 addSkipBackupAttributeToItemAtURL

method shown in the article you linked, or use this one that uses a path instead of an URL:

+ (void)addSkipBackupAttributeToPath:(NSString*)path {
    u_int8_t b = 1;
    setxattr([path fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
}

example using a directory:

NSString *docsDirPath = [(AppDelegate*)[[UIApplication sharedApplication] delegate] applicationDocumentsDirectory];
NSString *yourContentsDirPath = [docsDirPath stringByAppendingPathComponent:gContentsDirName];

[Utilities addSkipBackupAttributeToPath:yourContentsDirPath];

[EDIT]

I forgot this method use in the delegate to get the documents dir:

- (NSString *)applicationDocumentsDirectory {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    return basePath;
}
like image 146
k1th Avatar answered Oct 08 '22 09:10

k1th