From 708c7cc130991bf12cc3ccc1973414fa3313853f Mon Sep 17 00:00:00 2001 From: Hugo Dias Date: Mon, 20 Apr 2020 15:46:49 +0100 Subject: [PATCH] fix: use IPFS_PATH env var non disposable controllers should use IPFS_PATH if set. closes #497 --- src/utils.js | 3 +++ test/controller.spec.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/utils.js b/src/utils.js index dace41f9..9067a0d7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -22,6 +22,9 @@ const repoExists = async (repoPath) => { } const defaultRepo = (type) => { + if (process.env.IPFS_PATH !== undefined) { + return process.env.IPFS_PATH + } return path.join( os.homedir(), type === 'js' || type === 'proc' ? '.jsipfs' : '.ipfs' diff --git a/test/controller.spec.js b/test/controller.spec.js index cb48b505..d13392da 100644 --- a/test/controller.spec.js +++ b/test/controller.spec.js @@ -71,6 +71,21 @@ describe('Controller API', function () { after(() => factory.clean()) describe('init', () => { + it('should use process.IPFS_PATH', async () => { + const repoPath = await factory.tmpDir() + process.env.IPFS_PATH = repoPath + const ctl = await factory.spawn({ + type: 'go', + disposable: false, + ipfsOptions: { + init: false, + start: false + } + }) + + expect(ctl.path).to.equal(repoPath) + process.env.IPFS_PATH = undefined + }) describe('should work with defaults', () => { for (const opts of types) { it(`type: ${opts.type} remote: ${Boolean(opts.remote)}`, async () => {