Commit 81ad83e4 authored by Maks Orlovich's avatar Maks Orlovich Committed by Commit Bot

SimpleCache: don't close sparse file when trying to close non-sparse one

(but still close it when closing them all)

Not sure if this could ever be hit IRL (testcase would check-fail on file
being invalid in File::Read off ReadSparseRange), but I am going to be
touching this for FD limits, and it helps if the code makes sense.

Bug: 636400
Change-Id: Ie33f1787a81f90b893d963e1fcb1db3b4fd0aab2
Reviewed-on: https://chromium-review.googlesource.com/652965
Commit-Queue: Maks Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarJosh Karlin <jkarlin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506899}
parent 2b00cd1d
......@@ -4438,6 +4438,36 @@ TEST_F(DiskCacheEntryTest, SimpleCacheCreateCollision) {
entry2->Close();
}
TEST_F(DiskCacheEntryTest, SimpleCacheConvertToSparseStream2LeftOver) {
// Testcase for what happens when we have a sparse stream and a left over
// empty stream 2 file.
const int kSize = 10;
scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
CacheTestFillBuffer(buffer->data(), kSize, false);
SetSimpleCacheMode();
InitCache();
disk_cache::Entry* entry;
std::string key("a key");
ASSERT_THAT(CreateEntry(key, &entry), IsOk());
// Create an empty stream 2. To do that, we first make a non-empty one, then
// truncate it (since otherwise the write would just get ignored).
EXPECT_EQ(kSize, WriteData(entry, /* stream = */ 2, /* offset = */ 0,
buffer.get(), kSize, false));
EXPECT_EQ(0, WriteData(entry, /* stream = */ 2, /* offset = */ 0,
buffer.get(), 0, true));
EXPECT_EQ(kSize, WriteSparseData(entry, 5, buffer.get(), kSize));
entry->Close();
// Reopen, and try to get the sparse data back.
ASSERT_THAT(OpenEntry(key, &entry), IsOk());
scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize));
EXPECT_EQ(kSize, ReadSparseData(entry, 5, buffer2.get(), kSize));
EXPECT_EQ(0, memcmp(buffer->data(), buffer2->data(), kSize));
entry->Close();
}
class DiskCacheSimplePrefetchTest : public DiskCacheEntryTest {
public:
DiskCacheSimplePrefetchTest()
......
......@@ -1026,14 +1026,13 @@ void SimpleSynchronousEntry::CloseFile(int index) {
DCHECK(files_[index].IsValid());
files_[index].Close();
}
if (sparse_file_open())
CloseSparseFile();
}
void SimpleSynchronousEntry::CloseFiles() {
for (int i = 0; i < kSimpleEntryNormalFileCount; ++i)
CloseFile(i);
if (sparse_file_open())
CloseSparseFile();
}
bool SimpleSynchronousEntry::CheckHeaderAndKey(int file_index) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment