Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1951)

Unified Diff: webkit/fileapi/obfuscated_file_system_file_util.cc

Issue 7608018: Handle inconsistency between DB and Files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/fileapi/obfuscated_file_system_file_util.cc
diff --git a/webkit/fileapi/obfuscated_file_system_file_util.cc b/webkit/fileapi/obfuscated_file_system_file_util.cc
index 52113d695ba4d74d0c4793872fc833600f0b8615..776bd8b3c2290eeccc93f512a55d1b3b56c4e535 100644
--- a/webkit/fileapi/obfuscated_file_system_file_util.cc
+++ b/webkit/fileapi/obfuscated_file_system_file_util.cc
@@ -787,6 +787,15 @@ PlatformFileError ObfuscatedFileSystemFileUtil::CreateFile(
context, source_path, path, true /* copy */);
created = true;
} else {
+ if (file_util::PathExists(path)) {
+ if (!file_util::Delete(path, false)) {
+ NOTREACHED();
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ context->file_system_context()->RecalculateUsage(origin_url, type);
ericu 2011/08/17 00:54:08 What's the purpose of this RecalculateUsage call?
kinuko 2011/08/18 01:26:36 Eric, this is one of the place we wondered if we'd
tzik 2011/08/18 08:02:26 Thanks for explaining kinuko-san, it is what I wan
+ LOG(WARNING) << "A stray file detected";
+ }
+
if (handle) {
error = underlying_file_util_->CreateOrOpen(
context, path, file_flags, handle, &created);
@@ -1032,14 +1041,26 @@ FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin(
return FilePath();
FilePath directory_name;
std::string id = GetOriginIdentifierFromURL(origin);
- if (!create && !origin_database_->HasOriginPath(id))
+
+ bool exists_in_db = origin_database_->HasOriginPath(id);
+ if (!exists_in_db && !create)
return FilePath();
if (!origin_database_->GetPathForOrigin(id, &directory_name))
return FilePath();
+
FilePath path = file_system_directory_.Append(directory_name);
ericu 2011/08/17 00:54:08 This part looks like a good idea.
- if (!file_util::DirectoryExists(path) &&
- (!create || !file_util::CreateDirectory(path)))
- return FilePath();
+ bool exists_in_fs = file_util::DirectoryExists(path);
+ if (!exists_in_db && exists_in_fs) {
+ if (!file_util::Delete(path, true))
+ return FilePath();
+ exists_in_fs = false;
+ }
+
+ if (!exists_in_fs) {
+ if (!create || !file_util::CreateDirectory(path))
+ return FilePath();
+ }
+
return path;
}

Powered by Google App Engine
This is Rietveld 408576698