706bb7eb367b92f9a1b3d56a7adb39e81eb13f77 braney Tue Mar 14 10:56:04 2017 -0700 make trash dir for date decorated trash files diff --git src/hg/lib/trashDir.c src/hg/lib/trashDir.c index 027742b..f07c552 100644 --- src/hg/lib/trashDir.c +++ src/hg/lib/trashDir.c @@ -7,42 +7,48 @@ #include "common.h" #include "hash.h" #include "portable.h" #include "trashDir.h" static void trashDirFileExt(struct tempName *tn, char *dirName, char *base, char *suffix, boolean addDate) /* obtain a trash file name trash/dirName/base*.suffix */ { static struct hash *dirHash = NULL; char prefix[128]; char buffer[4096]; if (! dirHash) dirHash = newHash(0); +/* already created this directory ? */ +if (! hashLookup(dirHash,dirName)) + { + hashAddInt(dirHash, dirName, 1); /* remember, been here, done that */ + mkdirTrashDirectory(dirName); + } + if (addDate) { safef(buffer, sizeof buffer, "%s/%03d", dirName, dayOfYear()); dirName = buffer; - } - -/* already created this directory ? */ if (! hashLookup(dirHash,dirName)) { hashAddInt(dirHash, dirName, 1); /* remember, been here, done that */ mkdirTrashDirectory(dirName); } + } + /* no need to duplicate the _ at the end of base, makeTempName is going * to add _ to the given base, some CGIs pass "base_" */ if (endsWith(base,"_")) { char *t = cloneString(base); int len = strlen(t); t[len-1] = '\0'; /* remove ending _ */ safef(prefix, sizeof(prefix), "%s/%s", dirName,t); freeMem(t); } else safef(prefix, sizeof(prefix), "%s/%s", dirName,base); makeTempName(tn, prefix, suffix); }