From 46f26e7c2cc48ff5ca0506a8117b61164ec4a16f Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 1 Jun 2018 18:04:31 +0100 Subject: [PATCH] fix(repo): do not hang on calls to repo gc Previously calls to repo.gc would hang or fail silently or in the case of the HTTP API cause a 404. This PR responds to calls to repo.gc with an error to inform that this feature will eventually exist (it is spec'd) but is not implemented yet. License: MIT Signed-off-by: Alan Shaw --- src/cli/commands/repo/gc.js | 7 ++++++- src/core/components/repo.js | 9 ++++++++- src/http/api/resources/repo.js | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/repo/gc.js b/src/cli/commands/repo/gc.js index 6b6f705cf4..f427e5c966 100644 --- a/src/cli/commands/repo/gc.js +++ b/src/cli/commands/repo/gc.js @@ -3,10 +3,15 @@ module.exports = { command: 'gc', - describe: '', + describe: 'Perform a garbage collection sweep on the repo.', builder: {}, handler (argv) { + argv.ipfs.repo.gc((err) => { + if (err) { + throw err + } + }) } } diff --git a/src/core/components/repo.js b/src/core/components/repo.js index f2ad5106e1..23116d8cf5 100644 --- a/src/core/components/repo.js +++ b/src/core/components/repo.js @@ -38,7 +38,14 @@ module.exports = function repo (self) { }) }), - gc: () => {}, + gc: promisify((options, callback) => { + if (typeof options === 'function') { + callback = options + options = {} + } + + callback(new Error('Not implemented')) + }), stat: promisify((options, callback) => { if (typeof options === 'function') { diff --git a/src/http/api/resources/repo.js b/src/http/api/resources/repo.js index 394fda548e..d6add2c6e9 100644 --- a/src/http/api/resources/repo.js +++ b/src/http/api/resources/repo.js @@ -2,6 +2,21 @@ exports = module.exports +exports.gc = (request, reply) => { + const ipfs = request.server.app.ipfs + + ipfs.repo.gc((err) => { + if (err) { + return reply({ + Message: err.toString(), + Code: 0 + }).code(500) + } + + reply() + }) +} + exports.version = (request, reply) => { const ipfs = request.server.app.ipfs