Skip to content

Commit ca219b0

Browse files
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: #1605 Reviewed-By: Roman Reiss <[email protected]>
1 parent 051d482 commit ca219b0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/internal/repl.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,13 @@ function setupHistory(repl, historyPath, ready) {
107107
}
108108
repl._historyHandle = hnd;
109109
repl.on('line', online);
110-
repl.resume();
111-
return ready(null, repl);
110+
111+
// reading the file data out erases it
112+
repl.once('flushHistory', function() {
113+
repl.resume();
114+
ready(null, repl);
115+
});
116+
flushHistory();
112117
}
113118

114119
// ------ history listeners ------

src/node.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@
130130
// If -i or --interactive were passed, or stdin is a TTY.
131131
if (process._forceRepl || NativeModule.require('tty').isatty(0)) {
132132
// REPL
133-
Module.requireRepl().createInternalRepl(process.env, function(err, repl) {
133+
var cliRepl = Module.requireRepl();
134+
cliRepl.createInternalRepl(process.env, function(err, repl) {
134135
if (err) {
135136
throw err;
136137
}

0 commit comments

Comments
 (0)