Browse Source

Ensure sqlite folder is removed after clear cache / hard reset

closes #1554
gre-patch-1
meriadec 6 years ago
parent
commit
7c2088720e
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 12
      src/components/SettingsPage/CleanButton.js
  2. 11
      src/components/SettingsPage/ResetButton.js
  3. 41
      src/components/SettingsPage/ResetFallbackModal.js
  4. 1
      src/config/errors.js
  5. 15
      src/helpers/reset.js

12
src/components/SettingsPage/CleanButton.js

@ -8,6 +8,7 @@ import { cleanAccountsCache } from 'actions/accounts'
import Button from 'components/base/Button'
import { ConfirmModal } from 'components/base/Modal'
import { softReset } from 'helpers/reset'
import ResetFallbackModal from './ResetFallbackModal'
const mapDispatchToProps = {
cleanAccountsCache,
@ -20,32 +21,35 @@ type Props = {
type State = {
opened: boolean,
fallbackOpened: boolean,
isLoading: boolean,
}
class CleanButton extends PureComponent<Props, State> {
state = {
opened: false,
fallbackOpened: false,
isLoading: false,
}
open = () => this.setState({ opened: true })
close = () => this.setState({ opened: false })
closeFallback = () => this.setState({ fallbackOpened: false })
action = async () => {
if (this.state.isLoading) return
try {
this.setState({ isLoading: true })
await softReset({ cleanAccountsCache: this.props.cleanAccountsCache })
} finally {
this.setState({ isLoading: false })
} catch (err) {
this.setState({ isLoading: false, fallbackOpened: true })
}
}
render() {
const { t } = this.props
const { opened, isLoading } = this.state
const { opened, isLoading, fallbackOpened } = this.state
return (
<Fragment>
<Button small primary onClick={this.open} event="ClearCacheIntent">
@ -63,6 +67,8 @@ class CleanButton extends PureComponent<Props, State> {
subTitle={t('common.areYouSure')}
desc={t('settings.softResetModal.desc')}
/>
<ResetFallbackModal isOpened={fallbackOpened} onClose={this.closeFallback} />
</Fragment>
)
}

11
src/components/SettingsPage/ResetButton.js

@ -10,6 +10,7 @@ import Box from 'components/base/Box'
import Button from 'components/base/Button'
import { ConfirmModal } from 'components/base/Modal'
import IconTriangleWarning from 'icons/TriangleWarning'
import ResetFallbackModal from './ResetFallbackModal'
type Props = {
t: T,
@ -18,16 +19,19 @@ type Props = {
type State = {
opened: boolean,
pending: boolean,
fallbackOpened: boolean,
}
class ResetButton extends PureComponent<Props, State> {
state = {
opened: false,
pending: false,
fallbackOpened: false,
}
open = () => this.setState({ opened: true })
close = () => this.setState({ opened: false })
closeFallback = () => this.setState({ fallbackOpened: false })
action = async () => {
this.setState({ pending: true })
@ -35,13 +39,14 @@ class ResetButton extends PureComponent<Props, State> {
await hardReset()
remote.getCurrentWindow().webContents.reloadIgnoringCache()
} catch (err) {
this.setState({ pending: false })
this.setState({ pending: false, fallbackOpened: true })
}
}
render() {
const { t } = this.props
const { opened, pending } = this.state
const { opened, pending, fallbackOpened } = this.state
return (
<Fragment>
<Button small danger onClick={this.open} event="HardResetIntent">
@ -66,6 +71,8 @@ class ResetButton extends PureComponent<Props, State> {
</IconWrapperCircle>
)}
/>
<ResetFallbackModal isOpened={fallbackOpened} onClose={this.closeFallback} />
</Fragment>
)
}

41
src/components/SettingsPage/ResetFallbackModal.js

@ -0,0 +1,41 @@
// @flow
import React, { PureComponent } from 'react'
import { ConfirmModal } from 'components/base/Modal'
import { openUserDataFolderAndQuit } from 'helpers/reset'
type Props = {
isOpened: boolean,
onClose: () => *,
}
class ResetFallbackModal extends PureComponent<Props> {
render() {
const { isOpened, onClose } = this.props
return (
<ConfirmModal
centered
isOpened={isOpened}
onConfirm={openUserDataFolderAndQuit}
onClose={onClose}
onReject={onClose}
confirmText={'Open folder'}
title="Couldnt remove app files"
desc={
<div>
<p>{'Cache folder couldnt be deleted. You will have to delete it manually.'}</p>
<p style={{ fontWeight: 'bold' }}>
{'Click on "Open folder", then the '}
<span style={{ textDecoration: 'underline' }}>{'app will close'}</span>
{', and you will have to delete the "sqlite" folder.'}
</p>
<p style={{ marginTop: 20 }}>{'After that, you can restart the app.'}</p>
</div>
}
/>
)
}
}
export default ResetFallbackModal

1
src/config/errors.js

@ -50,3 +50,4 @@ export const FeeNotLoaded = createCustomErrorClass('FeeNotLoaded')
// db stuff, no need to translate
export const NoDBPathGiven = createCustomErrorClass('NoDBPathGiven')
export const DBWrongPassword = createCustomErrorClass('DBWrongPassword')
export const DBNotReset = createCustomErrorClass('DBNotReset')

15
src/helpers/reset.js

@ -1,5 +1,7 @@
// @flow
import fs from 'fs'
import { shell, remote } from 'electron'
import path from 'path'
import rimraf from 'rimraf'
import resolveUserDataDirectory from 'helpers/resolveUserDataDirectory'
@ -7,11 +9,15 @@ import { disable as disableDBMiddleware } from 'middlewares/db'
import db from 'helpers/db'
import { delay } from 'helpers/promise'
import killInternalProcess from 'commands/killInternalProcess'
import { DBNotReset } from 'config/errors'
async function resetLibcoreDatabase() {
await killInternalProcess.send().toPromise()
const dbpath = path.resolve(resolveUserDataDirectory(), 'sqlite/')
rimraf.sync(dbpath, { glob: false })
if (fs.existsSync(dbpath)) {
throw new DBNotReset()
}
}
function reload() {
@ -24,7 +30,7 @@ export async function hardReset() {
disableDBMiddleware()
db.resetAll()
await delay(500)
resetLibcoreDatabase()
await resetLibcoreDatabase()
reload()
}
@ -32,6 +38,11 @@ export async function softReset({ cleanAccountsCache }: *) {
cleanAccountsCache()
await delay(500)
await db.cleanCache()
resetLibcoreDatabase()
await resetLibcoreDatabase()
reload()
}
export async function openUserDataFolderAndQuit() {
shell.openItem(resolveUserDataDirectory())
remote.app.quit()
}

Loading…
Cancel
Save