Index: /trunk/psLib/src/types/psMetadata.c
===================================================================
--- /trunk/psLib/src/types/psMetadata.c	(revision 18713)
+++ /trunk/psLib/src/types/psMetadata.c	(revision 18714)
@@ -12,6 +12,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.170 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-06-20 02:50:27 $
+ *  @version $Revision: 1.171 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-07-24 22:42:28 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -509,42 +509,42 @@
     while ((inItem = psMetadataGetAndIncrement(iter))) {
 
-	// it is not possible to have RESET && UPDATE
-	// is it possible to have !RESET && !UPDATE?
-	// are these mutually exclusive conditions?
-	// input MULTI & RESET  : replace an existing MULTI or ITEM of same name
-	// input MULTI & UPDATE : supplement an existing MULTI or ITEM of same name
-	// in both cases the name must exist in 'out' 
+        // it is not possible to have RESET && UPDATE
+        // is it possible to have !RESET && !UPDATE?
+        // are these mutually exclusive conditions?
+        // input MULTI & RESET  : replace an existing MULTI or ITEM of same name
+        // input MULTI & UPDATE : supplement an existing MULTI or ITEM of same name
+        // in both cases the name must exist in 'out'
 
         // Need to look for MULTI, which won't be picked up using the iterator.
         psMetadataItem *multiCheckItem = psMetadataLookup(in, inItem->name);
 
-	// default operation for the new metadata item (replace existing entry, require existence & type)
-        unsigned int flag = PS_META_REPLACE | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE; 
-
-	// for MULTI items, the mode is carried on the multi container
+        // default operation for the new metadata item (replace existing entry, require existence & type)
+        unsigned int flag = PS_META_REPLACE | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;
+
+        // for MULTI items, the mode is carried on the multi container
         if (PS_METADATA_ITEM_GET_TYPE(multiCheckItem) == PS_DATA_METADATA_MULTI) {
-	    psTrace("psLib.types", 10, "MULTI: %s (%s)\n", inItem->name, inItem->comment);
-	    if (multiCheckItem->type & PS_META_UPDATE_FOLDER) {
-		psTrace("psLib.types", 10, "supplement MULTI with new entries\n");
-		flag = PS_META_DUPLICATE_OK | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;
-	    } else {
-		multiCheckItem->type |= PS_META_UPDATE_FOLDER;
-		// save this multi so we can reset their flags below
-		psArrayAdd (multiItems, 128, multiCheckItem); 
-	    }
+            psTrace("psLib.types", 10, "MULTI: %s (%s)\n", inItem->name, inItem->comment);
+            if (multiCheckItem->type & PS_META_UPDATE_FOLDER) {
+                psTrace("psLib.types", 10, "supplement MULTI with new entries\n");
+                flag = PS_META_DUPLICATE_OK | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;
+            } else {
+                multiCheckItem->type |= PS_META_UPDATE_FOLDER;
+                // save this multi so we can reset their flags below
+                psArrayAdd (multiItems, 128, multiCheckItem);
+            }
         }
         psTrace("psLib.types", 5, "Copying %s (%s)...\n", inItem->name, inItem->comment);
 
-	// for METADATA folders, do something different?
+        // for METADATA folders, do something different?
         if (PS_METADATA_ITEM_GET_TYPE(inItem) == PS_DATA_METADATA) {
-	    if (inItem->type & PS_META_UPDATE_FOLDER) {
-		flag = PS_META_UPDATE_FOLDER | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;
-	    }
-	}
+            if (inItem->type & PS_META_UPDATE_FOLDER) {
+                flag = PS_META_UPDATE_FOLDER | PS_META_REQUIRE_ENTRY | PS_META_REQUIRE_TYPE;
+            }
+        }
 
         // Copy the item and add it on.  report all errors so we get a listing
         psMetadataItem *newItem = psMetadataItemCopy(inItem); // Copied item
         if (!psMetadataAddItem(out, newItem, PS_LIST_TAIL, flag)) {
-	    psError(PS_ERR_UNKNOWN, false, "Error copying %s\n", inItem->name);
+            psError(PS_ERR_UNKNOWN, false, "Error copying %s\n", inItem->name);
             result = false;
         }
@@ -555,6 +555,6 @@
     // remove the UPDATE_FOLDER flag from the following MULTI items
     for (int i = 0; i < multiItems->n; i++) {
-	psMetadataItem *item = multiItems->data[i];
-	item->type &= ~PS_META_UPDATE_FOLDER;
+        psMetadataItem *item = multiItems->data[i];
+        item->type &= ~PS_META_UPDATE_FOLDER;
     }
     psFree (multiItems);
@@ -643,5 +643,5 @@
 }
 
-// XXX is it sensible that item is a 'const' here? 
+// XXX is it sensible that item is a 'const' here?
 bool psMetadataAddItem(psMetadata *md,
                        const psMetadataItem *item,
@@ -664,5 +664,5 @@
 
         // Shouldn't have a second reference to the same MULTI in a single Metadata!
-	// XXX not sure I understand this case 
+        // XXX not sure I understand this case
         if (item == existingEntry) {
             psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot have 2 references to the same MULTI in a single Metadata!");
@@ -670,11 +670,11 @@
         }
 
-	if (flags & PS_META_REPLACE) {
-	    // drop the existing entry or entries
-	    psMetadataRemoveKey(md, key);
-	} else {
-	    // elevate the existing hash entry to be PS_DATA_METADATA_MULTI
-	    existingEntry = makeMetaMulti(mdTable,key,existingEntry);
-	}
+        if (flags & PS_META_REPLACE) {
+            // drop the existing entry or entries
+            psMetadataRemoveKey(md, key);
+        } else {
+            // elevate the existing hash entry to be PS_DATA_METADATA_MULTI
+            existingEntry = makeMetaMulti(mdTable,key,existingEntry);
+        }
 
         // add all the items in the incoming entry to metadata
@@ -694,33 +694,33 @@
     // special block for items which are METADATA folders
     if (existingEntry && (item->type == PS_DATA_METADATA)) {
-	// REPLACE and UPDATE must be mutually exclusive
-	psAssert ((!((flags & PS_META_REPLACE) && (flags & PS_META_UPDATE_FOLDER))), "cannot have both REPLACE and UPDATE");
-
-	# if (0) 
-	// handle the case of replace below
-	if (flags & PS_META_REPLACE) {
-	    // drop the existing entry (skip if we are replacing with same pointer)
-	    // XXX what if existingEntry is a MULTI?  drop all?
-	    // XXX this segment does not check for matched types
-	    if (item != existingEntry) {
-		psMetadataRemoveKey(md, key);
-	    }
-	    existingEntry = NULL;
-	} 
-	# endif
-
-	if (flags & PS_META_UPDATE_FOLDER) {
-	    if (existingEntry->type != PS_DATA_METADATA) {
+        // REPLACE and UPDATE must be mutually exclusive
+        psAssert ((!((flags & PS_META_REPLACE) && (flags & PS_META_UPDATE_FOLDER))), "cannot have both REPLACE and UPDATE");
+
+        # if (0)
+        // handle the case of replace below
+        if (flags & PS_META_REPLACE) {
+            // drop the existing entry (skip if we are replacing with same pointer)
+            // XXX what if existingEntry is a MULTI?  drop all?
+            // XXX this segment does not check for matched types
+            if (item != existingEntry) {
+                psMetadataRemoveKey(md, key);
+            }
+            existingEntry = NULL;
+        }
+        # endif
+
+        if (flags & PS_META_UPDATE_FOLDER) {
+            if (existingEntry->type != PS_DATA_METADATA) {
                 psError(PS_ERR_UNKNOWN, false, "invalid to request UPDATE for metadata which matches another type");
                 return false;
             }
-		
-	    // merge the existing entry : this completes the insert
-	    if (!psMetadataCopy ((psMetadata *)existingEntry->data.V, (psMetadata *)item->data.V)) {
+
+            // merge the existing entry : this completes the insert
+            if (!psMetadataCopy ((psMetadata *)existingEntry->data.V, (psMetadata *)item->data.V)) {
                 psError(PS_ERR_UNKNOWN, false, "failed to copy new metadata on existing");
                 return false;
             }
-	    return true;
-	}
+            return true;
+        }
     }
 
@@ -729,5 +729,5 @@
     if (existingEntry) { // prior existence
 
-	// duplicate entries allowed - add another entry.
+        // duplicate entries allowed - add another entry.
         if ((existingEntry->type == PS_DATA_METADATA_MULTI) || (flags & PS_META_DUPLICATE_OK)) {
 
@@ -741,13 +741,13 @@
             }
             // add to the metadata list of entries
-	    if (!psListAdd(mdList, location, (psMetadataItem *) item)) {
-		psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
-		return false;
-	    }
-	    return true;
-        } 
-
-	// replace entry instead of creating a duplicate entry.
-	if (flags & PS_META_REPLACE) {
+            if (!psListAdd(mdList, location, (psMetadataItem *) item)) {
+                psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
+                return false;
+            }
+            return true;
+        }
+
+        // replace entry instead of creating a duplicate entry.
+        if (flags & PS_META_REPLACE) {
 
             if ((flags & PS_META_REQUIRE_TYPE) && (existingEntry->type != item->type)) {
@@ -759,35 +759,35 @@
                 // when you blow away what you're trying to add
                 psMetadataRemoveKey(md, key);
-		// add to the metadata has of entries
+                // add to the metadata has of entries
                 if (!psHashAdd(mdTable, key, (psMetadataItem *) item)) {
-		    psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
-		    return false;
-		}		    
-		// add to the metadata list of entries
-		if (!psListAdd(mdList, location, (psMetadataItem *) item)) {
-		    psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
-		    return false;
-		}
-		return true;
+                    psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
+                    return false;
+                }
+                // add to the metadata list of entries
+                if (!psListAdd(mdList, location, (psMetadataItem *) item)) {
+                    psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
+                    return false;
+                }
+                return true;
             } else {
-	      // adding myself back to the list; this is a NOP
-	      return true;
-	    }
-        } 
-
-	// if specified, keep the existing entry
-	if (flags & PS_META_NO_REPLACE) {
-	    return true;
-	}
-
-	// default is to error on duplicate entry.
-	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);
-	return false;
+              // adding myself back to the list; this is a NOP
+              return true;
+            }
+        }
+
+        // if specified, keep the existing entry
+        if (flags & PS_META_NO_REPLACE) {
+            return true;
+        }
+
+        // default is to error on duplicate entry.
+        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);
+        return false;
     }
 
     // OK, this is a new item.
     if (flags & PS_META_REQUIRE_ENTRY) {
-	psError (PS_ERR_UNKNOWN, true, _("No matching item found for item requiring existing entry (%s)"), key);
-	return false;
+        psError (PS_ERR_UNKNOWN, true, _("No matching item found for item requiring existing entry (%s)"), key);
+        return false;
     }
 
@@ -797,5 +797,5 @@
     // Create a multi, if requested
     if (flags & PS_META_DUPLICATE_OK) {
-	makeMetaMulti(mdTable, key, (psMetadataItem *) item); // Casting away const!
+        makeMetaMulti(mdTable, key, (psMetadataItem *) item); // Casting away const!
     }
 
@@ -1176,5 +1176,8 @@
             (void)psListGetAndDecrement(listIter);
         }
-        return (match == location);
+
+        // We return "true" even if we didn't find the Nth match, because the iterator is set appropriately
+        // (off the front), and subsequent calls to psMetadataGetAnd{In,De}crement will return NULL.
+        return true;
     }
 
@@ -1193,5 +1196,7 @@
         (void)psListGetAndIncrement(listIter);
     }
-    return (match == location);
+    // We return "true" even if we 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.
+    return true;
 }
 
