diff options
| author | Ignacio Chiazzo Cardarello <ignaciochiazzo@gmail.com> | 2024-02-02 18:58:19 -0300 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-02-02 21:58:22 +0000 |
| commit | aa780a678e98599fdd9011760dabe17f9e26826c (patch) | |
| tree | 60e3243debbd3cb1e7bf8b52e8f43beae4bd1244 /lib | |
| parent | 6afccdf4499931b94f513dea9e3c1c9bab4a8787 (diff) | |
[ruby/irb] Add a warning for when the history path doesn't exist
(https://github.com/ruby/irb/pull/852)
* Add a warning for when the history path doesn't exist
* warn when the directory does not exist
* added test for when the history_file does not exist
* Update lib/irb/history.rb
---------
https://github.com/ruby/irb/commit/9e6fa67212
Co-authored-by: Stan Lo <stan001212@gmail.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/irb/history.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/irb/history.rb b/lib/irb/history.rb index 90aa9f0bcf..ad17347fbd 100644 --- a/lib/irb/history.rb +++ b/lib/irb/history.rb @@ -59,6 +59,12 @@ module IRB append_history = true end + pathname = Pathname.new(history_file) + unless Dir.exist?(pathname.dirname) + warn "Warning: The directory to save IRB's history file does not exist. Please double check `IRB.conf[:HISTORY_FILE]`'s value." + return + end + File.open(history_file, (append_history ? 'a' : 'w'), 0o600, encoding: IRB.conf[:LC_MESSAGES]&.encoding) do |f| hist = history.map{ |l| l.scrub.split("\n").join("\\\n") } unless append_history |
