Index: /branches/eam_branch_20080430/psLib/src/types/psMetadata.c
===================================================================
--- /branches/eam_branch_20080430/psLib/src/types/psMetadata.c	(revision 17497)
+++ /branches/eam_branch_20080430/psLib/src/types/psMetadata.c	(revision 17498)
@@ -12,6 +12,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.168.6.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-04-30 21:04:22 $
+ *  @version $Revision: 1.168.6.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-05-02 00:10:43 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -642,5 +642,5 @@
 }
 
-
+// XXX is it sensible that item is a 'const' here? 
 bool psMetadataAddItem(psMetadata *md,
                        const psMetadataItem *item,
@@ -648,31 +648,32 @@
                        psS32 flags)
 {
-    char * key = NULL;
-    psHash *mdTable = NULL;
-    psList *mdList = NULL;
-    psMetadataItem *existingEntry = NULL;
-
     PS_ASSERT_METADATA_NON_NULL(md,false);
     PS_ASSERT_METADATA_ITEM_NON_NULL(item,false);
 
-    mdTable = md->hash;
-    mdList = md->list;
-    key = item->name;
+    psHash *mdTable = md->hash;
+    psList *mdList = md->list;
+    char *key = item->name;
 
     // See if key is already in table
-    existingEntry = (psMetadataItem*)psHashLookup(mdTable, key);
-
+    psMetadataItem *existingEntry = psHashLookup(mdTable, key);
+
+    // this block handles cases for the MULTI items
     if (item->type == PS_DATA_METADATA_MULTI) {
         // the incoming entry is PS_DATA_METADATA_MULTI
 
-        //Shouldn't have a second reference to the same MULTI in a single Metadata!
+        // Shouldn't have a second reference to the same MULTI in a single Metadata!
+	// 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!");
+            psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Cannot have 2 references to the same MULTI in a single Metadata!");
             return false;
         }
 
-        // force the 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
@@ -690,21 +691,53 @@
     }
 
+    // special block for items which are METADATA folders
+    if (item->type == PS_DATA_METADATA) {
+	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?
+	    if (item != existingEntry) {
+		psMetadataRemoveKey(md, key);
+	    }
+	} 
+	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)) {
+                psError(PS_ERR_UNKNOWN, false, "failed to copy new metadata on existing");
+                return false;
+            }
+	    return true;
+	}
+    }
+
     // how the item is added to the hash depends on prior existence, flags, etc.
+    // XXX i think these cases are overloaded - are all combinations possible?
     if (existingEntry) { // prior existence
-        if (existingEntry->type == PS_DATA_METADATA_MULTI || (flags & PS_META_DUPLICATE_OK)) {
-            // duplicate entries allowed - add another entry.
+
+	// duplicate entries allowed - add another entry.
+        if ((existingEntry->type == PS_DATA_METADATA_MULTI) || (flags & PS_META_DUPLICATE_OK)) {
 
             // make sure the existing entry is PS_DATA_METADATA_MULTI
             existingEntry = makeMetaMulti(mdTable,key,existingEntry);
 
-            // add to the hash's list of duplicate entries
-            if (!psListAdd(existingEntry->data.list, PS_LIST_TAIL, (psPtr)item) ) {
-                psError(PS_ERR_UNKNOWN, false,
-                        _("Failed to add metadata item, %s, to metadata collection list."),
-                        key);
+            // add item to the existing hash's list of duplicate entries
+            if (!psListAdd(existingEntry->data.list, PS_LIST_TAIL, (psMetadataItem *) item) ) {
+                psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
                 return false;
             }
-        } else if (flags & PS_META_REPLACE) {
-            // replace entry instead of creating a duplicate entry.
+            // 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 ((flags & PS_META_REQUIRE_TYPE) && (existingEntry->type != item->type)) {
@@ -716,43 +749,44 @@
                 // when you blow away what you're trying to add
                 psMetadataRemoveKey(md, key);
-                psHashAdd(mdTable, key, (psPtr)item);
-            }
-        } else {
-            // default is to error on duplicate entry.
-            if (flags & PS_META_NO_REPLACE) {
-                return true;
-            }
-            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;
-        }
-    } else {
-        // 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;
-        }
-
-        // Node doesn't exist - Add new metadata item to metadata collection's hash
-        /*  The following is unneeded.  HashAdd can't return false with non-null inputs.
-
-                if(!psHashAdd(mdTable, key, (psPtr)item)) {
-                    psError(PS_ERR_UNKNOWN,false,
-                            _("Failed to add metadata item, %s, to items table."),key);
-                    return false;
-                }
-        */
-        psHashAdd(mdTable, key, (psPtr)item);
-        // Create a multi, if required
-        if (flags & PS_META_DUPLICATE_OK) {
-            makeMetaMulti(mdTable,key,(psMetadataItem*)item); // Casting away const!
-        }
-    }
-
-    if(!psListAdd(mdList, location, (psPtr)item)) {
-        psError(PS_ERR_UNKNOWN, false,
-                _("Failed to add metadata item, %s, to metadata collection list."), key);
+		// 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;
+            }
+        } 
+
+	// 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;
+    }
+
+    // Node doesn't exist - Add new metadata item to metadata collection's hash
+    psHashAdd(mdTable, key, (psMetadataItem *) item);
+
+    // Create a multi, if requested
+    if (flags & PS_META_DUPLICATE_OK) {
+	makeMetaMulti(mdTable, key, (psMetadataItem *) item); // Casting away const!
+    }
+
+    if (!psListAdd(mdList, location, (psPtr)item)) {
+        psError(PS_ERR_UNKNOWN, false, _("Failed to add metadata item, %s, to metadata collection list."), key);
         return false;
     }
Index: /branches/eam_branch_20080430/psLib/src/types/psMetadata.h
===================================================================
--- /branches/eam_branch_20080430/psLib/src/types/psMetadata.h	(revision 17497)
+++ /branches/eam_branch_20080430/psLib/src/types/psMetadata.h	(revision 17498)
@@ -9,6 +9,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.103.12.1 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-04-30 21:04:22 $
+*  @version $Revision: 1.103.12.2 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2008-05-02 00:10:43 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -70,5 +70,5 @@
 #define PS_METADATA_TYPE_MASK 0x00FFFFFF
 
-#define PS_METADATA_ITEM_TYPE(ITEM) (MD->type & PS_METADATA_TYPE_MASK)
+#define PS_METADATA_ITEM_GET_TYPE(MDITEM) (MDITEM->type & PS_METADATA_TYPE_MASK)
 
 /** Metadata data structure.
Index: /branches/eam_branch_20080430/psLib/src/types/psMetadataConfig.c
===================================================================
--- /branches/eam_branch_20080430/psLib/src/types/psMetadataConfig.c	(revision 17497)
+++ /branches/eam_branch_20080430/psLib/src/types/psMetadataConfig.c	(revision 17498)
@@ -11,6 +11,6 @@
 *  @author Joshua Hoblitt, University of Hawaii 2006-2007
 *
-*  @version $Revision: 1.142.8.1 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-04-30 21:04:22 $
+*  @version $Revision: 1.142.8.2 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2008-05-02 00:10:43 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -819,5 +819,5 @@
 	    // found a directive, what does it say?
 	    if (strcasecmp (strValue, "UPDATE") && strcasecmp (strValue, "UPDATE")) {
-		psError(PS_ERR_IO, true, _("Invalid directive %s for METADATA or MULTI.", strValue));
+		psError(PS_ERR_IO, true, _("Invalid directive %s for METADATA or MULTI."), strValue);
 		psFree(strType);
 		psFree(strValue);
