macos prefs pane improved error handling
authorDerrick Brashear <shadow@dementia.org>
Thu, 29 Jul 2010 14:59:35 +0000 (10:59 -0400)
committerDerrick Brashear <shadow@dementia.org>
Thu, 29 Jul 2010 16:34:22 +0000 (09:34 -0700)
NSScanner: nil string argument
is a lame thing to see. so let's not.

Change-Id: I972ed9ebe5a9f7ef5ae9ecbd0423a61bd5bfb5b7
Reviewed-on: http://gerrit.openafs.org/2478
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/platform/DARWIN/AFSPreference/AFSPropertyManager.h
src/platform/DARWIN/AFSPreference/AFSPropertyManager.m

index 6330645..e229c76 100644 (file)
  @discussion The cache info is read from the file pointed by filePath param
  @param      filePath file location for the CacheInfo
  */
--(void) readCacheInfo:(NSString*)filePath;
+-(int) readCacheInfo:(NSString*)filePath;
 
 /*!
  @function      writeCacheInfo
  @param      filePath file path to afsd.option like file
  @result     <#(description)#>
  */
--(void) readOldAfsdOption:(NSString*)filePath;
+-(int) readOldAfsdOption:(NSString*)filePath;
 /*!
  @function      readAFSDParamLineContent
  @abstract   Try to decode one line of afsd.option or afs.conf
  @param      paramLine one line of file afsd.option(the only one that is present) os afs.conf
  */
--(void) readAFSDParamLineContent:(NSString*)paramLine;
+-(int) readAFSDParamLineContent:(NSString*)paramLine;
 /*!
  @function      readNewAfsdOption
  @abstract   Read the new afs.conf file format
  @discussion Scann every line f the afs.conf file ad for each one call the readAFSDParamLineContent with it's content
  @param      filePath path of the new file with afs.conf file format
  */
--(void) readNewAfsdOption:(NSString*)filePath;
+-(int) readNewAfsdOption:(NSString*)filePath;
 /*!
  @function      writeAfsdOption
  @abstract   <#(description)#>
index 559a216..2c4e5f2 100644 (file)
 //  readCacheInfo:
 //  file template "/afs:/var/db/openafs/cache:30000"
 // -------------------------------------------------------------------------------
--(void) readCacheInfo:(NSString*)filePath
+-(int) readCacheInfo:(NSString*)filePath
 {
        int cicle = 0;
        NSString *tmpString = nil;
        
        NSCharacterSet *returnCS = [NSCharacterSet characterSetWithCharactersInString:@"\n"];
        NSFileHandle *fileH = [NSFileHandle fileHandleForReadingAtPath:filePath];
+       if (!fileH) return nil;
        NSData *fileHData = [fileH readDataToEndOfFile];
        NSString *cacheInfoStrData = [[NSString alloc] initWithData:fileHData
                                                                                                           encoding:NSASCIIStringEncoding];
                //if(cacheInfoStrData) [cacheInfoStrData release];
                if(chunkStartCS) [chunkStartCS release];
        }
-       
+       return noErr;
 }
 
 
 {
        @try{
                if(useAfsdConfVersion) {
-                       [self readNewAfsdOption:filePath];
-               } else {
+                   if ([self readNewAfsdOption:filePath] != noErr)
                        [self readOldAfsdOption:filePath];
+               } else {
+                   if ([self readOldAfsdOption:filePath] != noErr)
+                       [self readNewAfsdOption:filePath];
                }
        
        }@catch(NSException *e){
 // -------------------------------------------------------------------------------
 //  readOldAfsdOption:
 // -------------------------------------------------------------------------------
--(void) readOldAfsdOption:(NSString*)filePath
+-(int) readOldAfsdOption:(NSString*)filePath
 {
-
-       /*NSFileHandle *fileH = [NSFileHandle fileHandleForReadingAtPath:filePath];
-       NSData *fileHData = [fileH readDataToEndOfFile];
-       NSString *afsdOptionStrData = [[NSString alloc] initWithData:fileHData
-                                                                                                               encoding:NSASCIIStringEncoding];*/
-       if(!filePath) return;
-       [self readAFSDParamLineContent:[[NSString stringWithContentsOfFile:filePath 
+       if(!filePath) return nil;
+       return [self readAFSDParamLineContent:[[NSString stringWithContentsOfFile:filePath 
                                                                                                                          encoding:NSUTF8StringEncoding 
                                                                                                                                 error:nil] stringByStandardizingPath]];
 }
 // -------------------------------------------------------------------------------
 //  readAFSDParamLineContent:
 // -------------------------------------------------------------------------------
--(void) readAFSDParamLineContent:(NSString*) paramLine{
+-(int) readAFSDParamLineContent:(NSString*) paramLine{
+       if (!paramLine) return nil;
+
        NSString *tmpString = nil;
        NSCharacterSet *space = [NSCharacterSet characterSetWithCharactersInString:@" "];
        NSScanner *afsdOptionS = [NSScanner  scannerWithString:paramLine];
                
                
        }while(![afsdOptionS isAtEnd]);
-       
+       return noErr;
 }
 
 // -------------------------------------------------------------------------------
 //  readNewAfsdOption:
 // -------------------------------------------------------------------------------
--(void) readNewAfsdOption:(NSString*)filePath
+-(int) readNewAfsdOption:(NSString*)filePath
 {
-       if(!filePath) return;
+       if(!filePath) return nil;
        NSString *currentLines = nil;
        NSString *paramValue = nil;
        NSScanner *lineScanner = nil;
        NSString *newAFSDConfContent = [NSString stringWithContentsOfFile:filePath 
                                                                                                                         encoding:NSUTF8StringEncoding 
                                                                                                                                error:nil];
+       if (!newAFSDConfContent) return nil;
        
        //get lines in array
        NSArray *confLines = [newAFSDConfContent componentsSeparatedByString:@"\n"];
                        
                }
        }
+       return noErr;
 }
 
 
 {
        NSString *tmpString = nil;
        NSString *result = [TaskUtil executeTaskSearchingPath:@"fs" args:[NSArray arrayWithObjects:@"-version", nil]];
+       if (!result) return nil;
        NSCharacterSet *endVersionCS = [NSCharacterSet characterSetWithCharactersInString:@"qwertyuiopasdfghjklzxcvbnmMNBVCXZLKJHGFDSAPOIUYTREWQ"];
        NSCharacterSet *spaceCS = [NSCharacterSet characterSetWithCharactersInString:@" "];
        NSScanner *versionS = [NSScanner  scannerWithString:result];
 {
        NSString *tmpString = nil;
        NSString *totalVersion = [self getAfsVersion];
+       if (!totalVersion) return 0;
        NSCharacterSet *pointCS = [NSCharacterSet characterSetWithCharactersInString:@"."];
        NSScanner *versionMS = [NSScanner  scannerWithString:totalVersion];
        [versionMS scanUpToCharactersFromSet:pointCS intoString:&tmpString];
 {
        NSString *tmpString = nil;
        NSString *totalVersion = [self getAfsVersion];
+       if (!totalVersion) return 0;
        NSCharacterSet *numCS = [NSCharacterSet characterSetWithCharactersInString:@"1234567890"];
        NSCharacterSet *pointCS = [NSCharacterSet characterSetWithCharactersInString:@"."];
        NSScanner *versionMS = [NSScanner  scannerWithString:totalVersion];
 -(int) getAfsPatchVersionVersion
 {
        NSString *totalVersion = [self getAfsVersion];
+       if (!totalVersion) return 0;
        NSCharacterSet *pointCS = [NSCharacterSet characterSetWithCharactersInString:@"."];
        int lastPointIndex = [totalVersion rangeOfCharacterFromSet:pointCS 
                                                                                                           options:NSBackwardsSearch].location;
                @throw [NSException exceptionWithName:@"readCellInfo" 
                                                                           reason:kConfFileNotExits
                                                                         userInfo:nil];
-       }
+       } else if (!result)
+           return;
        NSScanner *scanner = [NSScanner scannerWithString:result];
        [scanner scanUpToString:@"\n" 
                                 intoString:&tmpStr];
        NSCharacterSet *spaceCS = [NSCharacterSet characterSetWithCharactersInString:@" \t"];
        
        NSFileHandle *fileH = [NSFileHandle fileHandleForReadingAtPath:configFile];
+       if (!fileH) return;
        NSData *dbCellData = [fileH readDataToEndOfFile];
        NSString *strData = [[NSString alloc] initWithData:dbCellData
                                                                                          encoding:NSASCIIStringEncoding];
 //  scanIpForCell:
 // -------------------------------------------------------------------------------
 -(void) scanIpForCell:(DBCellElement*) cellElement allIP:(NSString*)allIP {
+    if (!allIP) return;
        NSScanner *ipScann = [NSScanner scannerWithString:allIP];
        NSCharacterSet *returnCS = [NSCharacterSet characterSetWithCharactersInString:@"\n"];
        NSCharacterSet *spaceCS = [NSCharacterSet characterSetWithCharactersInString:@" \t"];
        NSMutableArray *tokenList = [[NSMutableArray alloc] init];
        NSString *tokensOutput = [TaskUtil executeTaskSearchingPath:@"tokens" args:[NSArray arrayWithObjects:nil]];
        
-       // scann the tokens
+       if (!tokensOutput) return tokenList;
+       // scan the tokens
        NSScanner *tokenScan = [NSScanner scannerWithString:tokensOutput];
        NSCharacterSet *returnCS = [NSCharacterSet characterSetWithCharactersInString:@"\n"];