89d738beff2c63765e2b6b4bc89412c621246b33 max Thu Sep 3 12:25:02 2026 -0700 snapshotSession: rename the snapshot "reaper" to "cleaner" Renames the snapshotReaper utility to snapshotCleaner and drops the word "reap" from the API and comments (snapshotReapAnon -> snapshotCleanAnon, and the doc/usage text now say clean/cleaned/cleaner). No behavior change. refs #38197 diff --git src/hg/lib/snapshotSession.c src/hg/lib/snapshotSession.c index 6fd06b9ddc7..3eabd55d6ab 100644 --- src/hg/lib/snapshotSession.c +++ src/hg/lib/snapshotSession.c @@ -201,79 +201,79 @@ if (gotSettings) { sqlDyStringPrintf(dy, ", '"); sqlDyAppendEscaped(dy, settings); sqlDyStringPrintf(dy, "'"); } sqlDyStringPrintf(dy, ")"); sqlUpdate(conn, dy->string); freez(&contents); freez(&firstUse); dyStringFree(&dy); return useCount; } -/* ---- Reaping abandoned anonymous snapshots -------------------------------------------------- */ +/* ---- Cleaning up abandoned anonymous snapshots ---------------------------------------------- */ static void removeDirTree(char *dir) /* Best-effort recursive removal of a directory and its contents (files are hard-links into durable * storage; unlinking frees the space). Missing paths are ignored. */ { if (isEmpty(dir) || !fileExists(dir)) return; struct fileInfo *fiList = listDirX(dir, "*", TRUE), *fi; for (fi = fiList; fi != NULL; fi = fi->next) { if (fi->isDir) removeDirTree(fi->name); else remove(fi->name); } slFreeList(&fiList); rmdir(dir); } -int snapshotReapAnon(struct sqlConnection *conn, int ttlDays, boolean dryRun) +int snapshotCleanAnon(struct sqlConnection *conn, int ttlDays, boolean dryRun) /* See snapshotSession.h. */ { char *sessionDataDir = cfgOption("sessionDataDir"); char query[1024]; /* '\_\_%' : the two leading underscores are literal (escaped, since '_' is a LIKE wildcard), * followed by the '%' wildcard for the random token. */ sqlSafef(query, sizeof query, "SELECT sessionName FROM %s WHERE userName='%s' AND sessionName LIKE '\\_\\_%%' " "AND lastUse < DATE_SUB(now(), INTERVAL %d DAY)", namedSessionTable, snapshotAnonUser, ttlDays); -struct slName *toReap = NULL; +struct slName *toClean = NULL; struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) - slNameAddHead(&toReap, row[0]); + slNameAddHead(&toClean, row[0]); sqlFreeResult(&sr); int n = 0; struct slName *s; -for (s = toReap; s != NULL; s = s->next) +for (s = toClean; s != NULL; s = s->next) { if (!dryRun) { /* Remove the durable files first, then the row, so a crash never orphans the DB pointer. * Minimal snapshots live under the fanned-out snapshotSessionDir; a full anonymous share * (e.g. the top-right "Share a link" when logged out) uses sessionData's flat layout - remove * whichever exists (removeDirTree ignores a missing path). */ char *snapDir = snapshotSessionDir(sessionDataDir, snapshotAnonUser, s->name); char *flatDir = sessionDirFromNames(sessionDataDir, snapshotAnonUser, s->name); removeDirTree(snapDir); removeDirTree(flatDir); freez(&snapDir); freez(&flatDir); sqlSafef(query, sizeof query, "DELETE FROM %s WHERE userName='%s' AND sessionName='%s'", namedSessionTable, snapshotAnonUser, s->name); sqlUpdate(conn, query); } n++; } -slFreeList(&toReap); +slFreeList(&toClean); return n; }