summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmoss@google.com <mmoss@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-09 19:51:18 +0000
committermmoss@google.com <mmoss@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-09 19:51:18 +0000
commit2c10721c6927a7218078d9902c3238b81692ebd6 (patch)
tree04750162d068be1cf0e918ecf5d11eb9f3b92311
parentc2aaad178ab0a749ff515aca6a87af9597080edf (diff)
downloadchromium_src-2c10721c6927a7218078d9902c3238b81692ebd6.zip
chromium_src-2c10721c6927a7218078d9902c3238b81692ebd6.tar.gz
chromium_src-2c10721c6927a7218078d9902c3238b81692ebd6.tar.bz2
Fix Linux buildbot breakage on BlockFiles_Grow due to lingering cache files.
The buildbot was breaking because temporary cache files were being created under /tmp, like "/tmp/cache_test\data_*", rather than under /tmp/cache_test, like "/tmp/cache_test/data_*". This prevented the files from being cleaned up when /tmp/cache_test was deleted, and after a few runs, the max of 256 cache files was reached, and the tests failed when they couldn't create more. The following changes were made: - Replace '\' with platform-dependent path separator in various places. - Define constant (same as Windows) for invalid Linux file handle to fix error where wrong value was tested. - Force cache initialization in block_files tests, otherwise it fails to create cache files after calling DeleteCache(). BUG=1917 Review URL: http://codereview.chromium.org/1840 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1918 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/disk_cache/backend_impl.cc6
-rw-r--r--net/disk_cache/block_files.cc9
-rw-r--r--net/disk_cache/block_files_unittest.cc5
-rw-r--r--net/disk_cache/disk_cache_perftest.cc25
-rw-r--r--net/disk_cache/file_posix.cc3
-rw-r--r--net/disk_cache/os_file.h2
-rw-r--r--net/disk_cache/os_file_posix.cc5
7 files changed, 36 insertions, 19 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index f5a8d0a..f0733a7 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -524,8 +524,9 @@ std::wstring BackendImpl::GetFileName(Addr address) const {
return std::wstring();
}
- std::wstring name = StringPrintf(L"%ls\\f_%06x", path_.c_str(),
- address.FileNumber());
+ std::wstring name(path_);
+ std::wstring tmp = StringPrintf(L"f_%06x", address.FileNumber());
+ file_util::AppendToPath(&name, tmp);
return name;
}
@@ -1111,4 +1112,3 @@ bool BackendImpl::CheckEntry(EntryImpl* cache_entry) {
}
} // namespace disk_cache
-
diff --git a/net/disk_cache/block_files.cc b/net/disk_cache/block_files.cc
index fc81973..e14f33d 100644
--- a/net/disk_cache/block_files.cc
+++ b/net/disk_cache/block_files.cc
@@ -4,6 +4,7 @@
#include "net/disk_cache/block_files.h"
+#include "base/file_util.h"
#include "base/histogram.h"
#include "base/string_util.h"
#include "base/time.h"
@@ -11,7 +12,7 @@
namespace {
-const wchar_t* kBlockName = L"\\data_";
+const wchar_t* kBlockName = L"data_";
// This array is used to perform a fast lookup of the nibble bit pattern to the
// type of entry that can be stored there (number of consecutive blocks).
@@ -184,8 +185,9 @@ void BlockFiles::CloseFiles() {
std::wstring BlockFiles::Name(int index) {
// The file format allows for 256 files.
DCHECK(index < 256 || index >= 0);
- std::wstring name = StringPrintf(L"%ls%ls%d",
- path_.c_str(), kBlockName, index);
+ std::wstring name(path_);
+ std::wstring tmp = StringPrintf(L"%ls%d", kBlockName, index);
+ file_util::AppendToPath(&name, tmp);
return name;
}
@@ -417,4 +419,3 @@ bool BlockFiles::FixBlockFileHeader(MappedFile* file) {
}
} // namespace disk_cache
-
diff --git a/net/disk_cache/block_files_unittest.cc b/net/disk_cache/block_files_unittest.cc
index 59ca1d0..211ba96 100644
--- a/net/disk_cache/block_files_unittest.cc
+++ b/net/disk_cache/block_files_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/file_util.h"
#include "net/disk_cache/block_files.h"
#include "net/disk_cache/disk_cache.h"
#include "net/disk_cache/disk_cache_test_base.h"
@@ -11,6 +12,7 @@
TEST_F(DiskCacheTest, BlockFiles_Grow) {
std::wstring path = GetCachePath();
ASSERT_TRUE(DeleteCache(path.c_str()));
+ ASSERT_TRUE(file_util::CreateDirectory(path));
disk_cache::BlockFiles files(path);
ASSERT_TRUE(files.Init(true));
@@ -26,6 +28,7 @@ TEST_F(DiskCacheTest, BlockFiles_Grow) {
TEST_F(DiskCacheTest, BlockFiles_Recover) {
std::wstring path = GetCachePath();
ASSERT_TRUE(DeleteCache(path.c_str()));
+ ASSERT_TRUE(file_util::CreateDirectory(path));
disk_cache::BlockFiles files(path);
ASSERT_TRUE(files.Init(true));
@@ -98,5 +101,3 @@ TEST_F(DiskCacheTest, BlockFiles_Recover) {
EXPECT_EQ(empty_3, header->empty[2]);
EXPECT_EQ(empty_4, header->empty[3]);
}
-
-
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc
index 8cb893e..27f282b 100644
--- a/net/disk_cache/disk_cache_perftest.cc
+++ b/net/disk_cache/disk_cache_perftest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/file_util.h"
#include "base/perftimer.h"
#include "base/scoped_handle.h"
#include "base/timer.h"
@@ -201,11 +202,25 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) {
delete cache;
- ASSERT_TRUE(EvictFileFromSystemCache((path + L"\\index").c_str()));
- ASSERT_TRUE(EvictFileFromSystemCache((path + L"\\data_0").c_str()));
- ASSERT_TRUE(EvictFileFromSystemCache((path + L"\\data_1").c_str()));
- ASSERT_TRUE(EvictFileFromSystemCache((path + L"\\data_2").c_str()));
- ASSERT_TRUE(EvictFileFromSystemCache((path + L"\\data_3").c_str()));
+ std::wstring filename(path);
+ file_util::AppendToPath(&filename, L"index");
+ ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
+
+ filename = path;
+ file_util::AppendToPath(&filename, L"data_0");
+ ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
+
+ filename = path;
+ file_util::AppendToPath(&filename, L"data_1");
+ ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
+
+ filename = path;
+ file_util::AppendToPath(&filename, L"data_2");
+ ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
+
+ filename = path;
+ file_util::AppendToPath(&filename, L"data_3");
+ ASSERT_TRUE(EvictFileFromSystemCache(filename.c_str()));
cache = disk_cache::CreateCacheBackend(path, false, 0);
ASSERT_TRUE(NULL != cache);
diff --git a/net/disk_cache/file_posix.cc b/net/disk_cache/file_posix.cc
index 33866ea..842b4e7 100644
--- a/net/disk_cache/file_posix.cc
+++ b/net/disk_cache/file_posix.cc
@@ -42,7 +42,7 @@ OSFile File::os_file() const {
bool File::IsValid() const {
if (!init_)
return false;
- return (0 != os_file_);
+ return (INVALID_HANDLE_VALUE != os_file_);
}
bool File::Read(void* buffer, size_t buffer_len, size_t offset) {
@@ -118,4 +118,3 @@ size_t File::GetLength() {
}
} // namespace disk_cache
-
diff --git a/net/disk_cache/os_file.h b/net/disk_cache/os_file.h
index bbcedc1..2ef95e0 100644
--- a/net/disk_cache/os_file.h
+++ b/net/disk_cache/os_file.h
@@ -16,6 +16,7 @@ namespace disk_cache {
typedef HANDLE OSFile;
#elif defined(OS_POSIX)
typedef int OSFile;
+const OSFile INVALID_HANDLE_VALUE = -1;
#endif
enum OSFileFlags {
@@ -37,4 +38,3 @@ OSFile CreateOSFile(const std::wstring& name, int flags, bool* created);
} // namespace disk_cache
#endif // NET_DISK_CACHE_OS_FILE_H_
-
diff --git a/net/disk_cache/os_file_posix.cc b/net/disk_cache/os_file_posix.cc
index 7b1da0b..8209e37 100644
--- a/net/disk_cache/os_file_posix.cc
+++ b/net/disk_cache/os_file_posix.cc
@@ -5,6 +5,7 @@
#include "net/disk_cache/os_file.h"
#include <fcntl.h>
+#include <errno.h>
#include "base/logging.h"
#include "base/string_util.h"
@@ -24,7 +25,8 @@ OSFile CreateOSFile(const std::wstring& name, int flags, bool* created) {
if (!open_flags && !(flags & OS_FILE_OPEN) &&
!(flags & OS_FILE_OPEN_ALWAYS)) {
NOTREACHED();
- return -1;
+ errno = ENOTSUP;
+ return INVALID_HANDLE_VALUE;
}
if (flags & OS_FILE_WRITE && flags & OS_FILE_READ) {
@@ -57,4 +59,3 @@ OSFile CreateOSFile(const std::wstring& name, int flags, bool* created) {
}
} // namespace disk_cache
-