summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Reis <reis@janeasystems.com>2019-07-30 07:45:59 +0100
committerRich Trott <rtrott@gmail.com>2019-08-10 19:21:33 -0700
commit3eea43af074e129963a3398dc91ce22a589f8a13 (patch)
tree234dba26a1f854c10e6f60ed527664174716b946
parenteadc3850fe496506847a25a09f01e3c8238d177a (diff)
downloadandroid-node-v8-3eea43af074e129963a3398dc91ce22a589f8a13.tar.gz
android-node-v8-3eea43af074e129963a3398dc91ce22a589f8a13.tar.bz2
android-node-v8-3eea43af074e129963a3398dc91ce22a589f8a13.zip
repl: close file descriptor of history file
PR-URL: https://github.com/nodejs/node/pull/28858 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r--lib/internal/repl/history.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/internal/repl/history.js b/lib/internal/repl/history.js
index dd3ea85095..5d90b40e00 100644
--- a/lib/internal/repl/history.js
+++ b/lib/internal/repl/history.js
@@ -93,6 +93,7 @@ function setupHistory(repl, historyPath, ready) {
fs.ftruncate(hnd, 0, (err) => {
repl._historyHandle = hnd;
repl.on('line', online);
+ repl.once('exit', onexit);
// Reading the file data out erases it
repl.once('flushHistory', function() {
@@ -137,6 +138,15 @@ function setupHistory(repl, historyPath, ready) {
}
}
}
+
+ function onexit() {
+ if (repl._flushing) {
+ repl.once('flushHistory', onexit);
+ return;
+ }
+ repl.off('line', online);
+ fs.close(repl._historyHandle, () => {});
+ }
}
function _replHistoryMessage() {