diff --git a/src/config.js b/src/config.js index ac33534cb..978dc5eaa 100644 --- a/src/config.js +++ b/src/config.js @@ -58,6 +58,7 @@ process.on('unhandledRejection', fatal) export default { events: new EventEmitter(), debug: debug, + appData: ipfsAppData, settingsStore: settingsStore, logo: { ice: logo('ice'), diff --git a/src/index.js b/src/index.js index fa3e71842..084e6046e 100644 --- a/src/index.js +++ b/src/index.js @@ -48,6 +48,34 @@ function onRequestState (node, event) { send('node-status', state) } +// Moves files from appData/file-history.json to MFS so +// v0.4.0 is backwards compatible with v0.3.0. +function moveFilesOver () { + const path = join(config.appData, 'file-history.json') + + if (!fs.existsSync(path)) { + return + } + + let files + + try { + files = JSON.parse(fs.readFileSync(path)) + } catch (e) { + debug(e) + return + } + + Promise.all(files.map((file) => IPFS.files.cp([`/ipfs/${file.hash}`, `/${file.name}`]))) + .then(() => { + fs.unlinkSync(path) + }) + .catch((e) => { + fs.unlinkSync(path) + debug(e) + }) +} + function onStartDaemon (node) { debug('Starting daemon') updateState('starting') @@ -99,6 +127,9 @@ function onStartDaemon (node) { }) } + // Move files from V0.3.0 + moveFilesOver() + menubar.tray.setImage(config.logo.ice) updateState('running') })