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

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

Merged
merged 1 commit into from
May 3, 2017

Conversation

mrose17
Copy link
Member

@mrose17 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 18:24
@luixxiul luixxiul changed the title Issue 8602 use muon.file.writeImportant to write ledger files (#8602) May 2, 2017
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

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)

app/ledger.js Outdated
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))) {
Copy link
Member

Choose a reason for hiding this comment

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

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).

Copy link
Member Author

Choose a reason for hiding this comment

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

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...

Copy link
Member

Choose a reason for hiding this comment

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

@mrose17 ah ok- makes sense 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

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

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

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

Choose a reason for hiding this comment

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

Is this a stale comment? renaming?

Copy link
Member Author

Choose a reason for hiding this comment

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

oops! fixed.

@mrose17
Copy link
Member Author

mrose17 commented May 3, 2017

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

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

LGTM 😄 thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants