be9e5faa96a0773d42929c54f58ded53f40b7e88 braney Mon Dec 12 15:59:17 2016 -0800 some changes that make it easier for trash cleaner to squirrel away custom tracks holding BLAT results diff --git src/hg/lib/trashDir.c src/hg/lib/trashDir.c index 481d59d..c92185f 100644 --- src/hg/lib/trashDir.c +++ src/hg/lib/trashDir.c @@ -1,57 +1,77 @@ /* trashDir.c - temporary file creation and directory creation in /trash */ /* Copyright (C) 2014 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" #include "hash.h" #include "portable.h" #include "trashDir.h" -void trashDirFile(struct tempName *tn, char *dirName, char *base, char *suffix) +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[64]; +char buffer[4096]; if (! dirHash) dirHash = newHash(0); +if (addDate) + { + safef(buffer, sizeof buffer, "%s.%d", 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); } +void trashDirFile(struct tempName *tn, char *dirName, char *base, char *suffix) +/* obtain a trash file name trash/dirName/base*.suffix */ +{ +trashDirFileExt(tn, dirName, base, suffix, FALSE); +} + +void trashDirDateFile(struct tempName *tn, char *dirName, char *base, char *suffix) +/* obtain a trash file name trash/dirName.dayOfYear/base*.suffix */ +{ +trashDirFileExt(tn, dirName, base, suffix, TRUE); +} + + boolean trashDirReusableFile(struct tempName *tn, char *dirName, char *base, char *suffix) /* obtain a resusable trash file name as trash/dirName/base.suffix * returns TRUE if already exists. */ { trashDirFile(tn,dirName,base,suffix); // Don't really want the randomized name. char *cgiName = rStringIn("/",tn->forCgi ); char *htmlName = rStringIn("/",tn->forHtml); if (cgiName == NULL) cgiName = rStringIn("\\",tn->forCgi); assert(cgiName != NULL && htmlName != NULL); cgiName += 1; htmlName += 1; boolean addDot = (*suffix != '.');