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

Add a warning for when the history path doesn't exist #852

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/irb/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def save_history
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
Expand Down
13 changes: 13 additions & 0 deletions test/irb/test_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ def test_history_different_encodings
$VERBOSE = verbose_bak
end

def test_history_does_not_raise_when_history_file_directory_does_not_exist
backup_history_file = IRB.conf[:HISTORY_FILE]
IRB.conf[:SAVE_HISTORY] = 1
IRB.conf[:HISTORY_FILE] = "fake/fake/fake/history_file"
io = TestInputMethodWithRelineHistory.new

assert_nothing_raised do
io.save_history
end
ensure
IRB.conf[:HISTORY_FILE] = backup_history_file
end

private

def history_concurrent_use_for_input_method(input_method)
Expand Down
Loading