Index: trunk/psModules/src/config/pmConfigCamera.c
===================================================================
--- trunk/psModules/src/config/pmConfigCamera.c	(revision 26559)
+++ trunk/psModules/src/config/pmConfigCamera.c	(revision 26560)
@@ -149,5 +149,5 @@
     camerasIter = psMetadataIteratorAlloc(new, PS_LIST_HEAD, NULL); // Iterator
     while ((camerasItem = psMetadataGetAndIncrement(camerasIter))) {
-        psMetadataAddItem(cameras, camerasItem, PS_LIST_HEAD, 0);
+        psMetadataAddItem(cameras, camerasItem, PS_LIST_HEAD, PS_META_REPLACE);
     }
     psFree(camerasIter);
@@ -211,5 +211,11 @@
     // See if the new one is already there
     psString newName = pmConfigCameraSkycellName(name); // Name of skycelled camera
-    if (psMetadataLookup(oldCameras, newName)) {
+    bool mdok;                       // Status of MD lookup
+    psMetadata *oldCam = psMetadataLookupMetadata(&mdok, oldCameras, newName); // Existing camera configuration
+    if (mdok && oldCam) {
+        // Ensure new camera goes to the head of the metadata, so that it will be recognised first
+        // The old camera doesn't contain the PSMOSAIC header, so it will match anything!
+        psTrace("psModules.config", 6, "Camera configuration for %s exists, so moving to the front.", newName);
+        psMetadataAddMetadata(newCameras, PS_LIST_HEAD, newName, PS_META_REPLACE, NULL, oldCam);
         psFree(newName);
         return true;
@@ -365,4 +371,5 @@
     // New camera MUST go to the head of the metadata, so that it will be recognised first
     // The old camera doesn't contain the PSCAMERA and PSFORMAT headers, so it will match anything!
+    psTrace("psModules.config", 6, "Generated new camera configuration for %s.", newName);
     psMetadataAddMetadata(newCameras, PS_LIST_HEAD, newName, PS_META_REPLACE,
                           "Automatically generated", new);
@@ -435,5 +442,5 @@
     camerasIter = psMetadataIteratorAlloc(new, PS_LIST_HEAD, NULL); // Iterator
     while ((camerasItem = psMetadataGetAndIncrement(camerasIter))) {
-        psMetadataAddItem(cameras, camerasItem, PS_LIST_HEAD, 0);
+        psMetadataAddItem(cameras, camerasItem, PS_LIST_HEAD, PS_META_REPLACE);
     }
     psFree(camerasIter);
@@ -468,7 +475,13 @@
 
     // See if the new one is already there
-    psString newName = NULL;       // Name of mosaicked camera
-    psStringAppend(&newName, "_%s-%s", name, mosaicLevel == PM_FPA_LEVEL_CHIP ? "CHIP" : "FPA");
-    if (psMetadataLookup(oldCameras, newName)) {
+    psString newName = mosaicLevel == PM_FPA_LEVEL_CHIP ? pmConfigCameraChipName(name) :
+        pmConfigCameraFPAName(name); // Name of mosaicked camera
+    bool mdok;                       // Status of MD lookup
+    psMetadata *oldCam = psMetadataLookupMetadata(&mdok, oldCameras, newName); // Existing camera configuration
+    if (mdok && oldCam) {
+        // Ensure new camera goes to the head of the metadata, so that it will be recognised first
+        // The old camera doesn't contain the PSMOSAIC header, so it will match anything!
+        psTrace("psModules.config", 6, "Camera configuration for %s exists, so moving to the front.", newName);
+        psMetadataAddMetadata(newCameras, PS_LIST_HEAD, newName, PS_META_REPLACE, NULL, oldCam);
         psFree(newName);
         return true;
@@ -476,5 +489,4 @@
 
     psMetadata *new = psMetadataCopy(NULL, camera); // Copy of the camera description
-    bool mdok;                          // Status of MD lookups
 
     // ** Fix up the contents of the FPA description to match the mosaicked camera **
@@ -848,4 +860,5 @@
     // New camera MUST go to the head of the metadata, so that it will be recognised first
     // The old camera doesn't contain the PSMOSAIC header, so it will match anything!
+    psTrace("psModules.config", 6, "Generated new camera configuration for %s.", newName);
     psMetadataAddMetadata(newCameras, PS_LIST_HEAD, newName, PS_META_REPLACE,
                           "Automatically generated", new);
