Changeset 18714
- Timestamp:
- Jul 24, 2008, 12:42:28 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/types/psMetadata.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psMetadata.c
r18209 r18714 12 12 * @author Ross Harman, MHPCC 13 13 * 14 * @version $Revision: 1.17 0$ $Name: not supported by cvs2svn $15 * @date $Date: 2008-0 6-20 02:50:27$14 * @version $Revision: 1.171 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2008-07-24 22:42:28 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 509 509 while ((inItem = psMetadataGetAndIncrement(iter))) { 510 510 511 // it is not possible to have RESET && UPDATE512 // is it possible to have !RESET && !UPDATE?513 // are these mutually exclusive conditions?514 // input MULTI & RESET : replace an existing MULTI or ITEM of same name515 // input MULTI & UPDATE : supplement an existing MULTI or ITEM of same name516 // in both cases the name must exist in 'out' 511 // it is not possible to have RESET && UPDATE 512 // is it possible to have !RESET && !UPDATE? 513 // are these mutually exclusive conditions? 514 // input MULTI & RESET : replace an existing MULTI or ITEM of same name 515 // input MULTI & UPDATE : supplement an existing MULTI or ITEM of same name 516 // in both cases the name must exist in 'out' 517 517 518 518 // Need to look for MULTI, which won't be picked up using the iterator. 519 519 psMetadataItem *multiCheckItem = psMetadataLookup(in, inItem->name); 520 520 521 // default operation for the new metadata item (replace existing entry, require existence & type)522 unsigned int flag = PS_META_REPLACE | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE; 523 524 // for MULTI items, the mode is carried on the multi container521 // default operation for the new metadata item (replace existing entry, require existence & type) 522 unsigned int flag = PS_META_REPLACE | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE; 523 524 // for MULTI items, the mode is carried on the multi container 525 525 if (PS_METADATA_ITEM_GET_TYPE(multiCheckItem) == PS_DATA_METADATA_MULTI) { 526 psTrace("psLib.types", 10, "MULTI: %s (%s)\n", inItem->name, inItem->comment);527 if (multiCheckItem->type & PS_META_UPDATE_FOLDER) {528 psTrace("psLib.types", 10, "supplement MULTI with new entries\n");529 flag = PS_META_DUPLICATE_OK | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;530 } else {531 multiCheckItem->type |= PS_META_UPDATE_FOLDER;532 // save this multi so we can reset their flags below533 psArrayAdd (multiItems, 128, multiCheckItem); 534 }526 psTrace("psLib.types", 10, "MULTI: %s (%s)\n", inItem->name, inItem->comment); 527 if (multiCheckItem->type & PS_META_UPDATE_FOLDER) { 528 psTrace("psLib.types", 10, "supplement MULTI with new entries\n"); 529 flag = PS_META_DUPLICATE_OK | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE; 530 } else { 531 multiCheckItem->type |= PS_META_UPDATE_FOLDER; 532 // save this multi so we can reset their flags below 533 psArrayAdd (multiItems, 128, multiCheckItem); 534 } 535 535 } 536 536 psTrace("psLib.types", 5, "Copying %s (%s)...\n", inItem->name, inItem->comment); 537 537 538 // for METADATA folders, do something different?538 // for METADATA folders, do something different? 539 539 if (PS_METADATA_ITEM_GET_TYPE(inItem) == PS_DATA_METADATA) { 540 if (inItem->type & PS_META_UPDATE_FOLDER) {541 flag = PS_META_UPDATE_FOLDER | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;542 }543 }540 if (inItem->type & PS_META_UPDATE_FOLDER) { 541 flag = PS_META_UPDATE_FOLDER | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE; 542 } 543 } 544 544 545 545 // Copy the item and add it on. report all errors so we get a listing 546 546 psMetadataItem *newItem = psMetadataItemCopy(inItem); // Copied item 547 547 if (!psMetadataAddItem(out, newItem, PS_LIST_TAIL, flag)) { 548 psError(PS_ERR_UNKNOWN, false, "Error copying %s\n", inItem->name);548 psError(PS_ERR_UNKNOWN, false, "Error copying %s\n", inItem->name); 549 549 result = false; 550 550 } … … 555 555 // remove the UPDATE_FOLDER flag from the following MULTI items 556 556 for (int i = 0; i < multiItems->n; i++) { 557 psMetadataItem *item = multiItems->data[i];558 item->type &= ~PS_META_UPDATE_FOLDER;557 psMetadataItem *item = multiItems->data[i]; 558 item->type &= ~PS_META_UPDATE_FOLDER; 559 559 } 560 560 psFree (multiItems); … … 643 643 } 644 644 645 // XXX is it sensible that item is a 'const' here? 645 // XXX is it sensible that item is a 'const' here? 646 646 bool psMetadataAddItem(psMetadata *md, 647 647 const psMetadataItem *item, … … 664 664 665 665 // Shouldn't have a second reference to the same MULTI in a single Metadata! 666 // XXX not sure I understand this case 666 // XXX not sure I understand this case 667 667 if (item == existingEntry) { 668 668 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot have 2 references to the same MULTI in a single Metadata!"); … … 670 670 } 671 671 672 if (flags & PS_META_REPLACE) {673 // drop the existing entry or entries674 psMetadataRemoveKey(md, key);675 } else {676 // elevate the existing hash entry to be PS_DATA_METADATA_MULTI677 existingEntry = makeMetaMulti(mdTable,key,existingEntry);678 }672 if (flags & PS_META_REPLACE) { 673 // drop the existing entry or entries 674 psMetadataRemoveKey(md, key); 675 } else { 676 // elevate the existing hash entry to be PS_DATA_METADATA_MULTI 677 existingEntry = makeMetaMulti(mdTable,key,existingEntry); 678 } 679 679 680 680 // add all the items in the incoming entry to metadata … … 694 694 // special block for items which are METADATA folders 695 695 if (existingEntry && (item->type == PS_DATA_METADATA)) { 696 // REPLACE and UPDATE must be mutually exclusive697 psAssert ((!((flags & PS_META_REPLACE) && (flags & PS_META_UPDATE_FOLDER))), "cannot have both REPLACE and UPDATE");698 699 # if (0) 700 // handle the case of replace below701 if (flags & PS_META_REPLACE) {702 // drop the existing entry (skip if we are replacing with same pointer)703 // XXX what if existingEntry is a MULTI? drop all?704 // XXX this segment does not check for matched types705 if (item != existingEntry) {706 psMetadataRemoveKey(md, key);707 }708 existingEntry = NULL;709 } 710 # endif711 712 if (flags & PS_META_UPDATE_FOLDER) {713 if (existingEntry->type != PS_DATA_METADATA) {696 // REPLACE and UPDATE must be mutually exclusive 697 psAssert ((!((flags & PS_META_REPLACE) && (flags & PS_META_UPDATE_FOLDER))), "cannot have both REPLACE and UPDATE"); 698 699 # if (0) 700 // handle the case of replace below 701 if (flags & PS_META_REPLACE) { 702 // drop the existing entry (skip if we are replacing with same pointer) 703 // XXX what if existingEntry is a MULTI? drop all? 704 // XXX this segment does not check for matched types 705 if (item != existingEntry) { 706 psMetadataRemoveKey(md, key); 707 } 708 existingEntry = NULL; 709 } 710 # endif 711 712 if (flags & PS_META_UPDATE_FOLDER) { 713 if (existingEntry->type != PS_DATA_METADATA) { 714 714 psError(PS_ERR_UNKNOWN, false, "invalid to request UPDATE for metadata which matches another type"); 715 715 return false; 716 716 } 717 718 // merge the existing entry : this completes the insert719 if (!psMetadataCopy ((psMetadata *)existingEntry->data.V, (psMetadata *)item->data.V)) {717 718 // merge the existing entry : this completes the insert 719 if (!psMetadataCopy ((psMetadata *)existingEntry->data.V, (psMetadata *)item->data.V)) { 720 720 psError(PS_ERR_UNKNOWN, false, "failed to copy new metadata on existing"); 721 721 return false; 722 722 } 723 return true;724 }723 return true; 724 } 725 725 } 726 726 … … 729 729 if (existingEntry) { // prior existence 730 730 731 // duplicate entries allowed - add another entry.731 // duplicate entries allowed - add another entry. 732 732 if ((existingEntry->type == PS_DATA_METADATA_MULTI) || (flags & PS_META_DUPLICATE_OK)) { 733 733 … … 741 741 } 742 742 // add to the metadata list of entries 743 if (!psListAdd(mdList, location, (psMetadataItem *) item)) {744 psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);745 return false;746 }747 return true;748 } 749 750 // replace entry instead of creating a duplicate entry.751 if (flags & PS_META_REPLACE) {743 if (!psListAdd(mdList, location, (psMetadataItem *) item)) { 744 psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key); 745 return false; 746 } 747 return true; 748 } 749 750 // replace entry instead of creating a duplicate entry. 751 if (flags & PS_META_REPLACE) { 752 752 753 753 if ((flags & PS_META_REQUIRE_TYPE) && (existingEntry->type != item->type)) { … … 759 759 // when you blow away what you're trying to add 760 760 psMetadataRemoveKey(md, key); 761 // add to the metadata has of entries761 // add to the metadata has of entries 762 762 if (!psHashAdd(mdTable, key, (psMetadataItem *) item)) { 763 psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);764 return false;765 } 766 // add to the metadata list of entries767 if (!psListAdd(mdList, location, (psMetadataItem *) item)) {768 psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);769 return false;770 }771 return true;763 psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key); 764 return false; 765 } 766 // add to the metadata list of entries 767 if (!psListAdd(mdList, location, (psMetadataItem *) item)) { 768 psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key); 769 return false; 770 } 771 return true; 772 772 } else { 773 // adding myself back to the list; this is a NOP774 return true;775 }776 } 777 778 // if specified, keep the existing entry779 if (flags & PS_META_NO_REPLACE) {780 return true;781 }782 783 // default is to error on duplicate entry.784 psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Duplicate metadata item name: %s is not allowed. Use a psMetadataFlags option to allow such action."), item->name);785 return false;773 // adding myself back to the list; this is a NOP 774 return true; 775 } 776 } 777 778 // if specified, keep the existing entry 779 if (flags & PS_META_NO_REPLACE) { 780 return true; 781 } 782 783 // default is to error on duplicate entry. 784 psError(PS_ERR_BAD_PARAMETER_VALUE, true, _("Duplicate metadata item name: %s is not allowed. Use a psMetadataFlags option to allow such action."), item->name); 785 return false; 786 786 } 787 787 788 788 // OK, this is a new item. 789 789 if (flags & PS_META_REQUIRE_ENTRY) { 790 psError (PS_ERR_UNKNOWN, true, _("No matching item found for item requiring existing entry (%s)"), key);791 return false;790 psError (PS_ERR_UNKNOWN, true, _("No matching item found for item requiring existing entry (%s)"), key); 791 return false; 792 792 } 793 793 … … 797 797 // Create a multi, if requested 798 798 if (flags & PS_META_DUPLICATE_OK) { 799 makeMetaMulti(mdTable, key, (psMetadataItem *) item); // Casting away const!799 makeMetaMulti(mdTable, key, (psMetadataItem *) item); // Casting away const! 800 800 } 801 801 … … 1176 1176 (void)psListGetAndDecrement(listIter); 1177 1177 } 1178 return (match == location); 1178 1179 // We return "true" even if we didn't find the Nth match, because the iterator is set appropriately 1180 // (off the front), and subsequent calls to psMetadataGetAnd{In,De}crement will return NULL. 1181 return true; 1179 1182 } 1180 1183 … … 1193 1196 (void)psListGetAndIncrement(listIter); 1194 1197 } 1195 return (match == location); 1198 // We return "true" even if we didn't find the Nth match, because the iterator is set appropriately 1199 // (off the end), and subsequent calls to psMetadataGetAnd{In,De}crement will return NULL. 1200 return true; 1196 1201 } 1197 1202
Note:
See TracChangeset
for help on using the changeset viewer.
