Skip to content
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

Closed

Conversation

bzoz
Copy link
Contributor

@bzoz bzoz commented Apr 4, 2017

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

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows [commit guidelines][]
Affected core subsystem(s)

repl

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+'.
@bzoz bzoz added the repl Issues and PRs related to the REPL subsystem. label Apr 4, 2017
@vsemozhetbyt vsemozhetbyt added the windows Issues and PRs related to the Windows platform. label Apr 4, 2017
@@ -164,13 +164,22 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
}
}

fs.open(historyPath, 'w', onhandle);
fs.open(historyPath, 'r+', onhandle);
Copy link
Contributor

@Fishrock123 Fishrock123 Apr 4, 2017

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]

@Fishrock123 Fishrock123 dismissed their stale review April 4, 2017 15:56

Oops, didn't see the a+.

@Fishrock123
Copy link
Contributor

Copy link
Member

@jasnell jasnell left a 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) => {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@ghost
Copy link

ghost commented Apr 5, 2017

That's a good idea

@bzoz
Copy link
Contributor Author

bzoz commented Apr 20, 2017

Windows test fail unrelated. Landed in bb041ea

@bzoz bzoz closed this Apr 20, 2017
bzoz added a commit that referenced this pull request Apr 20, 2017
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 <jasnell@gmail.com>
evanlucas pushed a commit that referenced this pull request Apr 25, 2017
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 <jasnell@gmail.com>
@evanlucas evanlucas mentioned this pull request May 1, 2017
evanlucas pushed a commit that referenced this pull request May 1, 2017
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 <jasnell@gmail.com>
evanlucas pushed a commit that referenced this pull request May 2, 2017
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 <jasnell@gmail.com>
@gibfahn
Copy link
Member

gibfahn commented May 16, 2017

Should this be backported to v6.x?

@mscdex
Copy link
Contributor

mscdex commented May 26, 2017

Wherever this gets backported, we also need #12762.

@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
@gibfahn
Copy link
Member

gibfahn commented Jun 18, 2017

Should this be backported to v6.x?

Landed this with #12762, LMK if that wasn't a good idea.

gibfahn pushed a commit that referenced this pull request Jun 18, 2017
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 <jasnell@gmail.com>
@bzoz
Copy link
Contributor Author

bzoz commented Jun 19, 2017

LGTM

gibfahn pushed a commit that referenced this pull request Jun 20, 2017
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 <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 11, 2017
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 <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: EPERM: operation not permitted, open 'C:\Users\username\.node_repl_history'
6 participants