summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIgnacio Chiazzo Cardarello <ignaciochiazzo@gmail.com>2024-02-02 18:58:19 -0300
committergit <svn-admin@ruby-lang.org>2024-02-02 21:58:22 +0000
commitaa780a678e98599fdd9011760dabe17f9e26826c (patch)
tree60e3243debbd3cb1e7bf8b52e8f43beae4bd1244 /lib
parent6afccdf4499931b94f513dea9e3c1c9bab4a8787 (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.rb6
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