Browse Source

repl: fix for a+ fd clearing the file on read

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: https://github.com/iojs/io.js/pull/1605
Reviewed-By: Roman Reiss <me@silverwind.io>
v2.0.2
Chris Dickinson 10 years ago
parent
commit
ca219b00d1
  1. 9
      lib/internal/repl.js
  2. 3
      src/node.js

9
lib/internal/repl.js

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

3
src/node.js

@ -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;
}

Loading…
Cancel
Save