IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18714


Ignore:
Timestamp:
Jul 24, 2008, 12:42:28 PM (18 years ago)
Author:
Paul Price
Message:

psMetadataIteratorSet should return "true" even if it didn't find the
Nth match, because the iterator is set appropriately (off the end),
and subsequent calls to psMetadataGetAnd{In,De}crement will return
NULL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psMetadata.c

    r18209 r18714  
    1212 *  @author Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.170 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2008-06-20 02:50:27 $
     14 *  @version $Revision: 1.171 $ $Name: not supported by cvs2svn $
     15 *  @date $Date: 2008-07-24 22:42:28 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    509509    while ((inItem = psMetadataGetAndIncrement(iter))) {
    510510
    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'
     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'
    517517
    518518        // Need to look for MULTI, which won't be picked up using the iterator.
    519519        psMetadataItem *multiCheckItem = psMetadataLookup(in, inItem->name);
    520520
    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 container
     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 container
    525525        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 below
    533                 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            }
    535535        }
    536536        psTrace("psLib.types", 5, "Copying %s (%s)...\n", inItem->name, inItem->comment);
    537537
    538         // for METADATA folders, do something different?
     538        // for METADATA folders, do something different?
    539539        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        }
    544544
    545545        // Copy the item and add it on.  report all errors so we get a listing
    546546        psMetadataItem *newItem = psMetadataItemCopy(inItem); // Copied item
    547547        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);
    549549            result = false;
    550550        }
     
    555555    // remove the UPDATE_FOLDER flag from the following MULTI items
    556556    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;
    559559    }
    560560    psFree (multiItems);
     
    643643}
    644644
    645 // XXX is it sensible that item is a 'const' here? 
     645// XXX is it sensible that item is a 'const' here?
    646646bool psMetadataAddItem(psMetadata *md,
    647647                       const psMetadataItem *item,
     
    664664
    665665        // 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
    667667        if (item == existingEntry) {
    668668            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot have 2 references to the same MULTI in a single Metadata!");
     
    670670        }
    671671
    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         }
     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        }
    679679
    680680        // add all the items in the incoming entry to metadata
     
    694694    // special block for items which are METADATA folders
    695695    if (existingEntry && (item->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) {
     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) {
    714714                psError(PS_ERR_UNKNOWN, false, "invalid to request UPDATE for metadata which matches another type");
    715715                return false;
    716716            }
    717                
    718             // merge the existing entry : this completes the insert
    719             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)) {
    720720                psError(PS_ERR_UNKNOWN, false, "failed to copy new metadata on existing");
    721721                return false;
    722722            }
    723             return true;
    724         }
     723            return true;
     724        }
    725725    }
    726726
     
    729729    if (existingEntry) { // prior existence
    730730
    731         // duplicate entries allowed - add another entry.
     731        // duplicate entries allowed - add another entry.
    732732        if ((existingEntry->type == PS_DATA_METADATA_MULTI) || (flags & PS_META_DUPLICATE_OK)) {
    733733
     
    741741            }
    742742            // 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) {
    752752
    753753            if ((flags & PS_META_REQUIRE_TYPE) && (existingEntry->type != item->type)) {
     
    759759                // when you blow away what you're trying to add
    760760                psMetadataRemoveKey(md, key);
    761                 // add to the metadata has of entries
     761                // add to the metadata has of entries
    762762                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 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;
     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;
    772772            } else {
    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;
     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;
    786786    }
    787787
    788788    // OK, this is a new item.
    789789    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;
    792792    }
    793793
     
    797797    // Create a multi, if requested
    798798    if (flags & PS_META_DUPLICATE_OK) {
    799         makeMetaMulti(mdTable, key, (psMetadataItem *) item); // Casting away const!
     799        makeMetaMulti(mdTable, key, (psMetadataItem *) item); // Casting away const!
    800800    }
    801801
     
    11761176            (void)psListGetAndDecrement(listIter);
    11771177        }
    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;
    11791182    }
    11801183
     
    11931196        (void)psListGetAndIncrement(listIter);
    11941197    }
    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;
    11961201}
    11971202
Note: See TracChangeset for help on using the changeset viewer.