diff --git a/lib/internal/repl.js b/lib/internal/repl.js index c98fd00e35680f..4c27fa2746390f 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -172,25 +172,18 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) { return ready(err); } fs.ftruncate(hnd, 0, (err) => { - return onftruncate(err, hnd); + repl._historyHandle = hnd; + repl.on('line', online); + + // reading the file data out erases it + repl.once('flushHistory', function() { + repl.resume(); + ready(null, repl); + }); + flushHistory(); }); } - function onftruncate(err, hnd) { - if (err) { - return ready(err); - } - repl._historyHandle = hnd; - repl.on('line', online); - - // reading the file data out erases it - repl.once('flushHistory', function() { - repl.resume(); - ready(null, repl); - }); - flushHistory(); - } - // ------ history listeners ------ function online() { repl._flushing = true; diff --git a/test/parallel/test-repl-persistent-history.js b/test/parallel/test-repl-persistent-history.js index 6d95f932ccae45..0ce25a4dd5c7f0 100644 --- a/test/parallel/test-repl-persistent-history.js +++ b/test/parallel/test-repl-persistent-history.js @@ -78,6 +78,8 @@ const emptyHistoryPath = path.join(fixtures, '.empty-repl-history-file'); const defaultHistoryPath = path.join(common.tmpDir, '.node_repl_history'); const emptyHiddenHistoryPath = path.join(fixtures, '.empty-hidden-repl-history-file'); +const devNullHistoryPath = path.join(common.tmpDir, + '.dev-null-repl-history-file'); const tests = [ { @@ -178,6 +180,15 @@ const tests = [ test: [UP], expected: [prompt] }, + { + before: function before() { + if (!common.isWindows) + fs.symlinkSync('/dev/null', devNullHistoryPath); + }, + env: { NODE_REPL_HISTORY: devNullHistoryPath }, + test: [UP], + expected: [prompt] + }, { // Make sure this is always the last test, since we change os.homedir() before: function before() { // Mock os.homedir() failure