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() { |