return nil instead of NO

This commit is contained in:
Stefan Reitshamer 2017-11-13 06:46:16 -05:00
parent 9f14505297
commit 0f0c956e16
13 changed files with 31 additions and 31 deletions

View file

@ -610,7 +610,7 @@
- (BackupSet *)backupSetForTarget:(Target *)theInitialTarget computerUUID:(NSString *)theComputerUUID error:(NSError **)error { - (BackupSet *)backupSetForTarget:(Target *)theInitialTarget computerUUID:(NSString *)theComputerUUID error:(NSError **)error {
NSArray *expandedTargetList = [self expandedTargetListForTarget:theInitialTarget error:error]; NSArray *expandedTargetList = [self expandedTargetListForTarget:theInitialTarget error:error];
if (expandedTargetList == nil) { if (expandedTargetList == nil) {
return NO; return nil;
} }
for (Target *theTarget in expandedTargetList) { for (Target *theTarget in expandedTargetList) {
@ -622,7 +622,7 @@
} else { } else {
HSLogError(@"error getting backup sets for %@: %@", theTarget, myError); HSLogError(@"error getting backup sets for %@: %@", theTarget, myError);
SETERRORFROMMYERROR; SETERRORFROMMYERROR;
return NO; return nil;
} }
} else { } else {
for (BackupSet *backupSet in backupSets) { for (BackupSet *backupSet in backupSets) {

View file

@ -68,7 +68,7 @@
int errnum = errno; int errnum = errno;
HSLogError(@"lstat(%@) error %d: %s", path, errnum, strerror(errnum)); HSLogError(@"lstat(%@) error %d: %s", path, errnum, strerror(errnum));
SETNSERROR(@"UnixErrorDomain", errnum, @"%@: %s", path, strerror(errnum)); SETNSERROR(@"UnixErrorDomain", errnum, @"%@: %s", path, strerror(errnum));
return NO; return nil;
} }
unsigned long long length = (unsigned long long)st.st_size; unsigned long long length = (unsigned long long)st.st_size;
FileInputStream *fis = [[FileInputStream alloc] initWithPath:path offset:0 length:length]; FileInputStream *fis = [[FileInputStream alloc] initWithPath:path offset:0 length:length];

View file

@ -109,7 +109,7 @@
id <PListNode> node = [self makeNode:childNode error:error]; id <PListNode> node = [self makeNode:childNode error:error];
if (!node) { if (!node) {
[nodes release]; [nodes release];
return NO; return nil;
} }
[nodes addObject:node]; [nodes addObject:node];
} }
@ -134,7 +134,7 @@
} else { } else {
id <PListNode> node = [self makeNode:childNode error:error]; id <PListNode> node = [self makeNode:childNode error:error];
if (!node) { if (!node) {
return NO; return nil;
} }
NSAssert(key != nil, @"must have key before adding value"); NSAssert(key != nil, @"must have key before adding value");
[dn put:node forKey:key]; [dn put:node forKey:key];

View file

@ -161,7 +161,7 @@
int errnum = errno; int errnum = errno;
HSLogError(@"chown(%@) error %d: %s", thePath, errnum, strerror(errnum)); HSLogError(@"chown(%@) error %d: %s", thePath, errnum, strerror(errnum));
SETNSERROR(@"UnixErrorDomain", errnum, @"failed to change ownership of %@: %s", thePath, 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]) { if (![self ensureTempDirExists:&myError]) {
SETERRORFROMMYERROR; SETERRORFROMMYERROR;
HSLogError(@"error ensuring temp dir %@ exists: %@", tempDir, myError); HSLogError(@"error ensuring temp dir %@ exists: %@", tempDir, myError);
return NO; return nil;
} }
NSString *tempPath = [tempDir stringByAppendingPathComponent:[NSString stringWithRandomUUID]]; NSString *tempPath = [tempDir stringByAppendingPathComponent:[NSString stringWithRandomUUID]];
if (![theData writeToFile:tempPath options:NSAtomicWrite error:&myError]) { if (![theData writeToFile:tempPath options:NSAtomicWrite error:&myError]) {
SETERRORFROMMYERROR; SETERRORFROMMYERROR;
HSLogError(@"error creating temp file %@: %@", tempPath, myError); 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]) { 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]) { if (![myError isErrorWithDomain:NSCocoaErrorDomain code:NSFileWriteFileExistsError]) {
SETERRORFROMMYERROR; SETERRORFROMMYERROR;
HSLogError(@"error renaming %@ to %@: %@", tempPath, theFullPath, myError); HSLogError(@"error renaming %@ to %@: %@", tempPath, theFullPath, myError);
return NO; return nil;
} }
// Delete the file that's in the way. // Delete the file that's in the way.
HSLogDebug(@"deleting existing file before overwriting: %@", theFullPath); HSLogDebug(@"deleting existing file before overwriting: %@", theFullPath);
if (![[NSFileManager defaultManager] removeItemAtPath:theFullPath error:&myError]) { if (![[NSFileManager defaultManager] removeItemAtPath:theFullPath error:&myError]) {
SETERRORFROMMYERROR; SETERRORFROMMYERROR;
HSLogError(@"error removing a file that's in the way (%@): %@", theFullPath, myError); HSLogError(@"error removing a file that's in the way (%@): %@", theFullPath, myError);
return NO; return nil;
} }
// Try again. // Try again.
if (![[NSFileManager defaultManager] moveItemAtPath:tempPath toPath:theFullPath error:&myError]) { if (![[NSFileManager defaultManager] moveItemAtPath:tempPath toPath:theFullPath error:&myError]) {
if (![myError isErrorWithDomain:NSCocoaErrorDomain code:NSFileWriteFileExistsError]) { if (![myError isErrorWithDomain:NSCocoaErrorDomain code:NSFileWriteFileExistsError]) {
SETERRORFROMMYERROR; SETERRORFROMMYERROR;
HSLogError(@"error renaming %@ to %@: %@", tempPath, theFullPath, myError); HSLogError(@"error renaming %@ to %@: %@", tempPath, theFullPath, myError);
return NO; return nil;
} }
} }
} }
@ -246,7 +246,7 @@
int errnum = errno; int errnum = errno;
HSLogError(@"chown(%@) error %d: %s", theFullPath, errnum, strerror(errnum)); HSLogError(@"chown(%@) error %d: %s", theFullPath, errnum, strerror(errnum));
SETNSERROR(@"UnixErrorDomain", errnum, @"failed to change ownership of %@: %s", theFullPath, strerror(errnum)); SETNSERROR(@"UnixErrorDomain", errnum, @"failed to change ownership of %@: %s", theFullPath, strerror(errnum));
return NO; return nil;
} }
} }
Item *item = [[[Item alloc] init] autorelease]; Item *item = [[[Item alloc] init] autorelease];

View file

@ -237,14 +237,14 @@
if (!xmlDoc) { if (!xmlDoc) {
HSLogDebug(@"list Objects XML data: %@", [[[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding] autorelease]); HSLogDebug(@"list Objects XML data: %@", [[[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding] autorelease]);
SETNSERROR([S3Service errorDomain], [myError code], @"error parsing List Objects XML response: %@", myError); SETNSERROR([S3Service errorDomain], [myError code], @"error parsing List Objects XML response: %@", myError);
return NO; return nil;
} }
NSXMLElement *rootElement = [xmlDoc rootElement]; NSXMLElement *rootElement = [xmlDoc rootElement];
NSArray *isTruncatedNodes = [rootElement nodesForXPath:@"//ListBucketResult/IsTruncated" error:&myError]; NSArray *isTruncatedNodes = [rootElement nodesForXPath:@"//ListBucketResult/IsTruncated" error:&myError];
if (isTruncatedNodes == nil) { if (isTruncatedNodes == nil) {
HSLogError(@"nodesForXPath: %@", myError); HSLogError(@"nodesForXPath: %@", myError);
SETERRORFROMMYERROR; SETERRORFROMMYERROR;
return NO; return nil;
} }
if ([isTruncatedNodes count] == 0) { if ([isTruncatedNodes count] == 0) {
isTruncated = NO; isTruncated = NO;
@ -256,7 +256,7 @@
if (error != NULL) { if (error != NULL) {
HSLogError(@"error getting //ListBucketResult/CommonPrefixes/Prefix nodes: %@", *error); HSLogError(@"error getting //ListBucketResult/CommonPrefixes/Prefix nodes: %@", *error);
} }
return NO; return nil;
} }
NSMutableArray *theFoundPrefixes = [NSMutableArray array]; NSMutableArray *theFoundPrefixes = [NSMutableArray array];
for (NSXMLNode *prefixNode in prefixNodes) { for (NSXMLNode *prefixNode in prefixNodes) {

View file

@ -67,7 +67,7 @@ CWL_SYNTHESIZE_SINGLETON_FOR_CLASS(LZ4Compressor)
- (NSData *)lockedLZ4Deflate:(NSData *)data error:(NSError **)error { - (NSData *)lockedLZ4Deflate:(NSData *)data error:(NSError **)error {
if ([data length] > (NSUInteger)INT_MAX) { if ([data length] > (NSUInteger)INT_MAX) {
SETNSERROR([self errorDomain], -1, @"length larger than INT_MAX"); SETNSERROR([self errorDomain], -1, @"length larger than INT_MAX");
return NO; return nil;
} }
int originalSize = (int)[data length]; int originalSize = (int)[data length];
@ -83,7 +83,7 @@ CWL_SYNTHESIZE_SINGLETON_FOR_CLASS(LZ4Compressor)
if (compressed == 0) { if (compressed == 0) {
SETNSERROR([self errorDomain], -1, @"LZ4_compress_default failed"); SETNSERROR([self errorDomain], -1, @"LZ4_compress_default failed");
free(outBuf); free(outBuf);
return NO; return nil;
} }
uint32_t nboSize = OSSwapHostToBigInt32(originalSize); uint32_t nboSize = OSSwapHostToBigInt32(originalSize);
memcpy(outBuf, &nboSize, 4); memcpy(outBuf, &nboSize, 4);

View file

@ -327,7 +327,7 @@ typedef struct pack_index {
close(fd); close(fd);
if (endIndex == 0) { if (endIndex == 0) {
SETNSERROR(@"PacksErrorDomain", ERROR_NOT_FOUND, @"sha1 %@ not found in pack", sha1); SETNSERROR(@"PacksErrorDomain", ERROR_NOT_FOUND, @"sha1 %@ not found in pack", sha1);
return NO; return nil;
} }
fd = open([localPath fileSystemRepresentation], O_RDONLY); fd = open([localPath fileSystemRepresentation], O_RDONLY);
if (fd == -1) { if (fd == -1) {
@ -352,7 +352,7 @@ typedef struct pack_index {
int errnum = errno; int errnum = errno;
HSLogError(@"mmap(%@) error %d: %s", localPath, errnum, strerror(errnum)); HSLogError(@"mmap(%@) error %d: %s", localPath, errnum, strerror(errnum));
SETNSERROR(@"UnixErrorDomain", errnum, @"error mapping %@ to memory: %s", localPath, strerror(errnum)); SETNSERROR(@"UnixErrorDomain", errnum, @"error mapping %@ to memory: %s", localPath, strerror(errnum));
return NO; return nil;
} }
int64_t left = startIndex; int64_t left = startIndex;
int64_t right = endIndex - 1; int64_t right = endIndex - 1;

View file

@ -102,7 +102,7 @@ static unsigned long long DEFAULT_MAX_PACK_ITEM_SIZE_BYTES = 65536;
} }
- (PackIndexEntry *)packIndexEntryForObjectSHA1:(NSString *)theSHA1 targetConnectionDelegate:(id <TargetConnectionDelegate>)theTCD error:(NSError **)error { - (PackIndexEntry *)packIndexEntryForObjectSHA1:(NSString *)theSHA1 targetConnectionDelegate:(id <TargetConnectionDelegate>)theTCD error:(NSError **)error {
if (!loadedPIEs && ![self loadPackIndexEntriesWithTargetConnectionDelegate:theTCD error:error]) { if (!loadedPIEs && ![self loadPackIndexEntriesWithTargetConnectionDelegate:theTCD error:error]) {
return NO; return nil;
} }
PackIndexEntry *ret = [packIndexEntriesByObjectSHA1 objectForKey:theSHA1]; PackIndexEntry *ret = [packIndexEntriesByObjectSHA1 objectForKey:theSHA1];
if (ret == nil) { if (ret == nil) {

View file

@ -922,12 +922,12 @@
if ([[NSFileManager defaultManager] fileExistsAtPath:statusPath]) { if ([[NSFileManager defaultManager] fileExistsAtPath:statusPath]) {
NSDictionary *attribs = [[NSFileManager defaultManager] attributesOfItemAtPath:statusPath error:error]; NSDictionary *attribs = [[NSFileManager defaultManager] attributesOfItemAtPath:statusPath error:error];
if (attribs == nil) { if (attribs == nil) {
return NO; return nil;
} }
if ([[attribs objectForKey:NSFileSize] unsignedLongLongValue] > 0) { if ([[attribs objectForKey:NSFileSize] unsignedLongLongValue] > 0) {
NSData *jobIdData = [NSData dataWithContentsOfFile:statusPath options:NSUncachedRead error:error]; NSData *jobIdData = [NSData dataWithContentsOfFile:statusPath options:NSUncachedRead error:error];
if (jobIdData == nil) { if (jobIdData == nil) {
return NO; return nil;
} }
ret = [[[NSString alloc] initWithData:jobIdData encoding:NSUTF8StringEncoding] autorelease]; ret = [[[NSString alloc] initWithData:jobIdData encoding:NSUTF8StringEncoding] autorelease];
} }

View file

@ -141,7 +141,7 @@ targetConnectionDelegate:(id <TargetConnectionDelegate>)theTCD
} }
- (NSData *)v2EncryptedObjectFromData:(NSData *)theData masterIV:(NSData *)theMasterIV dataIVAndSymmetricKey:(NSData *)theDataIVAndSymmetricKey error:(NSError **)error { - (NSData *)v2EncryptedObjectFromData:(NSData *)theData masterIV:(NSData *)theMasterIV dataIVAndSymmetricKey:(NSData *)theDataIVAndSymmetricKey error:(NSError **)error {
SETNSERROR(@"ObjectEncryptorV1", -1, @"writeV2EncryptedObjectFromData not supported"); SETNSERROR(@"ObjectEncryptorV1", -1, @"writeV2EncryptedObjectFromData not supported");
return NO; return nil;
} }
// //
//- (NSString *)sha1HashForData:(NSData *)theData error:(NSError **)error { //- (NSString *)sha1HashForData:(NSData *)theData error:(NSError **)error {

View file

@ -137,7 +137,7 @@
} }
- (NSData *)encryptV1Data:(NSData *)theData error:(NSError **)error { - (NSData *)encryptV1Data:(NSData *)theData error:(NSError **)error {
SETNSERROR(@"ObjectEncryptorV2ErrorDomain", -1, @"encryptV1Data not supported"); SETNSERROR(@"ObjectEncryptorV2ErrorDomain", -1, @"encryptV1Data not supported");
return NO; return nil;
} }
- (NSString *)sha1HashForV2Data:(NSData *)theData { - (NSString *)sha1HashForV2Data:(NSData *)theData {
// Calculate SHA1 hash of computerUUID+plaintext. // Calculate SHA1 hash of computerUUID+plaintext.
@ -157,7 +157,7 @@
if (theDataIVAndSymmetricKey != nil) { if (theDataIVAndSymmetricKey != nil) {
if ([theDataIVAndSymmetricKey length] < DATA_IV_AND_SYMMETRIC_KEY_LEN) { 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); 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(dataIVAndSymmetricKey, [theDataIVAndSymmetricKey bytes], DATA_IV_AND_SYMMETRIC_KEY_LEN);
memcpy(mySymmetricKey, [theDataIVAndSymmetricKey bytes] + IV_LEN, SYMMETRIC_KEY_LEN); memcpy(mySymmetricKey, [theDataIVAndSymmetricKey bytes] + IV_LEN, SYMMETRIC_KEY_LEN);
@ -202,7 +202,7 @@
if (status != kCCSuccess) { if (status != kCCSuccess) {
SETNSERROR([ObjectEncryptor errorDomain], -1, @"encrypt: %@", [self errorMessageForStatus:status]); SETNSERROR([ObjectEncryptor errorDomain], -1, @"encrypt: %@", [self errorMessageForStatus:status]);
free(outbuf); free(outbuf);
return NO; return nil;
} }
// Reset theOutBuffer's length. // Reset theOutBuffer's length.
@ -213,7 +213,7 @@
if ([theMasterIV length] != IV_LEN) { if ([theMasterIV length] != IV_LEN) {
SETNSERROR([ObjectEncryptor errorDomain], -1, @"invalid masterIV length"); SETNSERROR([ObjectEncryptor errorDomain], -1, @"invalid masterIV length");
free(outbuf); free(outbuf);
return NO; return nil;
} }
memcpy(masterIV, [theMasterIV bytes], IV_LEN); memcpy(masterIV, [theMasterIV bytes], IV_LEN);
} else { } else {
@ -241,12 +241,12 @@
if (status != kCCSuccess) { if (status != kCCSuccess) {
SETNSERROR([ObjectEncryptor errorDomain], -1, @"encrypt: %@", [self errorMessageForStatus:status]); SETNSERROR([ObjectEncryptor errorDomain], -1, @"encrypt: %@", [self errorMessageForStatus:status]);
free(outbuf); free(outbuf);
return NO; return nil;
} }
if (encryptedMetadataActualLen != ENCRYPTED_DATA_IV_AND_SYMMETRIC_KEY_LEN) { if (encryptedMetadataActualLen != ENCRYPTED_DATA_IV_AND_SYMMETRIC_KEY_LEN) {
SETNSERROR([ObjectEncryptor errorDomain], -1, @"unexpected encrypted metadata length"); SETNSERROR([ObjectEncryptor errorDomain], -1, @"unexpected encrypted metadata length");
free(outbuf); free(outbuf);
return NO; return nil;
} }
// Calculate HMACSHA256 of (master IV + encryptedMetadata + ciphertext) using second half of master key. // Calculate HMACSHA256 of (master IV + encryptedMetadata + ciphertext) using second half of master key.

View file

@ -301,7 +301,7 @@ cachePackFilesToDisk:(BOOL)theCachePackFilesToDisk
- (NSNumber *)isObjectDownloadableForSHA1:(NSString *)theSHA1 error:(NSError **)error { - (NSNumber *)isObjectDownloadableForSHA1:(NSString *)theSHA1 error:(NSError **)error {
PackIndexEntry *pie = [self packIndexEntryForSHA1:theSHA1 error:error]; PackIndexEntry *pie = [self packIndexEntryForSHA1:theSHA1 error:error];
if (pie == nil) { if (pie == nil) {
return NO; return nil;
} }
return [fark isPackDownloadableWithId:[pie packId] storageType:storageType error:error]; return [fark isPackDownloadableWithId:[pie packId] storageType:storageType error:error];
} }

View file

@ -387,7 +387,7 @@
FlockFile *ff = [[[FlockFile alloc] initWithPath:lockFilePath] autorelease]; FlockFile *ff = [[[FlockFile alloc] initWithPath:lockFilePath] autorelease];
__block FMDatabaseQueue *ret = nil; __block FMDatabaseQueue *ret = nil;
if (![ff lockAndExecute:^void() { ret = [self lockedInitDB:error]; } error:error]) { if (![ff lockAndExecute:^void() { ret = [self lockedInitDB:error]; } error:error]) {
ret = NO; ret = nil;
} }
return ret; return ret;
} }