Reputation: 5806
I want to exclude a directory in documents storage class from backup.
Setting exclusion attribute like so
+ (BOOL)kit_addSkipBackupAttributeForItemAtURL:(NSURL *)url
{
if (![[NSFileManager defaultManager] fileExistsAtPath:url.path]) {
return NO;
}
NSError *error = nil;
NSNumber *value = nil;
BOOL success = [url getResourceValue:&value forKey:NSURLIsExcludedFromBackupKey error:&error];
if (value.boolValue == YES) {
NSLog(@"ALREADY Excluded %@ from backup", [url absoluteString]);
return YES;
}
success = [url setResourceValue:@(YES)
forKey:NSURLIsExcludedFromBackupKey
error:&error];
if (!success){
NSLog(@"Error excluding %@ from backup: %@", [url lastPathComponent], error);
}
success = [url getResourceValue:&value
forKey:NSURLIsExcludedFromBackupKey
error:&error];
NSAssert(success, @"The backup exclusion attribute is missing");
NSLog(@"Excluding %@ from backup", [url absoluteString]);
NSAssert(value.boolValue, @"The backup exclusion attribute is false");
return success;
}
does trip: value.boolValue is NO and listing the directory later on using ls -la@ {directoryname} does not show that attribute. Somehow it does not stick for some items in the filesystem (within the same storage class!).
Upvotes: 0
Views: 39
Reputation: 5806
Resolved: Application Support storage class was created exactly for these no man's land cases when data does not need to be purged and yet it is not important enough to be backed up in its entirety (not a document created by this user and unavailable anywhere else).
Upvotes: 0