summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/cache_util_win.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-22 21:24:42 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-22 21:24:42 +0000
commit70fe7d516ef0a16bf97a6e2f0143ea6cf5ef6060 (patch)
treef756a3059b6d227d3c8dd7281c20e0f0b2d53d48 /net/disk_cache/cache_util_win.cc
parentc9349d08ebc302d91d695f7abef4750d64a5dc31 (diff)
downloadchromium_src-70fe7d516ef0a16bf97a6e2f0143ea6cf5ef6060.zip
chromium_src-70fe7d516ef0a16bf97a6e2f0143ea6cf5ef6060.tar.gz
chromium_src-70fe7d516ef0a16bf97a6e2f0143ea6cf5ef6060.tar.bz2
Disk cache: Delete all files from the cache folder, instead of only the
files created by the cache. I changed the code that deletes the cache files from the unit tests to use the same code used by the cache itself to discard old caches. However, said code performs a selective deletion of files, and leave anything that it doesn't know about on the folder, and then attempts to remove the folder (knowing that it will fail if there are extra files or directories there). That causes a problem with the unit tests, because some of the tests create an extra file in that folder, so the folder cannot be deleted. As a result, we start accumulating extra folders until we reach our pre-defined limit, and at that time the tests start to fail. We could modify the code to also delete this extra file, but given that the whole cache lives under a hidden folder, it makes sense to simplify the code and just delete every file when we want to discard an old file. So this means that if a user decides to write a file to that folder, we will delete it whenever we update the cache version, or when the user chooses to "Clear browsing data/ cache". Note that if the foreign object is a directory, we won't delete it and it will be moved aside. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1244 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/cache_util_win.cc')
-rw-r--r--net/disk_cache/cache_util_win.cc32
1 files changed, 15 insertions, 17 deletions
diff --git a/net/disk_cache/cache_util_win.cc b/net/disk_cache/cache_util_win.cc
index 2c1457c..39a4de0 100644
--- a/net/disk_cache/cache_util_win.cc
+++ b/net/disk_cache/cache_util_win.cc
@@ -31,32 +31,32 @@
#include <windows.h>
+#include "base/logging.h"
#include "base/scoped_handle.h"
#include "base/file_util.h"
namespace {
// Deletes all the files on path that match search_name pattern.
-// Do not call this function with "*" as search_name.
-bool DeleteFiles(const wchar_t* path, const wchar_t* search_name) {
+void DeleteFiles(const wchar_t* path, const wchar_t* search_name) {
std::wstring name(path);
file_util::AppendToPath(&name, search_name);
WIN32_FIND_DATA data;
ScopedFindFileHandle handle(FindFirstFile(name.c_str(), &data));
- if (!handle.IsValid()) {
- DWORD error = GetLastError();
- return ERROR_FILE_NOT_FOUND == error;
- }
+ if (!handle.IsValid())
+ return;
+
std::wstring adjusted_path(path);
adjusted_path += L'\\';
do {
+ if (data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ||
+ data.dwFileAttributes == FILE_ATTRIBUTE_REPARSE_POINT)
+ continue;
std::wstring current(adjusted_path);
current += data.cFileName;
- if (!DeleteFile(current.c_str()))
- return false;
+ DeleteFile(current.c_str());
} while (FindNextFile(handle, &data));
- return true;
}
} // namespace
@@ -90,17 +90,15 @@ int64 GetSystemMemory() {
bool MoveCache(const std::wstring& from_path, const std::wstring& to_path) {
// I don't want to use the shell version of move because if something goes
// wrong, that version will attempt to move file by file and fail at the end.
- return MoveFileEx(from_path.c_str(), to_path.c_str(), 0) != FALSE;
+ if (!MoveFileEx(from_path.c_str(), to_path.c_str(), 0)) {
+ LOG(ERROR) << "Unable to move the cache: " << GetLastError();
+ return false;
+ }
+ return true;
}
void DeleteCache(const std::wstring& path, bool remove_folder) {
- DeleteFiles(path.c_str(), L"f_*");
- DeleteFiles(path.c_str(), L"data_*");
-
- std::wstring index(path);
- file_util::AppendToPath(&index, L"index");
- DeleteFile(index.c_str());
-
+ DeleteFiles(path.c_str(), L"*");
if (remove_folder)
RemoveDirectory(path.c_str());
}