Skip to content

Commit

Permalink
repl: fix for a+ fd clearing the file on read
Browse files Browse the repository at this point in the history
The second step of augmenting the internal REPL with persistent
history was to re-open the history file with a 'w' handle. This
truncated the file. If a user did not enter a new line before
closing the REPL, their history would be deleted.

PR-URL: #1605
Reviewed-By: Roman Reiss <me@silverwind.io>
  • Loading branch information
chrisdickinson committed May 4, 2015
1 parent 051d482 commit ca219b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ function setupHistory(repl, historyPath, ready) {
}
repl._historyHandle = hnd;
repl.on('line', online);
repl.resume();
return ready(null, repl);

// reading the file data out erases it
repl.once('flushHistory', function() {
repl.resume();
ready(null, repl);
});
flushHistory();
}

// ------ history listeners ------
Expand Down
3 changes: 2 additions & 1 deletion src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@
// If -i or --interactive were passed, or stdin is a TTY.
if (process._forceRepl || NativeModule.require('tty').isatty(0)) {
// REPL
Module.requireRepl().createInternalRepl(process.env, function(err, repl) {
var cliRepl = Module.requireRepl();
cliRepl.createInternalRepl(process.env, function(err, repl) {
if (err) {
throw err;
}
Expand Down

0 comments on commit ca219b0

Please sign in to comment.