-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: support hidden history file on Windows #12207
Conversation
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+'.
@@ -164,13 +164,22 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) { | |||
} | |||
} | |||
|
|||
fs.open(historyPath, 'w', onhandle); | |||
fs.open(historyPath, 'r+', onhandle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this break creating a new file if none exists? [1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if CI is green
} | ||
|
||
function onhandle(err, hnd) { | ||
if (err) { | ||
return ready(err); | ||
} | ||
fs.ftruncate(hnd, 0, (err) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I am gathering, the mode change no longer cause overwrites (appends instead) and so we need to "flush" the file?
From the docs though, it sounds like it does writes and not appends, so this shouldn't be necessary?
'r+' - Open file for reading and writing. An exception occurs if the file does not exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous implementation cleared the file once when opening it with w
. This was the only place that would reset history file content - i.e. if one would set NODE_REPL_HISTORY_SIZE
to value lower than 1000, then the history file would be trimmed when node starts. This ftruncate
call here is to preserve this functionality.
That's a good idea |
Windows test fail unrelated. Landed in bb041ea |
Should this be backported to v6.x? |
Wherever this gets backported, we also need #12762. |
Landed this with #12762, LMK if that wasn't a good idea. |
LGTM |
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 tor+
. The file is guaranteed to exists because of earlier open call witha+
.Fixes: #5261
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
repl