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

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 abff6cb5845cc1796b351e12cf90c7df23f2c4b8..830b0ab6a7d802c5678cac9c0600b3240071fcf4 100644
--- a/webkit/fileapi/obfuscated_file_system_file_util.cc
+++ b/webkit/fileapi/obfuscated_file_system_file_util.cc
@@ -79,7 +79,7 @@ PlatformFileError ObfuscatedFileSystemFileUtil::CreateOrOpen(
return base::PLATFORM_FILE_ERROR_FAILED;
FileId file_id;
if (!db->GetFileWithPath(virtual_path, &file_id)) {
- // The file doesn't exist.
+ // The file doesn't exist in the database.
if (!(file_flags & (base::PLATFORM_FILE_CREATE |
base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_OPEN_ALWAYS)))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
@@ -88,9 +88,20 @@ PlatformFileError ObfuscatedFileSystemFileUtil::CreateOrOpen(
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
FileInfo file_info;
InitFileInfo(&file_info, parent_id, virtual_path.BaseName().value());
+
+ // There may be a file without database entry out of inconsistency between
+ // actual filesystem and database. We use PLATFORM_FILE_CREATE_ALWAYS
+ // to truncate such file.
+ file_flags &= ~(base::PLATFORM_FILE_OPEN |
+ base::PLATFORM_FILE_CREATE |
+ base::PLATFORM_FILE_OPEN_TRUNCATED);
+ file_flags |= base::PLATFORM_FILE_CREATE_ALWAYS |
+ base::PLATFORM_FILE_OPEN_ALWAYS;
ericu 2011/08/10 17:28:01 From platform_file.h: // PLATFORM_FILE_(OPEN|CRE
tzik 2011/08/16 08:25:33 Yes, the patch went wrong way. It caused tests fai
PlatformFileError error = CreateFile(
context, context->src_origin_url(), context->src_type(), FilePath(),
&file_info, file_flags, file_handle);
+ if (error == base::PLATFORM_FILE_ERROR_EXISTS)
+ error = base::PLATFORM_FILE_OK;
if (created && base::PLATFORM_FILE_OK == error)
*created = true;
return error;
@@ -795,6 +806,21 @@ PlatformFileError ObfuscatedFileSystemFileUtil::CreateFile(
DCHECK(!file_flags); // file_flags is only used by CreateOrOpen.
error = underlying_file_util_->EnsureFileExists(
context, path, &created);
+
+ // If the file already exists, we found a stray file out of
+ // inconsistency between database and filesystem. We should truncate
+ // it to empty.
+ if (error == base::PLATFORM_FILE_OK && !created) {
+ PlatformFile file = base::CreatePlatformFile(
+ path, base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_CREATE_ALWAYS,
+ &created, &error);
+ if (error == base::PLATFORM_FILE_ERROR_EXISTS)
+ error = base::PLATFORM_FILE_OK;
+ if (error == base::PLATFORM_FILE_OK) {
+ if (!base::ClosePlatformFile(file))
+ error = base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ }
}
}
if (error != base::PLATFORM_FILE_OK)
@@ -1032,14 +1058,27 @@ 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();
+ else
+ 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