Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/renderer/lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,18 @@ function getDefaultPlayState () {
}
}

function overwriteSync(fromPath, toPath) {
const { unlinkSync, copyFileSync } = require('fs')
try {
// if a previous startup failed, the file could still be write protected
unlinkSync(toPath)
} catch { }
copyFileSync(fromPath, toPath)
}

/* If the saved state file doesn't exist yet, here's what we use instead */
function setupStateSaved () {
const { copyFileSync, mkdirSync, readFileSync } = require('fs')
const { mkdirSync, readFileSync } = require('fs')
const parseTorrent = require('parse-torrent')

const saved = {
Expand Down Expand Up @@ -146,11 +155,11 @@ function setupStateSaved () {
config.DEFAULT_TORRENTS.forEach((t, i) => {
const infoHash = saved.torrents[i].infoHash
// TODO: Doing several sync calls during first startup is not ideal
copyFileSync(
overwriteSync(
path.join(config.STATIC_PATH, t.posterFileName),
path.join(config.POSTER_PATH, infoHash + path.extname(t.posterFileName))
)
copyFileSync(
overwriteSync(
path.join(config.STATIC_PATH, t.torrentFileName),
path.join(config.TORRENT_PATH, infoHash + '.torrent')
)
Expand Down