diff --git a/docsrc/imap/reference/manpages/systemcommands/ptexpire.rst b/docsrc/imap/reference/manpages/systemcommands/ptexpire.rst index 4d6f9aaf00d..b088e6f1c2e 100644 --- a/docsrc/imap/reference/manpages/systemcommands/ptexpire.rst +++ b/docsrc/imap/reference/manpages/systemcommands/ptexpire.rst @@ -15,7 +15,7 @@ Synopsis .. parsed-literal:: - **ptexpire** [**-C** *filename*] [**-E** *seconds*] + **ptexpire** [**-C** *filename*] [**-E** *seconds*] [ *username* ...] Description =========== @@ -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 diff --git a/ptclient/ptexpire.c b/ptclient/ptexpire.c index 36245261bb4..c0ea0c7fc0f 100644 --- a/ptclient/ptexpire.c +++ b/ptclient/ptexpire.c @@ -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 */ @@ -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; }