Potenial fix for 'marshal data too short' error - Ref #685
This commit is contained in:
@@ -35,11 +35,9 @@ class CacheFileStore
|
|||||||
end
|
end
|
||||||
|
|
||||||
def read_entry(key)
|
def read_entry(key)
|
||||||
entry_file_path = get_entry_file_path(key)
|
@serializer.load(File.read(get_entry_file_path(key)))
|
||||||
|
rescue
|
||||||
if File.exists?(entry_file_path)
|
nil
|
||||||
return @serializer.load(File.read(entry_file_path))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_entry(key, data_to_store, cache_ttl)
|
def write_entry(key, data_to_store, cache_ttl)
|
||||||
|
|||||||
@@ -41,9 +41,25 @@ describe CacheFileStore do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#read_entry (nonexistent entry)' do
|
describe '#read_entry' do
|
||||||
|
after { expect(@cache.read_entry(key)).to eq @expected }
|
||||||
|
|
||||||
|
context 'when the entry does not exist' do
|
||||||
|
let(:key) { Digest::SHA1.hexdigest('hello world') }
|
||||||
|
|
||||||
it 'should return nil' do
|
it 'should return nil' do
|
||||||
expect(@cache.read_entry(Digest::SHA1.hexdigest('hello world'))).to be_nil
|
@expected = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the file exist but is empty (marshal data too short error)' do
|
||||||
|
let(:key) { 'empty-file' }
|
||||||
|
|
||||||
|
it 'returns nil' do
|
||||||
|
File.new(File.join(@cache.storage_path, key), File::CREAT)
|
||||||
|
|
||||||
|
@expected = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user