Skip to content

Commit 6d59631

Browse files
authored
feat: move files for backwards compatibility
2 parents 896bd91 + 657373a commit 6d59631

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ process.on('unhandledRejection', fatal)
5858
export default {
5959
events: new EventEmitter(),
6060
debug: debug,
61+
appData: ipfsAppData,
6162
settingsStore: settingsStore,
6263
logo: {
6364
ice: logo('ice'),

src/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,34 @@ function onRequestState (node, event) {
4848
send('node-status', state)
4949
}
5050

51+
// Moves files from appData/file-history.json to MFS so
52+
// v0.4.0 is backwards compatible with v0.3.0.
53+
function moveFilesOver () {
54+
const path = join(config.appData, 'file-history.json')
55+
56+
if (!fs.existsSync(path)) {
57+
return
58+
}
59+
60+
let files
61+
62+
try {
63+
files = JSON.parse(fs.readFileSync(path))
64+
} catch (e) {
65+
debug(e)
66+
return
67+
}
68+
69+
Promise.all(files.map((file) => IPFS.files.cp([`/ipfs/${file.hash}`, `/${file.name}`])))
70+
.then(() => {
71+
fs.unlinkSync(path)
72+
})
73+
.catch((e) => {
74+
fs.unlinkSync(path)
75+
debug(e)
76+
})
77+
}
78+
5179
function onStartDaemon (node) {
5280
debug('Starting daemon')
5381
updateState('starting')
@@ -99,6 +127,9 @@ function onStartDaemon (node) {
99127
})
100128
}
101129

130+
// Move files from V0.3.0
131+
moveFilesOver()
132+
102133
menubar.tray.setImage(config.logo.ice)
103134
updateState('running')
104135
})

0 commit comments

Comments
 (0)