Merge pull request #1419 from Borewit/fix/issue-1417
Fix startup problems (fix for #1417)
This commit is contained in:
@@ -113,7 +113,6 @@ function setupStateSaved (cb) {
|
|||||||
const cpFile = require('cp-file')
|
const cpFile = require('cp-file')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const parseTorrent = require('parse-torrent')
|
const parseTorrent = require('parse-torrent')
|
||||||
const parallel = require('run-parallel')
|
|
||||||
|
|
||||||
const saved = {
|
const saved = {
|
||||||
prefs: {
|
prefs: {
|
||||||
@@ -133,26 +132,25 @@ function setupStateSaved (cb) {
|
|||||||
|
|
||||||
const tasks = []
|
const tasks = []
|
||||||
|
|
||||||
config.DEFAULT_TORRENTS.map(function (t, i) {
|
config.DEFAULT_TORRENTS.forEach((t, i) => {
|
||||||
const infoHash = saved.torrents[i].infoHash
|
const infoHash = saved.torrents[i].infoHash
|
||||||
tasks.push(function (cb) {
|
tasks.push(
|
||||||
cpFile(
|
cpFile(
|
||||||
path.join(config.STATIC_PATH, t.posterFileName),
|
path.join(config.STATIC_PATH, t.posterFileName),
|
||||||
path.join(config.POSTER_PATH, infoHash + path.extname(t.posterFileName))
|
path.join(config.POSTER_PATH, infoHash + path.extname(t.posterFileName))
|
||||||
).then(cb).catch(cb)
|
)
|
||||||
})
|
)
|
||||||
tasks.push(function (cb) {
|
tasks.push(
|
||||||
cpFile(
|
cpFile(
|
||||||
path.join(config.STATIC_PATH, t.torrentFileName),
|
path.join(config.STATIC_PATH, t.torrentFileName),
|
||||||
path.join(config.TORRENT_PATH, infoHash + '.torrent')
|
path.join(config.TORRENT_PATH, infoHash + '.torrent')
|
||||||
).then(cb).catch(cb)
|
)
|
||||||
})
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
parallel(tasks, function (err) {
|
Promise.all(tasks)
|
||||||
if (err) return cb(err)
|
.then(() => cb(null, saved))
|
||||||
cb(null, saved)
|
.catch(err => cb(err))
|
||||||
})
|
|
||||||
|
|
||||||
function createTorrentObject (t) {
|
function createTorrentObject (t) {
|
||||||
// TODO: Doing several fs.readFileSync calls during first startup is not ideal
|
// TODO: Doing several fs.readFileSync calls during first startup is not ideal
|
||||||
|
|||||||
Reference in New Issue
Block a user