Skip to content

feat: run garbage collector #1407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"takeScreenshot": "Take Screenshot",
"downloadHash": "Download Hash",
"moveRepositoryLocation": "Move Repository Location",
"runGarbageCollector": "Run Garbage Collector",
"polkitDialog": {
"title": "Polkit not found",
"message": "IPFS can't be added to /usr/local/bin/ without polkit agent."
Expand Down Expand Up @@ -131,5 +132,14 @@
"updateDownloadedNotification": {
"title": "Update downloaded",
"message": "Update for version { version } of IPFS Desktop downloaded. Click this notification to install."
},
"runGarbageCollectorWarning": {
"title": "Garbage collector",
"message": "Running the garbage collector will remove from your repository all objects that are not pinned or on your MFS. This may take a while. Do you wish to proceed?",
"action": "Run"
},
"runGarbageCollectorDone": {
"title": "Garbage collector",
"message": "The garbage collector ran successfully."
}
}
48 changes: 48 additions & 0 deletions src/run-gc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const i18n = require('i18next')
const logger = require('./common/logger')
const { showDialog, recoverableErrorDialog } = require('./dialogs')
const dock = require('./dock')

module.exports = function runGarbageCollector ({ getIpfsd }) {
dock.run(async () => {
logger.info('[run gc] alerting user for effects')

const opt = showDialog({
title: i18n.t('runGarbageCollectorWarning.title'),
message: i18n.t('runGarbageCollectorWarning.message'),
type: 'warning',
buttons: [
i18n.t('runGarbageCollectorWarning.action'),
i18n.t('cancel')
],
showDock: false
})

if (opt !== 0) {
logger.info('[run gc] user canceled')
return
}

const ipfsd = await getIpfsd()

if (!ipfsd) {
return
}

try {
ipfsd.api.repo.gc()
showDialog({
title: i18n.t('runGarbageCollectorDone.title'),
message: i18n.t('runGarbageCollectorDone.message'),
type: 'info',
buttons: [
i18n.t('ok')
],
showDock: false
})
} catch (err) {
logger.error(`[run gc] ${err.toString()}`)
return recoverableErrorDialog(err)
}
})
}
8 changes: 8 additions & 0 deletions src/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const logger = require('./common/logger')
const store = require('./common/store')
const { IS_MAC, IS_WIN, VERSION, GO_IPFS_VERSION } = require('./common/consts')
const moveRepositoryLocation = require('./move-repository-location')
const runGarbageCollector = require('./run-gc')

// Notes on this: we are only supporting accelerators on macOS for now because
// they natively work as soon as the menu opens. They don't work like that on Windows
Expand Down Expand Up @@ -95,6 +96,12 @@ function buildMenu (ctx) {
{
label: i18n.t('moveRepositoryLocation'),
click: () => { moveRepositoryLocation(ctx) }
},
{
id: 'runGarbageCollector',
label: i18n.t('runGarbageCollector'),
click: () => { runGarbageCollector(ctx) },
enabled: false
}
]
},
Expand Down Expand Up @@ -193,6 +200,7 @@ module.exports = function (ctx) {

menu.getMenuItemById('takeScreenshot').enabled = menu.getMenuItemById('ipfsIsRunning').visible
menu.getMenuItemById('downloadHash').enabled = menu.getMenuItemById('ipfsIsRunning').visible
menu.getMenuItemById('runGarbageCollector').enabled = menu.getMenuItemById('ipfsIsRunning').visible

if (status === STATUS.STARTING_FINISHED) {
tray.setImage(icon(on))
Expand Down