Skip to content

Commit

Permalink
feat: move files for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Mar 26, 2018
2 parents 896bd91 + 657373a commit 6d59631
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ process.on('unhandledRejection', fatal)
export default {
events: new EventEmitter(),
debug: debug,
appData: ipfsAppData,
settingsStore: settingsStore,
logo: {
ice: logo('ice'),
Expand Down
31 changes: 31 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -99,6 +127,9 @@ function onStartDaemon (node) {
})
}

// Move files from V0.3.0
moveFilesOver()

menubar.tray.setImage(config.logo.ice)
updateState('running')
})
Expand Down

0 comments on commit 6d59631

Please sign in to comment.