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

Side by Side Diff: sql/connection.cc

Issue 17058004: [sql] Static helper to delete database and all associated files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sql/connection.h ('k') | sql/connection_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sql/connection.h" 5 #include "sql/connection.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 CloseInternal(true); 352 CloseInternal(true);
353 353
354 // Mark the database so that future API calls fail appropriately, 354 // Mark the database so that future API calls fail appropriately,
355 // but don't DCHECK (because after calling this function they are 355 // but don't DCHECK (because after calling this function they are
356 // expected to fail). 356 // expected to fail).
357 poisoned_ = true; 357 poisoned_ = true;
358 358
359 return result; 359 return result;
360 } 360 }
361 361
362 // TODO(shess): To the extent possible, figure out the optimal
363 // ordering for these deletes which will prevent other connections
364 // from seeing odd behavior. For instance, it may be necessary to
365 // manually lock the main database file in a SQLite-compatible fashion
366 // (to prevent other processes from opening it), then delete the
367 // journal files, then delete the main database file. Another option
368 // might be to lock the main database file and poison the header with
369 // junk to prevent other processes from opening it successfully (like
370 // Gears "SQLite poison 3" trick).
371 //
372 // static
373 bool Connection::Delete(const base::FilePath& path) {
374 base::ThreadRestrictions::AssertIOAllowed();
375
376 base::FilePath journal_path(path.value() + FILE_PATH_LITERAL("-journal"));
377 base::FilePath wal_path(path.value() + FILE_PATH_LITERAL("-wal"));
378
379 file_util::Delete(journal_path, false);
380 file_util::Delete(wal_path, false);
381 file_util::Delete(path, false);
382
383 return !file_util::PathExists(journal_path) &&
384 !file_util::PathExists(wal_path) &&
385 !file_util::PathExists(path);
386 }
387
362 bool Connection::BeginTransaction() { 388 bool Connection::BeginTransaction() {
363 if (needs_rollback_) { 389 if (needs_rollback_) {
364 DCHECK_GT(transaction_nesting_, 0); 390 DCHECK_GT(transaction_nesting_, 0);
365 391
366 // When we're going to rollback, fail on this begin and don't actually 392 // When we're going to rollback, fail on this begin and don't actually
367 // mark us as entering the nested transaction. 393 // mark us as entering the nested transaction.
368 return false; 394 return false;
369 } 395 }
370 396
371 bool success = true; 397 bool success = true;
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 } 829 }
804 830
805 // Best effort to put things back as they were before. 831 // Best effort to put things back as they were before.
806 const char kNoWritableSchema[] = "PRAGMA writable_schema = OFF"; 832 const char kNoWritableSchema[] = "PRAGMA writable_schema = OFF";
807 ignore_result(Execute(kNoWritableSchema)); 833 ignore_result(Execute(kNoWritableSchema));
808 834
809 return ret; 835 return ret;
810 } 836 }
811 837
812 } // namespace sql 838 } // namespace sql
OLDNEW
« no previous file with comments | « sql/connection.h ('k') | sql/connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698