Skip to content

Commit b09bf51

Browse files
bzozevanlucas
authored andcommitted
repl: support hidden history file on Windows
On Windows when REPL history file has the hidden attribute node will fail when trying to open it in 'w' mode. This changes the mode to 'r+'. The file is guaranteed to exists because of earlier open call with 'a+'. Fixes: #5261 PR-URL: #12207 Reviewed-By: James M Snell <[email protected]>
1 parent 7d87edc commit b09bf51

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

‎lib/internal/repl.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,19 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready){
165165
}
166166
}
167167

168-
fs.open(historyPath,'w',onhandle);
168+
fs.open(historyPath,'r+',onhandle);
169169
}
170170

171171
functiononhandle(err,hnd){
172+
if(err){
173+
returnready(err);
174+
}
175+
fs.ftruncate(hnd,0,(err)=>{
176+
returnonftruncate(err,hnd);
177+
});
178+
}
179+
180+
functiononftruncate(err,hnd){
172181
if(err){
173182
returnready(err);
174183
}

‎test/fixtures/.empty-hidden-repl-history-file‎

Whitespace-only changes.

‎test/parallel/test-repl-persistent-history.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ const oldHistoryPath = path.join(fixtures, 'old-repl-history-file.json');
7676
constenoentHistoryPath=path.join(fixtures,'enoent-repl-history-file.json');
7777
constemptyHistoryPath=path.join(fixtures,'.empty-repl-history-file');
7878
constdefaultHistoryPath=path.join(common.tmpDir,'.node_repl_history');
79+
constemptyHiddenHistoryPath=path.join(fixtures,
80+
'.empty-hidden-repl-history-file');
7981

8082
consttests=[
8183
{
@@ -163,6 +165,19 @@ const tests = [
163165
test: [UP],
164166
expected: [prompt,replFailedRead,prompt,replDisabled,prompt]
165167
},
168+
{
169+
before: functionbefore(){
170+
if(common.isWindows){
171+
constexecSync=require('child_process').execSync;
172+
execSync(`ATTRIB +H "${emptyHiddenHistoryPath}"`,(err)=>{
173+
assert.ifError(err);
174+
});
175+
}
176+
},
177+
env: {NODE_REPL_HISTORY: emptyHiddenHistoryPath},
178+
test: [UP],
179+
expected: [prompt]
180+
},
166181
{// Make sure this is always the last test, since we change os.homedir()
167182
before: functionbefore(){
168183
// Mock os.homedir() failure

0 commit comments

Comments
(0)