From a7606eb5e289de68ea8caa485a2563df0529830f Mon Sep 17 00:00:00 2001 From: huangboju Date: Wed, 1 Apr 2020 14:38:22 +0800 Subject: [PATCH 1/2] simplify code --- SDWebImage/Private/SDFileAttributeHelper.m | 78 +++++++++++----------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/SDWebImage/Private/SDFileAttributeHelper.m b/SDWebImage/Private/SDFileAttributeHelper.m index 45c015e0..65ecacd7 100644 --- a/SDWebImage/Private/SDFileAttributeHelper.m +++ b/SDWebImage/Private/SDFileAttributeHelper.m @@ -17,15 +17,15 @@ ssize_t nameBuffLen = listxattr([path fileSystemRepresentation], NULL, 0, flags); if (nameBuffLen == -1) { if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo: - [NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithUTF8String:strerror(errno)], @"error", - @"listxattr", @"function", - path, @":path", - [NSNumber numberWithBool:follow], @":traverseLink", - nil] - ]; + @{ + @"error": [NSString stringWithUTF8String:strerror(errno)], + @"function": @"listxattr", + @":path": path, + @":traverseLink": @(follow) + } + ]; return nil; - } else if (nameBuffLen == 0) return [NSArray array]; + } else if (nameBuffLen == 0) return @[]; // get name list NSMutableData *nameBuff = [NSMutableData dataWithLength:nameBuffLen]; @@ -36,7 +36,7 @@ char *nextName, *endOfNames = [nameBuff mutableBytes] + nameBuffLen; for(nextName = [nameBuff mutableBytes]; nextName < endOfNames; nextName += 1+strlen(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 { @@ -46,13 +46,13 @@ ssize_t nameBuffLen = listxattr([path fileSystemRepresentation], NULL, 0, flags); if (nameBuffLen == -1) { if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo: - [NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithUTF8String:strerror(errno)], @"error", - @"listxattr", @"function", - path, @":path", - [NSNumber numberWithBool:follow], @":traverseLink", - nil] - ]; + @{ + @"error": [NSString stringWithUTF8String:strerror(errno)], + @"function": @"listxattr", + @":path": path, + @":traverseLink": @(follow) + } + ]; return NO; } else if (nameBuffLen == 0) return NO; @@ -73,13 +73,13 @@ ssize_t attrLen = getxattr([path fileSystemRepresentation], [name UTF8String], NULL, 0, 0, flags); if (attrLen == -1) { if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo: - [NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithUTF8String:strerror(errno)], @"error", - @"getxattr", @"function", - name, @":name", - path, @":path", - [NSNumber numberWithBool:follow], @":traverseLink", - nil] + @{ + @"error": [NSString stringWithUTF8String:strerror(errno)], + @"function": @"getxattr", + @":name": name, + @":path": path, + @":traverseLink": @(follow) + } ]; return nil; } @@ -95,15 +95,15 @@ if (0 == setxattr([path fileSystemRepresentation], [name UTF8String], [value bytes], [value length], 0, flags)) return YES; // error if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo: - [NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithUTF8String:strerror(errno)], @"error", - @"setxattr", @"function", - name, @":name", - [NSNumber numberWithUnsignedInteger:[value length]], @":value.length", - path, @":path", - [NSNumber numberWithBool:follow], @":traverseLink", - [NSNumber numberWithBool:overwrite], @":overwrite", - nil] + @{ + @"error": [NSString stringWithUTF8String:strerror(errno)], + @"function": @"setxattr", + @":name": name, + @":value.length": [NSNumber numberWithUnsignedInteger:[value length]], + @":path": path, + @":traverseLink": @(follow), + @":overwrite": @(overwrite) + } ]; return NO; } @@ -113,13 +113,13 @@ if (0 == removexattr([path fileSystemRepresentation], [name UTF8String], flags)) return YES; // error if (err) *err = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo: - [NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithUTF8String:strerror(errno)], @"error", - @"removexattr", @"function", - name, @":name", - path, @":path", - [NSNumber numberWithBool:follow], @":traverseLink", - nil] + @{ + @"error": [NSString stringWithUTF8String:strerror(errno)], + @"function": @"removexattr", + @":name": name, + @":path": path, + @":traverseLink": @(follow) + } ]; return NO; } From 45be39f4a1dcb5869014a757879e0df3a64e6837 Mon Sep 17 00:00:00 2001 From: huangboju Date: Thu, 2 Apr 2020 10:15:12 +0800 Subject: [PATCH 2/2] Update SDFileAttributeHelper.m --- SDWebImage/Private/SDFileAttributeHelper.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage/Private/SDFileAttributeHelper.m b/SDWebImage/Private/SDFileAttributeHelper.m index 65ecacd7..5122089d 100644 --- a/SDWebImage/Private/SDFileAttributeHelper.m +++ b/SDWebImage/Private/SDFileAttributeHelper.m @@ -99,7 +99,7 @@ @"error": [NSString stringWithUTF8String:strerror(errno)], @"function": @"setxattr", @":name": name, - @":value.length": [NSNumber numberWithUnsignedInteger:[value length]], + @":value.length": @(value.length), @":path": path, @":traverseLink": @(follow), @":overwrite": @(overwrite)