Skip to content

Conversation

@bzoz
Copy link
Contributor

@bzozbzoz 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+'.
@bzozbzoz added the repl Issues and PRs related to the REPL subsystem. label Apr 4, 2017
@vsemozhetbytvsemozhetbyt added the windows Issues and PRs related to the Windows platform. label Apr 4, 2017
Fishrock123
Fishrock123 previously requested changes Apr 4, 2017
}

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

@Fishrock123Fishrock123Apr 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]

@Fishrock123Fishrock123 dismissed their stale reviewApril 4, 2017 15:56

Oops, didn't see the a+.

@Fishrock123
Copy link
Contributor

Copy link
Member

@jasnelljasnell 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

if(err){
returnready(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
ContributorAuthor

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
ContributorAuthor

bzoz commented Apr 20, 2017

Windows test fail unrelated. Landed in bb041ea

@bzozbzoz 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 <[email protected]>
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 <[email protected]>
@evanlucasevanlucas 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 <[email protected]>
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 <[email protected]>
@gibfahn
Copy link
Member

Should this be backported to v6.x?

@mscdex
Copy link
Contributor

Wherever this gets backported, we also need #12762.

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

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 <[email protected]>
@bzoz
Copy link
ContributorAuthor

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 <[email protected]>
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 <[email protected]>
@MylesBorinsMylesBorins mentioned this pull request Jul 18, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

replIssues and PRs related to the REPL subsystem.windowsIssues 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

@bzoz@Fishrock123@gibfahn@mscdex@jasnell@vsemozhetbyt