Skip to content
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
1 change: 1 addition & 0 deletions lib/pstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ def load_data(file, read_only)
table = load(file)
raise Error, "PStore file seems to be corrupted." unless table.is_a?(Hash)
rescue EOFError
raise unless file.size == 0
# This seems to be a newly-created file.
table = {}
end
Expand Down
9 changes: 9 additions & 0 deletions test/test_pstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ def clear_store
def second_file
File.join(Dir.tmpdir, "pstore.tmp2.#{Process.pid}")
end

def test_truncated_read_only_store_is_not_empty
@pstore.transaction { @pstore[:foo] = "bar" }
data = File.binread(@pstore_file)
File.binwrite(@pstore_file, data.byteslice(0, data.bytesize - 1))

assert_raise(EOFError) { @pstore.transaction(true) { @pstore[:foo] } }
end

def test_store_operations_require_transaction_owner
ready = Thread::Queue.new
release = Thread::Queue.new
Expand Down