From 0f0c956e1636ee501369cc04f59f2075b709e0e3 Mon Sep 17 00:00:00 2001 From: Stefan Reitshamer Date: Mon, 13 Nov 2017 06:46:16 -0500 Subject: [PATCH] return nil instead of NO --- ArqRestoreCommand.m | 4 ++-- cocoastack/crypto/SHA1Hash.m | 2 +- cocoastack/plist/XMLPListReader.m | 4 ++-- cocoastack/remotefs/LocalItemFS.m | 14 +++++++------- cocoastack/s3/S3Lister.m | 6 +++--- cocoastack/shared/LZ4Compressor.m | 4 ++-- glacierrestore/GlacierPackIndex.m | 4 ++-- glacierrestore/GlacierPackSet.m | 2 +- glacierrestore/GlacierRestorer.m | 4 ++-- repo/ObjectEncryptorV1.m | 2 +- repo/ObjectEncryptorV2.m | 12 ++++++------ repo/PackSet.m | 2 +- repo/PackSetDB.m | 2 +- 13 files changed, 31 insertions(+), 31 deletions(-) diff --git a/ArqRestoreCommand.m b/ArqRestoreCommand.m index b9d82d0..e4b5494 100644 --- a/ArqRestoreCommand.m +++ b/ArqRestoreCommand.m @@ -610,7 +610,7 @@ - (BackupSet *)backupSetForTarget:(Target *)theInitialTarget computerUUID:(NSString *)theComputerUUID error:(NSError **)error { NSArray *expandedTargetList = [self expandedTargetListForTarget:theInitialTarget error:error]; if (expandedTargetList == nil) { - return NO; + return nil; } for (Target *theTarget in expandedTargetList) { @@ -622,7 +622,7 @@ } else { HSLogError(@"error getting backup sets for %@: %@", theTarget, myError); SETERRORFROMMYERROR; - return NO; + return nil; } } else { for (BackupSet *backupSet in backupSets) { diff --git a/cocoastack/crypto/SHA1Hash.m b/cocoastack/crypto/SHA1Hash.m index 60e1400..9b60971 100644 --- a/cocoastack/crypto/SHA1Hash.m +++ b/cocoastack/crypto/SHA1Hash.m @@ -68,7 +68,7 @@ int errnum = errno; HSLogError(@"lstat(%@) error %d: %s", path, errnum, strerror(errnum)); SETNSERROR(@"UnixErrorDomain", errnum, @"%@: %s", path, strerror(errnum)); - return NO; + return nil; } unsigned long long length = (unsigned long long)st.st_size; FileInputStream *fis = [[FileInputStream alloc] initWithPath:path offset:0 length:length]; diff --git a/cocoastack/plist/XMLPListReader.m b/cocoastack/plist/XMLPListReader.m index 2bcec1a..0a0c6f2 100644 --- a/cocoastack/plist/XMLPListReader.m +++ b/cocoastack/plist/XMLPListReader.m @@ -109,7 +109,7 @@ id node = [self makeNode:childNode error:error]; if (!node) { [nodes release]; - return NO; + return nil; } [nodes addObject:node]; } @@ -134,7 +134,7 @@ } else { id node = [self makeNode:childNode error:error]; if (!node) { - return NO; + return nil; } NSAssert(key != nil, @"must have key before adding value"); [dn put:node forKey:key]; diff --git a/cocoastack/remotefs/LocalItemFS.m b/cocoastack/remotefs/LocalItemFS.m index 50a0977..73d8c6c 100644 --- a/cocoastack/remotefs/LocalItemFS.m +++ b/cocoastack/remotefs/LocalItemFS.m @@ -161,7 +161,7 @@ int errnum = errno; HSLogError(@"chown(%@) error %d: %s", thePath, errnum, strerror(errnum)); SETNSERROR(@"UnixErrorDomain", errnum, @"failed to change ownership of %@: %s", thePath, strerror(errnum)); - return NO; + return nil; } } @@ -200,14 +200,14 @@ if (![self ensureTempDirExists:&myError]) { SETERRORFROMMYERROR; HSLogError(@"error ensuring temp dir %@ exists: %@", tempDir, myError); - return NO; + return nil; } NSString *tempPath = [tempDir stringByAppendingPathComponent:[NSString stringWithRandomUUID]]; if (![theData writeToFile:tempPath options:NSAtomicWrite error:&myError]) { SETERRORFROMMYERROR; HSLogError(@"error creating temp file %@: %@", tempPath, myError); - return NO; + return nil; } if (![[NSFileManager defaultManager] ensureParentPathExistsForPath:theFullPath targetUID:[[CacheOwnership sharedCacheOwnership] uid] targetGID:[[CacheOwnership sharedCacheOwnership] gid] error:error]) { @@ -217,21 +217,21 @@ if (![myError isErrorWithDomain:NSCocoaErrorDomain code:NSFileWriteFileExistsError]) { SETERRORFROMMYERROR; HSLogError(@"error renaming %@ to %@: %@", tempPath, theFullPath, myError); - return NO; + return nil; } // Delete the file that's in the way. HSLogDebug(@"deleting existing file before overwriting: %@", theFullPath); if (![[NSFileManager defaultManager] removeItemAtPath:theFullPath error:&myError]) { SETERRORFROMMYERROR; HSLogError(@"error removing a file that's in the way (%@): %@", theFullPath, myError); - return NO; + return nil; } // Try again. if (![[NSFileManager defaultManager] moveItemAtPath:tempPath toPath:theFullPath error:&myError]) { if (![myError isErrorWithDomain:NSCocoaErrorDomain code:NSFileWriteFileExistsError]) { SETERRORFROMMYERROR; HSLogError(@"error renaming %@ to %@: %@", tempPath, theFullPath, myError); - return NO; + return nil; } } } @@ -246,7 +246,7 @@ int errnum = errno; HSLogError(@"chown(%@) error %d: %s", theFullPath, errnum, strerror(errnum)); SETNSERROR(@"UnixErrorDomain", errnum, @"failed to change ownership of %@: %s", theFullPath, strerror(errnum)); - return NO; + return nil; } } Item *item = [[[Item alloc] init] autorelease]; diff --git a/cocoastack/s3/S3Lister.m b/cocoastack/s3/S3Lister.m index 03d28ed..fc1f355 100644 --- a/cocoastack/s3/S3Lister.m +++ b/cocoastack/s3/S3Lister.m @@ -237,14 +237,14 @@ if (!xmlDoc) { HSLogDebug(@"list Objects XML data: %@", [[[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding] autorelease]); SETNSERROR([S3Service errorDomain], [myError code], @"error parsing List Objects XML response: %@", myError); - return NO; + return nil; } NSXMLElement *rootElement = [xmlDoc rootElement]; NSArray *isTruncatedNodes = [rootElement nodesForXPath:@"//ListBucketResult/IsTruncated" error:&myError]; if (isTruncatedNodes == nil) { HSLogError(@"nodesForXPath: %@", myError); SETERRORFROMMYERROR; - return NO; + return nil; } if ([isTruncatedNodes count] == 0) { isTruncated = NO; @@ -256,7 +256,7 @@ if (error != NULL) { HSLogError(@"error getting //ListBucketResult/CommonPrefixes/Prefix nodes: %@", *error); } - return NO; + return nil; } NSMutableArray *theFoundPrefixes = [NSMutableArray array]; for (NSXMLNode *prefixNode in prefixNodes) { diff --git a/cocoastack/shared/LZ4Compressor.m b/cocoastack/shared/LZ4Compressor.m index 9db72c2..a96948d 100644 --- a/cocoastack/shared/LZ4Compressor.m +++ b/cocoastack/shared/LZ4Compressor.m @@ -67,7 +67,7 @@ CWL_SYNTHESIZE_SINGLETON_FOR_CLASS(LZ4Compressor) - (NSData *)lockedLZ4Deflate:(NSData *)data error:(NSError **)error { if ([data length] > (NSUInteger)INT_MAX) { SETNSERROR([self errorDomain], -1, @"length larger than INT_MAX"); - return NO; + return nil; } int originalSize = (int)[data length]; @@ -83,7 +83,7 @@ CWL_SYNTHESIZE_SINGLETON_FOR_CLASS(LZ4Compressor) if (compressed == 0) { SETNSERROR([self errorDomain], -1, @"LZ4_compress_default failed"); free(outBuf); - return NO; + return nil; } uint32_t nboSize = OSSwapHostToBigInt32(originalSize); memcpy(outBuf, &nboSize, 4); diff --git a/glacierrestore/GlacierPackIndex.m b/glacierrestore/GlacierPackIndex.m index 47572c0..f2d0cef 100644 --- a/glacierrestore/GlacierPackIndex.m +++ b/glacierrestore/GlacierPackIndex.m @@ -327,7 +327,7 @@ typedef struct pack_index { close(fd); if (endIndex == 0) { SETNSERROR(@"PacksErrorDomain", ERROR_NOT_FOUND, @"sha1 %@ not found in pack", sha1); - return NO; + return nil; } fd = open([localPath fileSystemRepresentation], O_RDONLY); if (fd == -1) { @@ -352,7 +352,7 @@ typedef struct pack_index { int errnum = errno; HSLogError(@"mmap(%@) error %d: %s", localPath, errnum, strerror(errnum)); SETNSERROR(@"UnixErrorDomain", errnum, @"error mapping %@ to memory: %s", localPath, strerror(errnum)); - return NO; + return nil; } int64_t left = startIndex; int64_t right = endIndex - 1; diff --git a/glacierrestore/GlacierPackSet.m b/glacierrestore/GlacierPackSet.m index 0c83118..d77cd53 100644 --- a/glacierrestore/GlacierPackSet.m +++ b/glacierrestore/GlacierPackSet.m @@ -102,7 +102,7 @@ static unsigned long long DEFAULT_MAX_PACK_ITEM_SIZE_BYTES = 65536; } - (PackIndexEntry *)packIndexEntryForObjectSHA1:(NSString *)theSHA1 targetConnectionDelegate:(id )theTCD error:(NSError **)error { if (!loadedPIEs && ![self loadPackIndexEntriesWithTargetConnectionDelegate:theTCD error:error]) { - return NO; + return nil; } PackIndexEntry *ret = [packIndexEntriesByObjectSHA1 objectForKey:theSHA1]; if (ret == nil) { diff --git a/glacierrestore/GlacierRestorer.m b/glacierrestore/GlacierRestorer.m index 06304b5..05aabc7 100644 --- a/glacierrestore/GlacierRestorer.m +++ b/glacierrestore/GlacierRestorer.m @@ -922,12 +922,12 @@ if ([[NSFileManager defaultManager] fileExistsAtPath:statusPath]) { NSDictionary *attribs = [[NSFileManager defaultManager] attributesOfItemAtPath:statusPath error:error]; if (attribs == nil) { - return NO; + return nil; } if ([[attribs objectForKey:NSFileSize] unsignedLongLongValue] > 0) { NSData *jobIdData = [NSData dataWithContentsOfFile:statusPath options:NSUncachedRead error:error]; if (jobIdData == nil) { - return NO; + return nil; } ret = [[[NSString alloc] initWithData:jobIdData encoding:NSUTF8StringEncoding] autorelease]; } diff --git a/repo/ObjectEncryptorV1.m b/repo/ObjectEncryptorV1.m index 78ef11b..52ded30 100644 --- a/repo/ObjectEncryptorV1.m +++ b/repo/ObjectEncryptorV1.m @@ -141,7 +141,7 @@ targetConnectionDelegate:(id )theTCD } - (NSData *)v2EncryptedObjectFromData:(NSData *)theData masterIV:(NSData *)theMasterIV dataIVAndSymmetricKey:(NSData *)theDataIVAndSymmetricKey error:(NSError **)error { SETNSERROR(@"ObjectEncryptorV1", -1, @"writeV2EncryptedObjectFromData not supported"); - return NO; + return nil; } // //- (NSString *)sha1HashForData:(NSData *)theData error:(NSError **)error { diff --git a/repo/ObjectEncryptorV2.m b/repo/ObjectEncryptorV2.m index 6d8a7f1..ae75ee6 100644 --- a/repo/ObjectEncryptorV2.m +++ b/repo/ObjectEncryptorV2.m @@ -137,7 +137,7 @@ } - (NSData *)encryptV1Data:(NSData *)theData error:(NSError **)error { SETNSERROR(@"ObjectEncryptorV2ErrorDomain", -1, @"encryptV1Data not supported"); - return NO; + return nil; } - (NSString *)sha1HashForV2Data:(NSData *)theData { // Calculate SHA1 hash of computerUUID+plaintext. @@ -157,7 +157,7 @@ if (theDataIVAndSymmetricKey != nil) { if ([theDataIVAndSymmetricKey length] < DATA_IV_AND_SYMMETRIC_KEY_LEN) { SETNSERROR([ObjectEncryptor errorDomain], -1, @"given dataIVAndSymmetricKey is less than %d bytes", DATA_IV_AND_SYMMETRIC_KEY_LEN); - return NO; + return nil; } memcpy(dataIVAndSymmetricKey, [theDataIVAndSymmetricKey bytes], DATA_IV_AND_SYMMETRIC_KEY_LEN); memcpy(mySymmetricKey, [theDataIVAndSymmetricKey bytes] + IV_LEN, SYMMETRIC_KEY_LEN); @@ -202,7 +202,7 @@ if (status != kCCSuccess) { SETNSERROR([ObjectEncryptor errorDomain], -1, @"encrypt: %@", [self errorMessageForStatus:status]); free(outbuf); - return NO; + return nil; } // Reset theOutBuffer's length. @@ -213,7 +213,7 @@ if ([theMasterIV length] != IV_LEN) { SETNSERROR([ObjectEncryptor errorDomain], -1, @"invalid masterIV length"); free(outbuf); - return NO; + return nil; } memcpy(masterIV, [theMasterIV bytes], IV_LEN); } else { @@ -241,12 +241,12 @@ if (status != kCCSuccess) { SETNSERROR([ObjectEncryptor errorDomain], -1, @"encrypt: %@", [self errorMessageForStatus:status]); free(outbuf); - return NO; + return nil; } if (encryptedMetadataActualLen != ENCRYPTED_DATA_IV_AND_SYMMETRIC_KEY_LEN) { SETNSERROR([ObjectEncryptor errorDomain], -1, @"unexpected encrypted metadata length"); free(outbuf); - return NO; + return nil; } // Calculate HMACSHA256 of (master IV + encryptedMetadata + ciphertext) using second half of master key. diff --git a/repo/PackSet.m b/repo/PackSet.m index 424f2b2..04e5e87 100644 --- a/repo/PackSet.m +++ b/repo/PackSet.m @@ -301,7 +301,7 @@ cachePackFilesToDisk:(BOOL)theCachePackFilesToDisk - (NSNumber *)isObjectDownloadableForSHA1:(NSString *)theSHA1 error:(NSError **)error { PackIndexEntry *pie = [self packIndexEntryForSHA1:theSHA1 error:error]; if (pie == nil) { - return NO; + return nil; } return [fark isPackDownloadableWithId:[pie packId] storageType:storageType error:error]; } diff --git a/repo/PackSetDB.m b/repo/PackSetDB.m index f3ffce7..8d4fe0a 100644 --- a/repo/PackSetDB.m +++ b/repo/PackSetDB.m @@ -387,7 +387,7 @@ FlockFile *ff = [[[FlockFile alloc] initWithPath:lockFilePath] autorelease]; __block FMDatabaseQueue *ret = nil; if (![ff lockAndExecute:^void() { ret = [self lockedInitDB:error]; } error:error]) { - ret = NO; + ret = nil; } return ret; }