repl: fix /dev/null history file regression
This fixes a regression from 83887f35fa where ftruncate() fails on a file symlinked to /dev/null. PR-URL: https://github.com/nodejs/node/pull/12762 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
dc3bbb45a7
commit
c20e87a10e
@ -172,14 +172,6 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
|
|||||||
return ready(err);
|
return ready(err);
|
||||||
}
|
}
|
||||||
fs.ftruncate(hnd, 0, (err) => {
|
fs.ftruncate(hnd, 0, (err) => {
|
||||||
return onftruncate(err, hnd);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onftruncate(err, hnd) {
|
|
||||||
if (err) {
|
|
||||||
return ready(err);
|
|
||||||
}
|
|
||||||
repl._historyHandle = hnd;
|
repl._historyHandle = hnd;
|
||||||
repl.on('line', online);
|
repl.on('line', online);
|
||||||
|
|
||||||
@ -189,6 +181,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
|
|||||||
ready(null, repl);
|
ready(null, repl);
|
||||||
});
|
});
|
||||||
flushHistory();
|
flushHistory();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------ history listeners ------
|
// ------ history listeners ------
|
||||||
|
@ -78,6 +78,8 @@ const emptyHistoryPath = path.join(fixtures, '.empty-repl-history-file');
|
|||||||
const defaultHistoryPath = path.join(common.tmpDir, '.node_repl_history');
|
const defaultHistoryPath = path.join(common.tmpDir, '.node_repl_history');
|
||||||
const emptyHiddenHistoryPath = path.join(fixtures,
|
const emptyHiddenHistoryPath = path.join(fixtures,
|
||||||
'.empty-hidden-repl-history-file');
|
'.empty-hidden-repl-history-file');
|
||||||
|
const devNullHistoryPath = path.join(common.tmpDir,
|
||||||
|
'.dev-null-repl-history-file');
|
||||||
|
|
||||||
const tests = [
|
const tests = [
|
||||||
{
|
{
|
||||||
@ -178,6 +180,15 @@ const tests = [
|
|||||||
test: [UP],
|
test: [UP],
|
||||||
expected: [prompt]
|
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()
|
{ // Make sure this is always the last test, since we change os.homedir()
|
||||||
before: function before() {
|
before: function before() {
|
||||||
// Mock os.homedir() failure
|
// Mock os.homedir() failure
|
||||||
|
Loading…
x
Reference in New Issue
Block a user