Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOFileScannerVerifierStage(OOPrivate) Category Reference

Instance Methods

(void) - scanForFiles
 
(void) - checkRootFolders
 
(void) - checkKnownFiles
 
(NSDictionary *) - lowercaseMap:
 
(NSDictionary *) - scanDirectory:
 
(void) - checkPListFormat:file:folder:
 
(NSSet *) - constructReadMeNames
 
(void) - checkConfigFiles [implementation]
 

Detailed Description

Definition at line 62 of file OOFileScannerVerifierStage.m.

Method Documentation

◆ checkConfigFiles

- (void) checkConfigFiles
implementation

Extends class OOFileScannerVerifierStage.

Definition at line 761 of file OOFileScannerVerifierStage.m.

445{
446 NSArray *knownNames = nil;
447 NSEnumerator *nameEnum = nil;
448 NSString *name = nil,
449 *lcName = nil,
450 *realFileName = nil;
451 BOOL inConfigDir;
452
453 knownNames = [[self verifier] configurationArrayForKey:@"knownConfigFiles"];
454 for (nameEnum = [knownNames objectEnumerator]; (name = [nameEnum nextObject]); )
455 {
456 if (![name isKindOfClass:[NSString class]]) continue;
457
458 /* In theory, we could use -fileExists:inFolder:referencedFrom:checkBuiltIn:
459 here, but we want a different error message.
460 */
461
462 lcName = [name lowercaseString];
463 realFileName = [[_directoryListings oo_dictionaryForKey:@"config"] objectForKey:lcName];
464 inConfigDir = realFileName != nil;
465 if (!inConfigDir) realFileName = [[_directoryListings oo_dictionaryForKey:@""] objectForKey:lcName];
466 if (realFileName == nil) continue;
467
468 if (![realFileName isEqualToString:name])
469 {
470 if (inConfigDir) realFileName = [@"Config" stringByAppendingPathComponent:realFileName];
471 OOLog(@"verifyOXP.files.caseMismatch", @"***** ERROR: case mismatch: configuration file '%@' should be called '%@'.", realFileName, name);
472 }
473 }
474}
#define OOLog(class, format,...)
Definition OOLogging.h:88
return nil

References nil.

◆ checkKnownFiles

- (void) checkKnownFiles

Extends class OOFileScannerVerifierStage.

Definition at line 761 of file OOFileScannerVerifierStage.m.

478{
479 NSDictionary *directories = nil;
480 NSEnumerator *directoryEnum = nil;
481 NSString *directory = nil,
482 *lcDirectory = nil;
483 NSArray *fileList = nil;
484 NSEnumerator *nameEnum = nil;
485 NSString *name = nil,
486 *lcName = nil,
487 *realFileName = nil;
488 BOOL inDirectory;
489
490 directories = [[self verifier] configurationDictionaryForKey:@"knownFiles"];
491 for (directoryEnum = [directories keyEnumerator]; (directory = [directoryEnum nextObject]); )
492 {
493 fileList = [directories objectForKey:directory];
494 lcDirectory = [directory lowercaseString];
495 for (nameEnum = [fileList objectEnumerator]; (name = [nameEnum nextObject]); )
496 {
497 if (![name isKindOfClass:[NSString class]]) continue;
498
499 /* In theory, we could use -fileExists:inFolder:referencedFrom:checkBuiltIn:
500 here, but we want a different error message.
501 */
502
503 lcName = [name lowercaseString];
504 realFileName = [[_directoryListings oo_dictionaryForKey:lcDirectory] objectForKey:lcName];
505 inDirectory = (realFileName != nil);
506 if (!inDirectory)
507 {
508 // Allow for files in root directory of OXP
509 realFileName = [[_directoryListings oo_dictionaryForKey:@""] objectForKey:lcName];
510 }
511 if (realFileName == nil) continue;
512
513 if (![realFileName isEqualToString:name])
514 {
515 if (inDirectory) realFileName = [directory stringByAppendingPathComponent:realFileName];
516 OOLog(@"verifyOXP.files.caseMismatch", @"***** ERROR: case mismatch: file '%@' should be called '%@'.", realFileName, name);
517 }
518 }
519 }
520}

◆ checkPListFormat:file:folder:

- (void) checkPListFormat: (NSPropertyListFormat) format
file: (NSString *) file
folder: (NSString *) folder 

Extends class OOFileScannerVerifierStage.

Definition at line 761 of file OOFileScannerVerifierStage.m.

616 :(NSPropertyListFormat)format file:(NSString *)file folder:(NSString *)folder
617{
618 NSString *weirdnessKey = nil;
619 NSString *formatDesc = nil;
620 NSString *displayPath = nil;
621
622 if (format != NSPropertyListOpenStepFormat && format != NSPropertyListXMLFormat_v1_0)
623 {
624 displayPath = [self displayNameForFile:file andFolder:folder];
625 weirdnessKey = [displayPath lowercaseString];
626
627 if (![_badPLists containsObject:weirdnessKey])
628 {
629 // Warn about "non-standard" format
630 [_badPLists addObject:weirdnessKey];
631
632 switch (format)
633 {
634 case NSPropertyListBinaryFormat_v1_0:
635 formatDesc = @"Apple binary format";
636 break;
637
638#if OOLITE_GNUSTEP
639 case NSPropertyListGNUstepFormat:
640 formatDesc = @"GNUstep text format";
641 break;
642
643 case NSPropertyListGNUstepBinaryFormat:
644 formatDesc = @"GNUstep binary format";
645 break;
646#endif
647
648 default:
649 formatDesc = [NSString stringWithFormat:@"unknown format (%i)", (int)format];
650 }
651
652 OOLog(@"verifyOXP.plist.weirdFormat", @"----- WARNING: Property list %@ is in %@; OpenStep text format and XML format are the recommended formats for Oolite.", displayPath, formatDesc);
653 }
654 }
655}

◆ checkRootFolders

- (void) checkRootFolders

Extends class OOFileScannerVerifierStage.

Definition at line 761 of file OOFileScannerVerifierStage.m.

419{
420 NSArray *knownNames = nil;
421 NSEnumerator *nameEnum = nil;
422 NSString *name = nil;
423 NSString *lcName = nil;
424 NSString *actual = nil;
425
426 knownNames = [[self verifier] configurationArrayForKey:@"knownRootDirectories"];
427 for (nameEnum = [knownNames objectEnumerator]; (name = [nameEnum nextObject]); )
428 {
429 if (![name isKindOfClass:[NSString class]]) continue;
430
431 lcName = [name lowercaseString];
432 actual = [_directoryCases objectForKey:lcName];
433 if (actual == nil) continue;
434
435 if (![actual isEqualToString:name])
436 {
437 OOLog(@"verifyOXP.files.caseMismatch", @"***** ERROR: case mismatch: directory '%@' should be called '%@'.", actual, name);
438 }
439 [_caseWarnings addObject:lcName];
440 }
441}

◆ constructReadMeNames

- (NSSet *) constructReadMeNames

Extends class OOFileScannerVerifierStage.

Definition at line 761 of file OOFileScannerVerifierStage.m.

659{
660 NSDictionary *dict = nil;
661 NSArray *stems = nil,
662 *extensions = nil;
663 NSMutableSet *result = nil;
664 NSUInteger i, j, stemCount, extCount;
665 NSString *stem = nil,
666 *extension = nil;
667
668 dict = [[self verifier] configurationDictionaryForKey:@"readMeNames"];
669 stems = [dict oo_arrayForKey:@"stems"];
670 extensions = [dict oo_arrayForKey:@"extensions"];
671 stemCount = [stems count];
672 extCount = [extensions count];
673 if (stemCount * extCount == 0) return nil;
674
675 // Construct all stem+extension permutations
676 result = [NSMutableSet setWithCapacity:stemCount * extCount];
677 for (i = 0; i != stemCount; ++i)
678 {
679 stem = [[stems oo_stringAtIndex:i] lowercaseString];
680 if (stem != nil)
681 {
682 for (j = 0; j != extCount; ++j)
683 {
684 extension = [[extensions oo_stringAtIndex:j] lowercaseString];
685 if (extension != nil)
686 {
687 [result addObject:[stem stringByAppendingString:extension]];
688 }
689 }
690 }
691 }
692
693 return result;
694}

◆ lowercaseMap:

- (NSDictionary *) lowercaseMap: (NSArray *) array

Extends class OOFileScannerVerifierStage.

Definition at line 761 of file OOFileScannerVerifierStage.m.

523 :(NSArray *)array
524{
525 NSUInteger i, count;
526 NSString *canonical = nil,
527 *lowercase = nil;
528 NSMutableDictionary *result = nil;
529
530 count = [array count];
531 if (count == 0) return [NSDictionary dictionary];
532 result = [NSMutableDictionary dictionaryWithCapacity:count];
533
534 for (i = 0; i != count; ++i)
535 {
536 canonical = [array oo_stringAtIndex:i];
537 if (canonical != nil)
538 {
539 lowercase = [canonical lowercaseString];
540 [result setObject:canonical forKey:lowercase];
541 }
542 }
543
544 return result;
545}
unsigned count

◆ scanDirectory:

- (NSDictionary *) scanDirectory: (NSString *) path

Extends class OOFileScannerVerifierStage.

Definition at line 761 of file OOFileScannerVerifierStage.m.

548 :(NSString *)path
549{
550 NSDirectoryEnumerator *dirEnum = nil;
551 NSMutableDictionary *result = nil;
552 NSString *name = nil,
553 *lcName = nil,
554 *type = nil,
555 *dirName = nil,
556 *relativeName = nil,
557 *existing = nil;
558
559 result = [NSMutableDictionary dictionary];
560 dirName = [path lastPathComponent];
561
562 dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:path];
563 while ((name = [dirEnum nextObject]))
564 {
565 type = [[dirEnum fileAttributes] fileType];
566 relativeName = [dirName stringByAppendingPathComponent:name];
567
568 if ([_junkFileNames containsObject:name])
569 {
570 OOLog(@"verifyOXP.scanFiles.skipJunk", @"NOTE: skipping junk file %@/%@.", dirName, name);
571 }
572 else if ([type isEqualToString:NSFileTypeRegular])
573 {
574 lcName = [name lowercaseString];
575 existing = [result objectForKey:lcName];
576
577 if (existing == nil)
578 {
579 OOLog(@"verifyOXP.verbose.listFiles", @"- %@", name);
580 [result setObject:name forKey:lcName];
581 }
582 else
583 {
584 OOLog(@"verifyOXP.scanFiles.overloadedName", @"***** ERROR: %@ '%@' conflicts with %@ named '%@', ignoring. (OXPs must work on case-insensitive file systems!)", @"file", relativeName, @"file", [dirName stringByAppendingPathComponent:existing]);
585 }
586 }
587 else
588 {
589 if ([type isEqualToString:NSFileTypeDirectory])
590 {
591 [dirEnum skipDescendents];
592 if (![_skipDirectoryNames containsObject:name])
593 {
594 OOLog(@"verifyOXP.scanFiles.directory", @"----- WARNING: \"%@\" is a nested directory, ignoring.", relativeName);
595 }
596 else
597 {
598 OOLog(@"verifyOXP.verbose.listFiles", @"- Skipping %@/%@/", dirName, name);
599 }
600 }
601 else if ([type isEqualToString:NSFileTypeSymbolicLink])
602 {
603 OOLog(@"verifyOXP.scanFiles.symLink", @"----- WARNING: \"%@\" is a symbolic link, ignoring.", relativeName);
604 }
605 else
606 {
607 OOLog(@"verifyOXP.scanFiles.nonStandardFile", @"----- WARNING: \"%@\" is a non-standard file (%@), ignoring.", relativeName, type);
608 }
609 }
610 }
611
612 return result;
613}

◆ scanForFiles

- (void) scanForFiles

Extends class OOFileScannerVerifierStage.

Definition at line 761 of file OOFileScannerVerifierStage.m.

325{
326 NSDirectoryEnumerator *dirEnum = nil;
327 NSString *name = nil,
328 *path = nil,
329 *type = nil,
330 *lcName = nil,
331 *existing = nil,
332 *existingType = nil;
333 NSMutableDictionary *directoryListings = nil,
334 *directoryCases = nil,
335 *rootFiles = nil;
336 NSDictionary *dirFiles = nil;
337 NSSet *readMeNames = nil;
338
339 _basePath = [[[self verifier] oxpPath] copy];
340
341 _junkFileNames = [[self verifier] configurationSetForKey:@"junkFiles"];
342 _skipDirectoryNames = [[self verifier] configurationSetForKey:@"skipDirectories"];
343
344 directoryCases = [NSMutableDictionary dictionary];
345 directoryListings = [NSMutableDictionary dictionary];
346 rootFiles = [NSMutableDictionary dictionary];
347 readMeNames = [self constructReadMeNames];
348
349 dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:_basePath];
350 while ((name = [dirEnum nextObject]))
351 {
352 path = [_basePath stringByAppendingPathComponent:name];
353 type = [[dirEnum fileAttributes] fileType];
354 lcName = [name lowercaseString];
355
356 if ([type isEqualToString:NSFileTypeDirectory])
357 {
358 [dirEnum skipDescendents];
359
360 if ([_skipDirectoryNames containsObject:name])
361 {
362 // Silently skip .svn and CVS
363 OOLog(@"verifyOXP.verbose.listFiles", @"- Skipping %@/", name);
364 }
365 else if (!CheckNameConflict(lcName, directoryCases, rootFiles, &existing, &existingType))
366 {
367 OOLog(@"verifyOXP.verbose.listFiles", @"- %@/", name);
368 OOLogIndentIf(@"verifyOXP.verbose.listFiles");
369 dirFiles = [self scanDirectory:path];
370 [directoryListings setObject:dirFiles forKey:lcName];
371 [directoryCases setObject:name forKey:lcName];
372 OOLogOutdentIf(@"verifyOXP.verbose.listFiles");
373 }
374 else
375 {
376 OOLog(@"verifyOXP.scanFiles.overloadedName", @"***** ERROR: %@ '%@' conflicts with %@ named '%@', ignoring. (OXPs must work on case-insensitive file systems!)", @"directory", name, existingType, existing);
377 }
378 }
379 else if ([type isEqualToString:NSFileTypeRegular])
380 {
381 if ([_junkFileNames containsObject:name])
382 {
383 OOLog(@"verifyOXP.scanFiles.skipJunk", @"NOTE: skipping junk file %@.", name);
384 }
385 else if ([readMeNames containsObject:lcName])
386 {
387 OOLog(@"verifyOXP.scanFiles.readMe", @"----- WARNING: apparent Read Me file (\"%@\") inside OXP. This is the wrong place for a Read Me file, because it will not be read.", name);
388 }
389 else if (!CheckNameConflict(lcName, directoryCases, rootFiles, &existing, &existingType))
390 {
391 OOLog(@"verifyOXP.verbose.listFiles", @"- %@", name);
392 [rootFiles setObject:name forKey:lcName];
393 }
394 else
395 {
396 OOLog(@"verifyOXP.scanFiles.overloadedName", @"***** ERROR: %@ '%@' conflicts with %@ named '%@', ignoring. (OXPs must work on case-insensitive file systems!)", @"file", name, existingType, existing);
397 }
398 }
399 else if ([type isEqualToString:NSFileTypeSymbolicLink])
400 {
401 OOLog(@"verifyOXP.scanFiles.symLink", @"----- WARNING: \"%@\" is a symbolic link, ignoring.", name);
402 }
403 else
404 {
405 OOLog(@"verifyOXP.scanFiles.nonStandardFile", @"----- WARNING: \"%@\" is a non-standard file (%@), ignoring.", name, type);
406 }
407 }
408
409 _junkFileNames = nil;
410 _skipDirectoryNames = nil;
411
412 [directoryListings setObject:rootFiles forKey:@""];
413 _directoryListings = [directoryListings copy];
414 _directoryCases = [directoryCases copy];
415}
static BOOL CheckNameConflict(NSString *lcName, NSDictionary *directoryCases, NSDictionary *rootFiles, NSString **outExisting, NSString **outExistingType)
#define OOLogOutdentIf(class)
Definition OOLogging.h:102
#define OOLogIndentIf(class)
Definition OOLogging.h:101

The documentation for this category was generated from the following file: