Ensure state.saved.prefs exists

Fixes a bug I introduced in the migrations
This commit is contained in:
Feross Aboukhadijeh
2016-06-02 22:33:22 -07:00
parent 5d71f9e9c6
commit 8a95895254

View File

@@ -18,25 +18,24 @@ function run (state) {
var version = state.saved.version var version = state.saved.version
if (semver.lt(version, '0.7.0')) { if (semver.lt(version, '0.7.0')) {
migrate_0_7_0(state) migrate_0_7_0(state.saved)
} }
// Future migrations... if (semver.lt(version, '0.7.2')) {
// if (semver.lt(version, '0.8.0')) { migrate_0_7_2(state.saved)
// migrate_0_8_0(state) }
// }
// Config is now on the new version // Config is now on the new version
state.saved.version = config.APP_VERSION state.saved.version = config.APP_VERSION
} }
function migrate_0_7_0 (state) { function migrate_0_7_0 (saved) {
console.log('migrate to 0.7.0') console.log('migrate to 0.7.0')
var fs = require('fs-extra') var fs = require('fs-extra')
var path = require('path') var path = require('path')
state.saved.torrents.forEach(function (ts) { saved.torrents.forEach(function (ts) {
var infoHash = ts.infoHash var infoHash = ts.infoHash
// Replace torrentPath with torrentFileName // Replace torrentPath with torrentFileName
@@ -86,3 +85,11 @@ function migrate_0_7_0 (state) {
delete ts.fileModtimes delete ts.fileModtimes
}) })
} }
function migrate_0_7_2 (saved) {
if (!saved.prefs) {
saved.prefs = {
downloadPath: config.DEFAULT_DOWNLOAD_PATH
}
}
}