Skip to content

Instantly share code, notes, and snippets.

@naokits
Created December 21, 2011 07:51
Show Gist options
  • Save naokits/1505121 to your computer and use it in GitHub Desktop.
Save naokits/1505121 to your computer and use it in GitHub Desktop.
「do not backup」 属性をディレクトリにマークするスニペットコード
- (void)sampleAddAttributeToFolder
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *baseDir = [self paperStandDocumentsBasePath];
NSError *error;
BOOL result = [fileManager createDirectoryAtPath:baseDir
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (result) {
NSURL *url = [NSURL fileURLWithPath:baseDir];
if ([self addSkipBackupAttributeToItemAtURL:url]) {
NSLog(@"success! could add do not backup attribute to folder");
}
}
/// <Application_Home>/Library/Private Documents/PapaerStand
#define kPaperStandDocumentsBaseName @"PaperStand"
- (NSString *)paperStandDocumentsBasePath
{
NSString *libraryPath;
libraryPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library"];
NSString *privateDocumenstPath;
privateDocumenstPath = [libraryPath stringByAppendingPathComponent:@"Private Documents"];
NSString *myDocumentsPath;
myDocumentsPath = [privateDocumenstPath stringByAppendingPathComponent:kPaperStandDocumentsBaseName];
return myDocumentsPath;
}
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
if (URL == nil) {
return NO;
} else if (![URL isFileURL]){
return NO;
}
u_int8_t b = 1;
int result = setxattr([[URL path] fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
if (result == 0) {
LOG(@"success result:%d path:%@", result, [URL path]);
} else {
LOG(@"failur result:%d path:%@", result, [URL path]);
}
return result == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment