Changeset 8064
- Timestamp:
- Aug 1, 2006, 7:03:50 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfig.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r7920 r8064 3 3 * @author PAP, IfA 4 4 * 5 * @version $Revision: 1.3 4$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-0 7-18 00:56:49$5 * @version $Revision: 1.35 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-08-02 05:03:50 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 638 638 // We could use psMetadataCopy for this, but it's better to check that everything's of the correct type. 639 639 // If it's not of the correct type, we can tell the user which file it's in, so they can find it easier. 640 psMetadataIterator *recipesIter = psMetadataIteratorAlloc(recipes, PS_LIST_HEAD, NULL); // Iterator 641 psMetadataItem *fileItem = NULL; // MD item containing the filename, from recipe iteration 642 while ((fileItem = psMetadataGetAndIncrement(recipesIter))) { 643 if (fileItem->type != PS_DATA_STRING) { 644 psLogMsg(__func__, PS_LOG_WARN, "Recipe %s from %s is not of type STR --- ignored.\n", 645 fileItem->name, sourceName); 646 continue; 647 } 648 649 // Check to see if it's currently defined 650 int check = psMetadataLookupS32(&mdok, config->recipesSource, fileItem->name); 651 if (mdok && check > sourceType) { 652 // It's already defined with a higher priority 653 continue; 654 } 655 psString comment = psStringCopy("Recipe added at "); 656 psStringAppend(&comment, "%s from %s", sourceName, fileItem->data.V); 657 psMetadataAddS32(config->recipesSource, PS_LIST_TAIL, fileItem->name, 658 PS_META_REPLACE, comment, sourceType); 659 psFree(comment); 660 661 // Read the recipe 662 psMetadata *recipe = NULL; // Recipe from file 663 if (readConfig(&recipe, fileItem->data.V, "recipe")) { 664 psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, 665 PS_DATA_METADATA | PS_META_REPLACE, fileItem->comment, recipe); 666 } else { 667 psError(PS_ERR_IO, false, "Failed to read recipe"); 668 669 psFree(recipe); // Drop reference 670 psFree(recipesIter); 671 672 return false; 673 } 674 psFree(recipe); // Drop reference 675 } 676 psFree(recipesIter); 677 640 { 641 psMetadataIterator *recipesIter = psMetadataIteratorAlloc(recipes, PS_LIST_HEAD, NULL); // Iterator 642 psMetadataItem *fileItem = NULL; // MD item containing the filename, from recipe iteration 643 while ((fileItem = psMetadataGetAndIncrement(recipesIter))) 644 { 645 if (fileItem->type != PS_DATA_STRING) { 646 psLogMsg(__func__, PS_LOG_WARN, "Recipe %s from %s is not of type STR --- ignored.\n", 647 fileItem->name, sourceName); 648 continue; 649 } 650 651 // Check to see if it's currently defined 652 int check = psMetadataLookupS32(&mdok, config->recipesSource, fileItem->name); 653 if (mdok && check > sourceType) { 654 // It's already defined with a higher priority 655 continue; 656 } 657 psString comment = psStringCopy("Recipe added at "); 658 psStringAppend(&comment, "%s from %s", sourceName, fileItem->data.V); 659 psMetadataAddS32(config->recipesSource, PS_LIST_TAIL, fileItem->name, 660 PS_META_REPLACE, comment, sourceType); 661 psFree(comment); 662 663 // Read the recipe 664 psMetadata *recipe = NULL; // Recipe from file 665 if (readConfig(&recipe, fileItem->data.V, "recipe")) { 666 psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, 667 PS_DATA_METADATA | PS_META_REPLACE, fileItem->comment, recipe); 668 } else { 669 psError(PS_ERR_IO, false, "Failed to read recipe"); 670 671 psFree(recipe); // Drop reference 672 psFree(recipesIter); 673 674 return false; 675 } 676 psFree(recipe); // Drop reference 677 } 678 psFree(recipesIter); 679 } 678 680 config->recipesRead |= sourceType; 679 681 680 // Having read that, we now need to check to see if any symbolic links need to be resolved 681 recipesIter = psMetadataIteratorAlloc(config->recipesSource, PS_LIST_HEAD, NULL); 682 psMetadataItem *sourceItem = NULL; // Item containing source, from iteration 683 while ((sourceItem = psMetadataGetAndIncrement(recipesIter))) { 684 assert(sourceItem->type == PS_TYPE_S32); // It should be this type: we put it in ourselves 685 if (sourceItem->data.S32 == P_PM_RECIPE_SOURCE_SYMBOLIC) { 686 const char *linkName = sourceItem->comment; // The name of the link 687 psMetadata *linkSource = psMetadataLookupMD(&mdok, config->recipes, linkName); // The source 688 if (!mdok || !linkSource) { 689 psLogMsg(__func__, PS_LOG_WARN, "Unable to resolve symbolic link for recipe %s to %s " 690 "--- ignored.\n", sourceItem->name, linkName); 691 continue; 692 } 693 psMetadataItem *target = psMetadataLookup(config->recipes, sourceItem->name); // The target item 694 assert(target); // It had better be here: it's in the "sourcesRead" metadata 695 psFree(target->data.V); // Free old copy 696 target->data.V = psMetadataCopy(NULL, linkSource); 697 } 698 } 699 psFree(recipesIter); 682 { 683 // Having read that, we now need to check to see if any symbolic links need to be resolved 684 psMetadataIterator *recipesIter = psMetadataIteratorAlloc(config->recipesSource, PS_LIST_HEAD, NULL); 685 psMetadataItem *sourceItem = NULL; // Item containing source, from iteration 686 while ((sourceItem = psMetadataGetAndIncrement(recipesIter))) { 687 assert(sourceItem->type == PS_TYPE_S32); // It should be this type: we put it in ourselves 688 if (sourceItem->data.S32 == P_PM_RECIPE_SOURCE_SYMBOLIC) { 689 const char *linkName = sourceItem->comment; // The name of the link 690 psMetadata *linkSource = psMetadataLookupMD(&mdok, config->recipes, linkName); // The source 691 if (!mdok || !linkSource) { 692 // Can't yet resolve it 693 continue; 694 } 695 psString comment = NULL; 696 psStringAppend(&comment, "Symbolic link from %s", linkName); 697 psMetadataAdd(config->recipes, PS_LIST_TAIL, sourceItem->name, 698 PS_DATA_METADATA | PS_META_REPLACE, comment, linkSource); 699 psFree(comment); 700 } 701 } 702 psFree(recipesIter); 703 } 700 704 return true; 701 705 } … … 769 773 recipeSource, P_PM_RECIPE_SOURCE_SYMBOLIC); 770 774 771 } else {772 // Otherwise, treat the source as a filename775 } else if (access(recipeSource, R_OK) == 0) { 776 // The source is a file 773 777 psMetadata *recipe = NULL; // Recipe from file 774 778 if (readConfig(&recipe, recipeSource, "recipe")) { … … 782 786 "Recipe added from command line", P_PM_RECIPE_SOURCE_CL); 783 787 } 788 } else { 789 // Assume it's a symbolic reference to something that's not yet read in 790 printf("==> %s points to %s\n", recipeName, recipeSource); 791 psMetadataAddS32(config->recipesSource, PS_LIST_TAIL, recipeName, PS_META_REPLACE, 792 recipeSource, P_PM_RECIPE_SOURCE_SYMBOLIC); 784 793 } 785 794 psFree(recipeName);
Note:
See TracChangeset
for help on using the changeset viewer.
