import { actionGroups } from '../actionGroups' import { i18n } from '../i18n' import { sdk } from '../sdk' import { dataDir, SUBSPACES_DIR } from '../utils' export const resetSubspacesState = sdk.Action.withoutInput( // id 'reset-subspaces-state', // metadata async ({ effects }) => ({ name: i18n('Reset Subspaces State'), description: i18n( 'Wipe /data/subspaces so the next start re-creates empty Subspaces data, prover, and registry directories.', ), warning: i18n( 'This deletes all local Subspaces state — any handles/proofs stored on disk will be lost. The binaries ship in the image, so nothing needs to be re-downloaded. The spaces wallet on spaced is preserved.', ), allowedStatuses: 'any', group: actionGroups.subspaces, visibility: 'enabled', }), // run async ({ effects }) => { const res = await sdk.SubContainer.withTemp( effects, { imageId: 'subspaces' }, sdk.Mounts.of().mountVolume({ volumeId: 'main', subpath: null, mountpoint: dataDir, readonly: false, }), 'spaces-reset-subspaces', (subc) => subc.exec(['rm', '-rf', SUBSPACES_DIR], { user: 'root' }), ) if (res.exitCode !== 0) { return { version: '1', title: i18n('Failure'), message: i18n('Could not wipe Subspaces state: ${error}', { error: (res.stderr ?? '').toString() || `exit ${res.exitCode}`, }), result: null, } } return { version: '1', title: i18n('Success'), message: i18n( 'Subspaces cache and data have been wiped. Start (or restart) the service to re-fetch and rebuild from GitHub.', ), result: null, } }, )