-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
repl: persist in plain text, save to home tmp directory by default #2224
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
Conversation
lib/internal/repl.js
Outdated
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.
I think we can drop this check.
With the new condition at lines 99-100, we are sure it is an array.
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.
Oh, haha, true.
I didn't really know how else to check that it was probably JSON is an reasonable and quick way.
a440565 to
8664f5e
Compare
lib/internal/repl.js
Outdated
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.
I know you didn't touch it but this line has no effect. It should be repl.history = repl.history.slice(-repl.historySize);
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.
btw it feels wrong to slice it here. Why isn't it done before saving the file in flushHistory ?
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.
Good catch.
flushHistory() could probably use some fixes/improvements. It always appends to the file no matter what the current file size is.
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.
It shouldn't be permanently appending, since we're using this variant of fs.write, with position set to 0. The existing repl logic should be handling the trimming of history.
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.
(but yes, we should assign repl.history = repl.history.slice(...) here.)
|
Updated based off on this length discussion with @chrisdickinson on IRC: http://logs.libuv.org/io.js/2015-07-22#18:19:50.744 We now prefer a new Still needs some extra log messages about all of this, especially if people are still afterwards specifying a |
lib/internal/repl.js
Outdated
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.
It is possible for os.homedir() to throw, it would be very uncommon but there are some scenarios beyond ENOMEM, ENOBUFS, ENOENT, EMFILE etc. that might be useful to report rather than just crash. I wonder if we should try/catch this and early return ready()?
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.
Oh, whoops, I had forgotten about that, thanks.
It'd probably depend on the error what we may want to do; there a difference between say ENOMEM and ENOENT. :P
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.
Hmm, I'm not really so sure what I meant with this last night! I guess we should just log the error stack and then call ready?
|
I haven't been following the repl history discussion, but what about keeping JSON and just using exclusive locks on the history file? |
Doing thing atomically is another must-do sometime soon. (But I currently don't know how to do that at all.) This however is more about moving off of json for thoughts of of general stability and API going forward, especially as we near a converged release. It just seems like a better option future-wise, so I felt it was best not to delay it; might as well do it now rather than when people might actually rely on it being json for one reason or other. |
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.
What if someone wants to share history files across platforms, maybe on a network drive? I think we'd be better off just using \n here.
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.
We should save using os.EOL, and split liberally on either line ending.
|
I think I've addressed basically everything. We don't really have tests for this, right? I just need to improve the "converting" info message. Also it now only tries to load the old history if there isn't any new history. |
lib/internal/repl.js
Outdated
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.
I think you should split with /[\r\n]+/ for Windows compatibility.
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.
or os.EOL?
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.
@thefourtheye see above comment from @silverwind .
The idea is to be able to share the history file between different platforms.
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.
Oh yeah, thanks for pointing out :-)
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.
/\n|\r/ will result in empty lines when reading \r\n files. better use /\r?\n/ or even /\r?\n|\n?\r/ if you want to be totally safe.
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.
/\r\n|\r|\n/ would be more explicit, right?
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.
Wouldn't catch a \n\r case, if such a platform exists, so you'd need /\r\n|\n\r|\r|\n/ but I really have no preference here.
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.
Based on os.EOL, /\r?\n/ would suffice.
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.
FWIW the regex I suggested has an interesting side-effect: empty lines will be ignored.
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.
@targos oh indeed. That might be a nice 'feature' ;)
|
Updated with everything, PTAL. + cc @chrisdickinson & @rvagg again |
lib/internal/repl.js
Outdated
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.
Will fix this line when squashing
|
Tiny nit re: message, but LGTM. |
|
Now includes some doc updates. Should I mention that ... I'll try to add that bit in later tonight. |
PR-URL: #2224 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
|
landed in d200932...ed6c249 |
|
would be nice to support XDG Base Directory Specification for the default path |
|
+1 @arty-name on the XDG spec standard |
I know @chrisdickinson said it would have been better to have the repl save in plain text, and that doing so would require a semver-major change.
I'd like to get it into 3.0 if possible, and I'm willing to do whatever if it looks good to people.
This also effectively enables it by default, by using
os.homedir()to get an appropriate location (I think?). Perhaps I should be handling more errors if it can't exist?The first commit is the important one.
R= @chrisdickinson or @rvagg since he's doing 3.0?