Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

use different file name for development version #3472

Merged
merged 3 commits into from
Aug 27, 2016
Merged
Show file tree
Hide file tree
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
50 changes: 29 additions & 21 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ const eventStore = require('../js/stores/eventStore')
const rulesolver = require('./extensions/brave/content/scripts/pageInformation.js')

// TBD: remove these post beta [MTR]
const logPath = path.join(app.getPath('userData'), 'ledger-log.json')
const publisherPath = path.join(app.getPath('userData'), 'ledger-publisher.json')
const scoresPath = path.join(app.getPath('userData'), 'ledger-scores.json')
const logPath = 'ledger-log.json'
const publisherPath = 'ledger-publisher.json'
const scoresPath = 'ledger-scores.json'

// TBD: move these to secureState post beta [MTR]
const statePath = path.join(app.getPath('userData'), 'ledger-state.json')
const synopsisPath = path.join(app.getPath('userData'), 'ledger-synopsis.json')
const statePath = 'ledger-state.json'
const synopsisPath = 'ledger-synopsis.json'

/*
* ledger globals
Expand Down Expand Up @@ -132,7 +132,7 @@ var boot = () => {
if ((bootP) || (client)) return

bootP = true
fs.access(statePath, fs.FF_OK, (err) => {
fs.access(pathName(statePath), fs.FF_OK, (err) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pathName could probably just be called only once again above instead of repeatedly below, downside is that someone could forget to call it when using statePath (which isn't actually a path) later. I'll merge though.

if (!err) return

if (err.code !== 'ENOENT') console.log('statePath read error: ' + err.toString())
Expand Down Expand Up @@ -337,11 +337,11 @@ var initialize = (onoff) => {

cacheRuleSet(ledgerPublisher.rules)

fs.access(statePath, fs.FF_OK, (err) => {
fs.access(pathName(statePath), fs.FF_OK, (err) => {
if (!err) {
if (clientOptions.verboseP) console.log('\nfound ' + statePath)
if (clientOptions.verboseP) console.log('\nfound ' + pathName(statePath))

fs.readFile(statePath, (err, data) => {
fs.readFile(pathName(statePath), (err, data) => {
var state

if (err) return console.log('read error: ' + err.toString())
Expand Down Expand Up @@ -389,15 +389,15 @@ var enable = (onoff) => {
}

synopsis = new (ledgerPublisher.Synopsis)()
fs.readFile(synopsisPath, (err, data) => {
fs.readFile(pathName(synopsisPath), (err, data) => {
if (clientOptions.verboseP) console.log('\nstarting up ledger publisher integration')

if (err) {
if (err.code !== 'ENOENT') console.log('synopsisPath read error: ' + err.toString())
return updatePublisherInfo()
}

if (clientOptions.verboseP) console.log('\nfound ' + synopsisPath)
if (clientOptions.verboseP) console.log('\nfound ' + pathName(synopsisPath))
try {
synopsis = new (ledgerPublisher.Synopsis)(data)
} catch (ex) {
Expand All @@ -411,13 +411,13 @@ var enable = (onoff) => {
// Check if the add funds notification should be shown every 15 minutes
notificationTimeout = setInterval(notifyAddFunds, msecs.minute * 15)

fs.readFile(publisherPath, (err, data) => {
fs.readFile(pathName(publisherPath), (err, data) => {
if (err) {
if (err.code !== 'ENOENT') console.log('publisherPath read error: ' + err.toString())
return
}

if (clientOptions.verboseP) console.log('\nfound ' + publisherPath)
if (clientOptions.verboseP) console.log('\nfound ' + pathName(publisherPath))
try {
data = JSON.parse(data)
underscore.keys(data).sort().forEach((publisher) => {
Expand Down Expand Up @@ -464,10 +464,10 @@ var updatePublisherInfo = () => {

if (entries.length > 0) data[publisher] = entries
})
syncWriter(publisherPath, data, () => {})
syncWriter(scoresPath, synopsis.allN(), () => {})
syncWriter(pathName(publisherPath), data, () => {})
syncWriter(pathName(scoresPath), synopsis.allN(), () => {})

syncWriter(synopsisPath, synopsis, () => {})
syncWriter(pathName(synopsisPath), synopsis, () => {})
publisherInfo.synopsis = synopsisNormalizer()

if (publisherInfo._internal.debugP) {
Expand Down Expand Up @@ -774,7 +774,7 @@ var callback = (err, result, delayTime) => {
if ((i !== 0) && (i !== logs.length)) logs = logs.slice(i)
if (result) entries.push({ who: 'callback', what: result, when: underscore.now() })

syncWriter(logPath, entries, { flag: 'a' }, () => {})
syncWriter(pathName(logPath), entries, { flag: 'a' }, () => {})
}

if (err) {
Expand All @@ -792,7 +792,7 @@ var callback = (err, result, delayTime) => {
}
cacheRuleSet(result.ruleset)

syncWriter(statePath, result, () => { run(delayTime) })
syncWriter(pathName(statePath), result, () => { run(delayTime) })
}

var roundtrip = (params, options, callback) => {
Expand Down Expand Up @@ -883,7 +883,7 @@ var run = (delayTime) => {
result = client.vote(winner)
if (result) state = result
})
if (state) syncWriter(statePath, state, () => {})
if (state) syncWriter(pathName(statePath), state, () => {})
} catch (ex) {
console.log('ledger client error(2): ' + ex.toString() + (ex.stack ? ('\n' + ex.stack) : ''))
}
Expand All @@ -903,7 +903,7 @@ var run = (delayTime) => {

if (!client) return console.log('\n\n*** MTR says this can\'t happen(1)... please tell him that he\'s wrong!\n\n')

if (client.sync(callback) === true) return run(random.randomInt({ min: 1, max: 10 * msecs.minute }))
if (client.sync(callback) === true) return run(0)
}, delayTime)
}

Expand Down Expand Up @@ -1023,7 +1023,7 @@ var setPaymentInfo = (amount) => {
client.setBraveryProperties(bravery, (err, result) => {
if (err) return console.log('ledger setBraveryProperties: ' + err.toString())

if (result) syncWriter(statePath, result, () => {})
if (result) syncWriter(pathName(statePath), result, () => {})
})
if (ledgerInfo.created) getPaymentInfo()
}
Expand Down Expand Up @@ -1079,6 +1079,14 @@ var syncWriter = (path, obj, options, cb) => {
})
}

const pathSuffix = (process.env.NODE_ENV === 'development') ? '-dev' : ''

var pathName = (name) => {
var parts = path.parse(name)

return path.join(app.getPath('userData'), parts.name + pathSuffix + parts.ext)
}

/**
* UI controller functionality
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"keytar": "^3.0.0",
"l20n": "^3.5.1",
"ledger-balance": "^0.8.46",
"ledger-client": "^0.8.49",
"ledger-client": "^0.8.50",
"ledger-publisher": "^0.8.47",
"lru_cache": "^1.0.0",
"random-lib": "2.1.0",
Expand Down