* Run the hygiene sweep. * * @param {object} [options] * @param {boolean} [options.dryRun=false] Report what would be removed without deleting * @param {string} [options.pluginDataDir] Override consent marker location (tests) * @param {string} [options.planningDir] Override .planning lo
(options = {})
| 157 | * Counts are successful removals, or would-be removals when dryRun is true. |
| 158 | */ |
| 159 | function cleanState(options = {}) { |
| 160 | const dryRun = options.dryRun === true; |
| 161 | const pluginDataDir = options.pluginDataDir || DEFAULT_PLUGIN_DATA_DIR; |
| 162 | const planningDir = options.planningDir || DEFAULT_PLANNING_DIR; |
| 163 | const nowMs = typeof options.now === 'number' ? options.now : Date.now(); |
| 164 | |
| 165 | const result = { |
| 166 | dryRun, |
| 167 | sessionMarkers: 0, |
| 168 | onetimeTokens: 0, |
| 169 | lockdirs: 0, |
| 170 | errors: 0, |
| 171 | removed: [], |
| 172 | failed: [], |
| 173 | }; |
| 174 | |
| 175 | sweepMarkers(pluginDataDir, SESSION_MARKER_RE, SESSION_ALLOW_TTL_MS, nowMs, dryRun, result, 'sessionMarkers'); |
| 176 | sweepMarkers(pluginDataDir, ONETIME_MARKER_RE, ONETIME_TTL_MS, nowMs, dryRun, result, 'onetimeTokens'); |
| 177 | sweepLockdirs(planningDir, nowMs, dryRun, result, 0); |
| 178 | |
| 179 | return result; |
| 180 | } |
| 181 | |
| 182 | // -- CLI ---------------------------------------------------------------------- |
| 183 |
no test coverage detected