-
Notifications
You must be signed in to change notification settings - Fork 121
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
History file being overidden if initially empty #388
Comments
I understood that something that should probably handle this was done by @jeremyevans in #193, but it is definitely not working in this case. I also tried "initializing" the file in the Dockerfile already (putting some content in it), but that didn't help. |
If you can provide steps to reproduce this issue without docker, I will look into it. |
I have no idea how. However exactly the same approach for .bash_history is working with no issue. |
OK, maybe I did. First – ensure there is no history file existing. Launch IRB in two windows, enter someting in the first, exit, enter something in the second, exit. You will have only the history from the second. 1st terminal:
2nd terminal:
1st terminal:
|
Thank you for that. I can reproduce the issue. I'll look into it, and hopefully have a fix today or next week. |
Thanks. Unfortunately I'm afraid that this is not the same issue I'm actually facing in the Docker Compose setup with Rails :( |
Can you try this patch?: diff --git a/lib/irb/ext/save-history.rb b/lib/irb/ext/save-history.rb
index 7acaebe..fd5db16 100644
--- a/lib/irb/ext/save-history.rb
+++ b/lib/irb/ext/save-history.rb
@@ -81,9 +81,9 @@ module IRB
end
}
end
- @loaded_history_lines = history.size
- @loaded_history_mtime = File.mtime(history_file)
end
+ @loaded_history_lines = history.size
+ nil
end
def save_history
@@ -107,21 +107,10 @@ module IRB
raise
end
- if File.exist?(history_file) && @loaded_history_mtime &&
- File.mtime(history_file) != @loaded_history_mtime
- history = history[@loaded_history_lines..-1]
- append_history = true
- end
+ history = history[@loaded_history_lines..-1]
- open(history_file, "#{append_history ? 'a' : 'w'}:#{IRB.conf[:LC_MESSAGES].encoding}", 0600) do |f|
+ open(history_file, "a:#{IRB.conf[:LC_MESSAGES].encoding}", 0600) do |f|
hist = history.map{ |l| l.split("\n").join("\\\n") }
- unless append_history
- begin
- hist = hist.last(num) if hist.size > num and num > 0
- rescue RangeError # bignum too big to convert into `long'
- # Do nothing because the bignum should be treated as inifinity
- end
- end
f.puts(hist)
end
end |
Is it enough if I just edit the file in |
That should work. |
Yes! That seems to be working (my original issue in Docker Compose no longer occurs). |
OK. Let me update the tests and send a pull request for this. |
Looks like my previous diff fixed one issue, but broke others. Here's a much simpler diff that doesn't break any tests: diff --git a/lib/irb/ext/save-history.rb b/lib/irb/ext/save-history.rb
index 7acaebe..83d0710 100644
--- a/lib/irb/ext/save-history.rb
+++ b/lib/irb/ext/save-history.rb
@@ -107,7 +107,7 @@ module IRB
raise
end
- if File.exist?(history_file) && @loaded_history_mtime &&
+ if File.exist?(history_file) &&
File.mtime(history_file) != @loaded_history_mtime
history = history[@loaded_history_lines..-1]
append_history = true If there is no history file originally, |
…e doesn't exist If history file didn't exist when irb was started, @loaded_history_mtime would be nil. However, if the history file didn't exist before, but it exists when saving history, that means the history file was modified, and we should handle it the same way as we handle the other case where the history file was modified. Fixes ruby#388
OK, I submitted #389 to fix this |
That seems to be working as well. Awesome, many thanks! |
Description
I'm running multiple containers via Docker Compose with all of them mapped to a single .irb-history file which is placed on Docker volume. When they are launched, the (last?) one overrides the history.
Consider following example:
Dockerfile:
docker-compose.yaml:
run:
docker compose up -d
run in another terminal:
run in another terminal:
run in first terminal:
docker compose down
run in first terminal:
docker compose run first cat /root/.history/.irb-history
result:
puts 'second'
Result of irb_info
Setting Files
~/.irbrc
:The text was updated successfully, but these errors were encountered: