f02bb3ce9489bb2c922188ebf94f52a0e80dd757
braney
  Mon Jul 5 10:45:34 2021 -0700
change system() calls to pipeline() calls.

diff --git src/hg/hgSession/backup.c src/hg/hgSession/backup.c
index f0798ff..f1daa50 100644
--- src/hg/hgSession/backup.c
+++ src/hg/hgSession/backup.c
@@ -21,30 +21,31 @@
 
 #include <sys/wait.h>
 
 #include "hCommon.h"
 #include "hdb.h"
 #include "trackHub.h"
 #include "hubConnect.h"
 #include "customFactory.h"
 #include "jsHelper.h"
 #include "trashDir.h"
 #include "filePath.h"
 #include "cgiApoptosis.h"
 
 #include "wiggle.h"
 
+#include "pipeline.h"
 
 #define UCSC_GB_BACKUP_VERSION_FILENAME "UCSC_GB_BACKUP_VERSION"
 
 
 static void errAbortHandler(char *format, va_list args)
 {
 // provide more explicit message when we run out of memory (#5147).
 if(strstr(format, "needLargeMem:") || strstr(format, "carefulAlloc:"))
     htmlVaWarn("Region selected is too large for calculation. Please specify a smaller region or try limiting to fewer data points.", args);
 else
     {
     // call previous handler
     popWarnHandler();
     vaWarn(format, args);
     }
@@ -1123,33 +1124,41 @@
     errAbort("No session found for hgsid=%u", cartSessionRawId(cart));
 
 if (ctCount == 0)
     errAbort("No custom tracks found for hgsid=%u", cartSessionRawId(cart));
 
 char archiveName[1024];
 safef(archiveName, sizeof archiveName, "savedSessionCtRaw.tar.gz");
 
 dyStringPrintf(dyProg, "<br>\n");
 int saveDySize = dyProg->stringSize;
 dyStringPrintf(dyProg, "creating and compressing archive %s <br>\n", archiveName);
 updateProgessFile(backgroundProgress, dyProg);
 lazarusLives(20 * 60);
 
 // create the archive
-char cmd[2048];
-safef(cmd, sizeof cmd, "cd %s; tar -cpzhf %s *", tempOutRand, archiveName);
-mustSystem(cmd);
+char *cwd = cloneString(getCurrentDir());
+setCurrentDir(tempOutRand);
+char excludeBuf[4096];
+safef(excludeBuf, sizeof excludeBuf, "--exclude=%s", archiveName);
+char *pipeCmd1[] = { "tar", "-zcphf", archiveName, ".", excludeBuf, NULL};
+struct pipeline *pl = pipelineOpen1(pipeCmd1, pipelineWrite | pipelineNoAbort, "/dev/null", NULL);
+int sysVal = pipelineWait(pl);
+setCurrentDir(cwd);
+
+if (!((sysVal == 0) || (sysVal == 1)))  // we tolerate 1 because tar doesn't like us creating the archive in the directory we're backing up
+    errAbort("System call returned %d for:\n  %s", sysVal, pipelineDesc(pl));
 
 dyProg->stringSize = saveDySize;  // restore prev size, popping.
 dyProg->string[dyProg->stringSize] = 0;
 dyStringPrintf(dyProg, "archive %s created <br>\n", archiveName);
 updateProgessFile(backgroundProgress, dyProg);
 lazarusLives(20 * 60);
 
 char downPath[1024];
 safef(downPath, sizeof downPath, "%s/%s", tempOutRand, archiveName);
 
 printf("<br>\n");
 
 char *encDownPath = cgiEncodeFull(downPath);
 char downButName[1024];
 safef(downButName, sizeof(downButName), "%s%s", hgsDoDownloadPrefix, encDownPath);