simplify code
This commit is contained in:
parent
0335b96114
commit
a7606eb5e2
|
@ -17,15 +17,15 @@
|
||||||
ssize_t nameBuffLen = listxattr([path fileSystemRepresentation], NULL, 0, flags);
|
ssize_t nameBuffLen = listxattr([path fileSystemRepresentation], NULL, 0, flags);
|
||||||
if (nameBuffLen == -1) {
|
if (nameBuffLen == -1) {
|
||||||
if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:
|
if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:
|
||||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
@{
|
||||||
[NSString stringWithUTF8String:strerror(errno)], @"error",
|
@"error": [NSString stringWithUTF8String:strerror(errno)],
|
||||||
@"listxattr", @"function",
|
@"function": @"listxattr",
|
||||||
path, @":path",
|
@":path": path,
|
||||||
[NSNumber numberWithBool:follow], @":traverseLink",
|
@":traverseLink": @(follow)
|
||||||
nil]
|
}
|
||||||
];
|
];
|
||||||
return nil;
|
return nil;
|
||||||
} else if (nameBuffLen == 0) return [NSArray array];
|
} else if (nameBuffLen == 0) return @[];
|
||||||
|
|
||||||
// get name list
|
// get name list
|
||||||
NSMutableData *nameBuff = [NSMutableData dataWithLength:nameBuffLen];
|
NSMutableData *nameBuff = [NSMutableData dataWithLength:nameBuffLen];
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
char *nextName, *endOfNames = [nameBuff mutableBytes] + nameBuffLen;
|
char *nextName, *endOfNames = [nameBuff mutableBytes] + nameBuffLen;
|
||||||
for(nextName = [nameBuff mutableBytes]; nextName < endOfNames; nextName += 1+strlen(nextName))
|
for(nextName = [nameBuff mutableBytes]; nextName < endOfNames; nextName += 1+strlen(nextName))
|
||||||
[names addObject:[NSString stringWithUTF8String:nextName]];
|
[names addObject:[NSString stringWithUTF8String:nextName]];
|
||||||
return [NSArray arrayWithArray:names];
|
return names.copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (BOOL)hasExtendedAttribute:(NSString *)name atPath:(NSString *)path traverseLink:(BOOL)follow error:(NSError **)err {
|
+ (BOOL)hasExtendedAttribute:(NSString *)name atPath:(NSString *)path traverseLink:(BOOL)follow error:(NSError **)err {
|
||||||
|
@ -46,12 +46,12 @@
|
||||||
ssize_t nameBuffLen = listxattr([path fileSystemRepresentation], NULL, 0, flags);
|
ssize_t nameBuffLen = listxattr([path fileSystemRepresentation], NULL, 0, flags);
|
||||||
if (nameBuffLen == -1) {
|
if (nameBuffLen == -1) {
|
||||||
if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:
|
if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:
|
||||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
@{
|
||||||
[NSString stringWithUTF8String:strerror(errno)], @"error",
|
@"error": [NSString stringWithUTF8String:strerror(errno)],
|
||||||
@"listxattr", @"function",
|
@"function": @"listxattr",
|
||||||
path, @":path",
|
@":path": path,
|
||||||
[NSNumber numberWithBool:follow], @":traverseLink",
|
@":traverseLink": @(follow)
|
||||||
nil]
|
}
|
||||||
];
|
];
|
||||||
return NO;
|
return NO;
|
||||||
} else if (nameBuffLen == 0) return NO;
|
} else if (nameBuffLen == 0) return NO;
|
||||||
|
@ -73,13 +73,13 @@
|
||||||
ssize_t attrLen = getxattr([path fileSystemRepresentation], [name UTF8String], NULL, 0, 0, flags);
|
ssize_t attrLen = getxattr([path fileSystemRepresentation], [name UTF8String], NULL, 0, 0, flags);
|
||||||
if (attrLen == -1) {
|
if (attrLen == -1) {
|
||||||
if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:
|
if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:
|
||||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
@{
|
||||||
[NSString stringWithUTF8String:strerror(errno)], @"error",
|
@"error": [NSString stringWithUTF8String:strerror(errno)],
|
||||||
@"getxattr", @"function",
|
@"function": @"getxattr",
|
||||||
name, @":name",
|
@":name": name,
|
||||||
path, @":path",
|
@":path": path,
|
||||||
[NSNumber numberWithBool:follow], @":traverseLink",
|
@":traverseLink": @(follow)
|
||||||
nil]
|
}
|
||||||
];
|
];
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
@ -95,15 +95,15 @@
|
||||||
if (0 == setxattr([path fileSystemRepresentation], [name UTF8String], [value bytes], [value length], 0, flags)) return YES;
|
if (0 == setxattr([path fileSystemRepresentation], [name UTF8String], [value bytes], [value length], 0, flags)) return YES;
|
||||||
// error
|
// error
|
||||||
if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:
|
if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:
|
||||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
@{
|
||||||
[NSString stringWithUTF8String:strerror(errno)], @"error",
|
@"error": [NSString stringWithUTF8String:strerror(errno)],
|
||||||
@"setxattr", @"function",
|
@"function": @"setxattr",
|
||||||
name, @":name",
|
@":name": name,
|
||||||
[NSNumber numberWithUnsignedInteger:[value length]], @":value.length",
|
@":value.length": [NSNumber numberWithUnsignedInteger:[value length]],
|
||||||
path, @":path",
|
@":path": path,
|
||||||
[NSNumber numberWithBool:follow], @":traverseLink",
|
@":traverseLink": @(follow),
|
||||||
[NSNumber numberWithBool:overwrite], @":overwrite",
|
@":overwrite": @(overwrite)
|
||||||
nil]
|
}
|
||||||
];
|
];
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
@ -113,13 +113,13 @@
|
||||||
if (0 == removexattr([path fileSystemRepresentation], [name UTF8String], flags)) return YES;
|
if (0 == removexattr([path fileSystemRepresentation], [name UTF8String], flags)) return YES;
|
||||||
// error
|
// error
|
||||||
if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:
|
if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:
|
||||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
@{
|
||||||
[NSString stringWithUTF8String:strerror(errno)], @"error",
|
@"error": [NSString stringWithUTF8String:strerror(errno)],
|
||||||
@"removexattr", @"function",
|
@"function": @"removexattr",
|
||||||
name, @":name",
|
@":name": name,
|
||||||
path, @":path",
|
@":path": path,
|
||||||
[NSNumber numberWithBool:follow], @":traverseLink",
|
@":traverseLink": @(follow)
|
||||||
nil]
|
}
|
||||||
];
|
];
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue