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

Unified Diff: sql/connection.cc

Issue 1176653002: mandoline filesystem: add a sqlite3 vfs to proxy filesystem usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with ToT and fix the test import. Created 5 years, 6 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: sql/connection.cc
diff --git a/sql/connection.cc b/sql/connection.cc
index c196073ebfb549d39340316e4437e7f2c7cb61b5..82f1f9cefc737d16be514a1663b283af7a108997 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -607,6 +607,14 @@ void Connection::Poison() {
poisoned_ = true;
}
+std::string AsUTF8ForSQL(const base::FilePath& path) {
Scott Hess - ex-Googler 2015/06/17 19:32:58 Please add this to Open()'s implementation while y
Elliot Glaysher 2015/06/17 21:59:34 Done.
+#if defined(OS_WIN)
+ return base::WideToUTF8(path.value());
+#elif defined(OS_POSIX)
+ return path.value();
+#endif
+}
+
// TODO(shess): To the extent possible, figure out the optimal
// ordering for these deletes which will prevent other connections
// from seeing odd behavior. For instance, it may be necessary to
@@ -624,13 +632,38 @@ bool Connection::Delete(const base::FilePath& path) {
base::FilePath journal_path(path.value() + FILE_PATH_LITERAL("-journal"));
base::FilePath wal_path(path.value() + FILE_PATH_LITERAL("-wal"));
- base::DeleteFile(journal_path, false);
- base::DeleteFile(wal_path, false);
- base::DeleteFile(path, false);
+ std::string journal_str = AsUTF8ForSQL(journal_path);
+ std::string wal_str = AsUTF8ForSQL(wal_path);
+ std::string path_str = AsUTF8ForSQL(path);
+
+ sqlite3_vfs* vfs = sqlite3_vfs_find(NULL);
+ CHECK(vfs);
+ CHECK(vfs->xDelete);
+ CHECK(vfs->xAccess);
+
+ // We only work with unix, win32 and mojo filesystems. If you're trying to
+ // use this code with any other VFS, you're not in a good place.
+ CHECK(strncmp(vfs->zName, "unix", 4) == 0 ||
+ strncmp(vfs->zName, "win32", 5) == 0 ||
+ strcmp(vfs->zName, "mojo") == 0);
+
+ vfs->xDelete(vfs, journal_str.c_str(), 0);
+ vfs->xDelete(vfs, wal_str.c_str(), 0);
+ vfs->xDelete(vfs, path_str.c_str(), 0);
+
+ int journal_exists = 0;
+ vfs->xAccess(vfs, journal_str.c_str(), SQLITE_ACCESS_EXISTS,
+ &journal_exists);
+
+ int wal_exists = 0;
+ vfs->xAccess(vfs, wal_str.c_str(), SQLITE_ACCESS_EXISTS,
+ &wal_exists);
+
+ int path_exists = 0;
+ vfs->xAccess(vfs, path_str.c_str(), SQLITE_ACCESS_EXISTS,
+ &path_exists);
- return !base::PathExists(journal_path) &&
- !base::PathExists(wal_path) &&
- !base::PathExists(path);
+ return !journal_exists && !wal_exists && !path_exists;
}
bool Connection::BeginTransaction() {
« no previous file with comments | « sql/BUILD.gn ('k') | sql/connection_unittest.cc » ('j') | sql/connection_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698