Skip to content
This repository has been archived by the owner. It is now read-only.

use muon.file.writeImportant to write ledger files (#8602) #8605

Merged
merged 1 commit into from May 3, 2017
Merged

Conversation

@mrose17
Copy link
Member

mrose17 commented May 1, 2017

Test Plan

no new tests. existing ledger tests should apply.

Description

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).

Fixes #8602

@mrose17 mrose17 added this to the 0.15.2 milestone May 1, 2017
@mrose17 mrose17 requested a review from bsclifton May 1, 2017
@luixxiul luixxiul changed the title Issue 8602 use muon.file.writeImportant to write ledger files (#8602) May 2, 2017
@bsclifton bsclifton force-pushed the issue-8602 branch from d1af4fa to 1a67fff May 3, 2017
Copy link
Member

bsclifton left a comment

Comments left; I also noticed that there are two places still using AtomicWriter(). Is that intended? (or should we switch everything to MuonWriter and remove the old code)

muon.file.writeImportant(path, JSON.stringify(payload, null, 2), (success) => {
if (!success) return console.log('write error: ' + path)

if ((quitP) && (!getSetting(settings.PAYMENTS_ENABLED)) && (getSetting(settings.SHUTDOWN_CLEAR_HISTORY))) {

This comment has been minimized.

Copy link
@bsclifton

bsclifton May 3, 2017

Member

this is kind of weird; so just to confirm... when Brave is exiting (user chose to quit) and payments aren't enabled / history is set to clear, we destroy the file by setting quitP to true and then logging something? I mention it's weird because the deletion only happens after the file is written to (versus just deleting the file).

This comment has been minimized.

Copy link
@mrose17

mrose17 May 3, 2017

Author Member

yes, it's weird: this deals with a race condition that @NejcZdovc found during testing.

it's done that way because the file may be in the process of being written when we want to delete it. in which case, if we unlink the file, we might just then go ahead and write it again. hence, always delete in this case...

This comment has been minimized.

Copy link
@bsclifton

bsclifton May 3, 2017

Member

@mrose17 ah ok- makes sense 😄

This comment has been minimized.

Copy link
@mrose17

mrose17 May 3, 2017

Author Member

i'm not sure whether it makes sense. it is certainly counter-intuitive: if you have successfully written the file, and the user is quitting, and the ledger isn't enabled, and history is to be deleted, then get rid of the synopsis file... reminiscent of https://www.youtube.com/watch?v=GoxcyV4DJuY

return fs.unlink(path, (err) => { if (err) console.log('unlink error: ' + err.toString()) })
}

if (ledgerInfo._internal.debugP) console.log('\nrenaming ' + path)

This comment has been minimized.

Copy link
@bsclifton

bsclifton May 3, 2017

Member

Is this a stale comment? renaming?

This comment has been minimized.

Copy link
@mrose17

mrose17 May 3, 2017

Author Member

oops! fixed.

@mrose17
Copy link
Member Author

mrose17 commented May 3, 2017

no more atomicWriter ... 34d7eb9 ... ok, i'm done, i hope!

@bsclifton bsclifton force-pushed the issue-8602 branch from 34d7eb9 to 360f3a5 May 3, 2017
Copy link
Member

bsclifton left a comment

LGTM 😄 thanks!

@bsclifton bsclifton merged commit e0bd325 into master May 3, 2017
0 of 2 checks passed
0 of 2 checks passed
continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@bsclifton bsclifton deleted the issue-8602 branch May 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.