Index: /trunk/ippTools/src/pzgetimfiles.c
===================================================================
--- /trunk/ippTools/src/pzgetimfiles.c	(revision 10034)
+++ /trunk/ippTools/src/pzgetimfiles.c	(revision 10035)
@@ -184,4 +184,8 @@
         // point of no return
         if (!psDBCommit(config->dbh)) {
+            // rollback
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
             psError(PS_ERR_UNKNOWN, false, "database error");
             return false;
@@ -237,5 +241,9 @@
     psFree(newImfiles);
 
-    // queue the imfiles (files) in pzPendingImfile
+    // queue the imfiles (files) in pzPendingImfile -- must be done before the
+    // imfile is insterted into summitImfile (after that happens when don't
+    // know which imfiles are new anymore (well thats not exactly true but it
+    // make be someday if we have to beable to resync to modified datastore
+    // entries)
     {
         char *query = 
@@ -247,5 +255,5 @@
             "       incoming.class,"
             "       incoming.class_id,"
-            "       pzPendingExp.exp_tag"
+            "       NULL" // exp_tag, will be assigned later
             "   FROM incoming"
             "   JOIN pzPendingExp"
@@ -270,5 +278,5 @@
     }
 
-    // move imfiles (files) from the temp table into summitImfiles
+    // copy imfiles (files) from the temp table into summitImfiles
     {
         char *query = 
@@ -327,4 +335,52 @@
     }
 
+    // copy the summitExp row into newExp in order to create a new exp_tag
+    {
+        char *query = 
+            "INSERT INTO newExp" 
+            "   SElECT"
+            "       NULL," // exp_tag
+            "       summitExp.exp_id,"
+            "       summitExp.camera,"
+            "       summitExp.telescope,"
+            "       summitExp.dateobs,"
+            "       summitExp.exp_type,"
+            "       summitExp.imfiles"
+            "   FROM summitExp"
+            "   WHERE"
+            "       summitExp.exp_id = '%s'"
+            "       AND summitExp.camera = '%s'"
+            "       AND summitExp.telescope = '%s'";
+
+        if (!p_psDBRunQuery(config->dbh, query)) {
+            // rollback
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            return false;
+        }
+    }
+ 
+    // set the exp_tag for the imfiles (files) in the exposure (fileset) that
+    // we are investigating
+    {
+        char *query = 
+            "UPDATE pzPendingImfile"
+            " SET exp_tag = LAST_INSERT_ID()"
+            " WHERE"
+            "   exp_id = '%s'"
+            "   AND camera = '%s'"
+            "   AND telescope = '%s'";
+        if (!p_psDBRunQuery(config->dbh, query, filesetid, camera, telescope)) {
+            // rollback
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            psError(PS_ERR_UNKNOWN, false, "database error");
+            return false;
+        }
+    }
+ 
     // remove the pzPendingExp entry for this exp (fileset)
     {
@@ -347,4 +403,8 @@
     // point of no return
     if (!psDBCommit(config->dbh)) {
+        // rollback
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
