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

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 dc6b70e80461d2299a24a73e14a8aae02f51cbcc..8526d9f9d0f209276321d74ef8ef9dd1c3361814 100644
--- a/webkit/fileapi/obfuscated_file_system_file_util.cc
+++ b/webkit/fileapi/obfuscated_file_system_file_util.cc
@@ -157,8 +157,17 @@ PlatformFileError ObfuscatedFileSystemFileUtil::CreateOrOpen(
return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
FilePath data_path = DataPathToLocalPath(context->src_origin_url(),
context->src_type(), file_info.data_path);
- return underlying_file_util_->CreateOrOpen(
+ base::PlatformFileError error = underlying_file_util_->CreateOrOpen(
context, data_path, file_flags, file_handle, created);
+ if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
+ // TODO(tzik): Also invalidate on-memory usage cache in UsageTracker.
+ context->file_system_context()->GetQuotaUtil(context->src_type())->
+ InvalidateUsageCache(context->src_origin_url(),
+ context->src_type());
+ LOG(WARNING) << "Lost a backing file.";
+ error = base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ return error;
}
PlatformFileError ObfuscatedFileSystemFileUtil::EnsureFileExists(
@@ -385,6 +394,15 @@ PlatformFileError ObfuscatedFileSystemFileUtil::CopyOrMoveFile(
if (copy) {
FilePath src_data_path = DataPathToLocalPath(context->src_origin_url(),
context->src_type(), src_file_info.data_path);
+ if (!underlying_file_util_->PathExists(context, src_data_path)) {
+ // TODO(tzik): Also invalidate on-memory usage cache in UsageTracker.
+ context->file_system_context()->GetQuotaUtil(context->src_type())->
+ InvalidateUsageCache(context->src_origin_url(),
+ context->src_type());
+ LOG(WARNING) << "Lost a backing file.";
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+
if (overwrite) {
FilePath dest_data_path = DataPathToLocalPath(context->src_origin_url(),
context->src_type(), dest_file_info.data_path);
@@ -865,6 +883,14 @@ PlatformFileError ObfuscatedFileSystemFileUtil::CreateFile(
context, source_path, path, true /* copy */);
created = true;
} else {
+ if (file_util::PathExists(path)) {
ericu 2011/08/24 03:43:50 This should probably use underlying_file_util_, no
tzik 2011/08/29 06:54:13 We use underlying_file_util_ in the next patch. It
kinuko 2011/08/29 07:45:37 Maybe we can explicitly call underlying_file_util_
tzik 2011/08/29 08:34:15 Done.
ericu 2011/08/29 22:48:20 Thanks, and Kinuko, that was a good idea. I've jus
tzik 2011/08/31 02:40:05 Done.
+ if (!file_util::Delete(path, false)) {
+ NOTREACHED();
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ LOG(WARNING) << "A stray file detected";
+ }
+
if (handle) {
error = underlying_file_util_->CreateOrOpen(
context, path, file_flags, handle, &created);
@@ -1111,14 +1137,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);
- 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