Skip to content

Commit

Permalink
Fix Windows Portable App mode
Browse files Browse the repository at this point in the history
Fixes: #971

This is a perfect example of putting too many statements into a
try-catch block. My bad. I was trying to keep the code simple, but it
bit us here.

This happens because we were using IS_PRODUCTION, but the order of the
consts at the top are:

const IS_PORTABLE = isPortable()
const IS_PRODUCTION = isProduction()

So we're inside of isPortable() and referring to IS_PRODUCTION before
it's defined. This should have thrown an exception, since const does
not allow use-before-define, but we're transforming to ES5 with Babel.

Also, standard could have caught this, but we can't enable the
use-before-define rule until this bug is fixed:
standard/standard#636

Basically, a perfect storm.
  • Loading branch information
feross committed Sep 27, 2016
1 parent 2114532 commit be08925
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/config.js
Expand Up @@ -12,8 +12,8 @@ const IS_TEST = isTest()
const PORTABLE_PATH = IS_TEST
? path.join(process.platform === 'win32' ? 'C:\\Windows\\Temp' : '/tmp', 'WebTorrentTest')
: path.join(path.dirname(process.execPath), 'Portable Settings')
const IS_PORTABLE = isPortable()
const IS_PRODUCTION = isProduction()
const IS_PORTABLE = isPortable()

const UI_HEADER_HEIGHT = 38
const UI_TORRENT_HEIGHT = 100
Expand Down Expand Up @@ -141,11 +141,18 @@ function isPortable () {
if (IS_TEST) {
return true
}
try {
return process.platform === 'win32' && IS_PRODUCTION && !!fs.statSync(PORTABLE_PATH)
} catch (err) {

if (process.platform !== 'win32' || !IS_PRODUCTION) {
// Fast path: Non-Windows platforms should not check for path on disk
return false
}

let portablePathExists = false
try {
portablePathExists = !!fs.statSync(PORTABLE_PATH)
} catch (err) {}

return portablePathExists
}

function isProduction () {
Expand Down

0 comments on commit be08925

Please sign in to comment.