Skip to content

Commit

Permalink
ptexpire: allow passing a list of userids to remove
Browse files Browse the repository at this point in the history
  • Loading branch information
brong committed Mar 31, 2024
1 parent 7c17e2a commit 9d6466a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion docsrc/imap/reference/manpages/systemcommands/ptexpire.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Synopsis

.. parsed-literal::
**ptexpire** [**-C** *filename*] [**-E** *seconds*]
**ptexpire** [**-C** *filename*] [**-E** *seconds*] [ *username* ...]
Description
===========
Expand All @@ -24,6 +24,9 @@ The **ptexpire** program sweeps the ``ptscache_db`` database, deleting
entries older than the expiry duration, which defaults to 5400 seconds
(3 hours). The expiry duration can be changed with the **-E** option.

Alternatively, if it's passed a list of usernames it deletes just those
usernames, immediately.

**ptexpire** |default-conf-text|

Options
Expand Down
24 changes: 18 additions & 6 deletions ptclient/ptexpire.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ int main(int argc, char *argv[])

cyrus_init(alt_config, "ptexpire", 0, 0);

timenow = time(0);
syslog(LOG_INFO, "Expiring entries older than %d seconds (currently %d)",
(int)expire_time, (int)timenow);
syslog(LOG_DEBUG, "ptexpire.c %s", PACKAGE_VERSION);

/* open database */
Expand All @@ -163,15 +160,30 @@ int main(int argc, char *argv[])
exit(1);
}

if (tofree) free(tofree);
if (optind < argc) {
int i;
for (i = optind; i < argc; i++) {
const char *userid = argv[i];
int r = cyrusdb_delete(ptdb, userid, strlen(userid), /*tid*/NULL, /*force*/0);
syslog(LOG_INFO, "Removing cache for %s (%s)", userid,
r == CYRUSDB_OK ? "found" : "not-found");
}
}
else {
timenow = time(0);
syslog(LOG_INFO, "Expiring entries older than %d seconds (currently %d)",
(int)expire_time, (int)timenow);

/* iterate through db, wiping expired entries */
cyrusdb_foreach(ptdb, "", 0, expire_p, expire_cb, ptdb, NULL);
/* iterate through db, wiping expired entries */
cyrusdb_foreach(ptdb, "", 0, expire_p, expire_cb, ptdb, NULL);
}

cyrusdb_close(ptdb);

cyrus_done();

if (tofree) free(tofree);

syslog(LOG_INFO, "finished");
return 0;
}

0 comments on commit 9d6466a

Please sign in to comment.