1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Don't save history if we can't write, don't load if we can't read.

Fixes: #466.
Signed-off-by: Jordon Bedwell <jordon@envygeeks.com>
This commit is contained in:
Jordon Bedwell 2012-02-15 05:33:15 -06:00
parent 3f9741b628
commit c97ecf0b25

View file

@ -70,9 +70,11 @@ class Pry
def read_from_file
history_file = File.expand_path(Pry.config.history.file)
if File.exists?(history_file)
File.foreach(history_file) { |line| yield(line) }
end
begin
if File.exists?(history_file)
File.foreach(history_file) { |line| yield(line) }
end
rescue; end
end
# The default saver. Appends the given lines to `Pry.history.config.file`.
@ -80,8 +82,10 @@ class Pry
def write_to_file(lines)
history_file = File.expand_path(Pry.config.history.file)
File.open(history_file, 'a') do |f|
lines.each { |ln| f.puts ln }
if File.writable?(history_file)
File.open(history_file, 'a') do |f|
lines.each { |ln| f.puts ln }
end
end
end