Use UUIDs for WebSQL database filenames instead of a sequential number
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Jun 2015 22:14:23 +0000 (22:14 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Jun 2015 22:14:23 +0000 (22:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145571

Reviewed by Dan Bernstein.

This is a first step towards getting rid of the iOS specific code path where we truncate
database files instead of deleting them (in order to avoid file corruption).

* Modules/webdatabase/DatabaseTracker.cpp:
(WebCore::generateDatabaseFileName):
(WebCore::DatabaseTracker::fullPathForDatabaseNoLock):
* platform/sql/SQLiteFileSystem.cpp:
(WebCore::SQLiteFileSystem::getFileNameForNewDatabase): Deleted.
* platform/sql/SQLiteFileSystem.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185129 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp
Source/WebCore/platform/sql/SQLiteFileSystem.cpp
Source/WebCore/platform/sql/SQLiteFileSystem.h

index 9be5b45..3ff8e03 100644 (file)
@@ -1,3 +1,20 @@
+2015-06-02  Anders Carlsson  <andersca@apple.com>
+
+        Use UUIDs for WebSQL database filenames instead of a sequential number
+        https://bugs.webkit.org/show_bug.cgi?id=145571
+
+        Reviewed by Dan Bernstein.
+
+        This is a first step towards getting rid of the iOS specific code path where we truncate
+        database files instead of deleting them (in order to avoid file corruption).
+
+        * Modules/webdatabase/DatabaseTracker.cpp:
+        (WebCore::generateDatabaseFileName):
+        (WebCore::DatabaseTracker::fullPathForDatabaseNoLock):
+        * platform/sql/SQLiteFileSystem.cpp:
+        (WebCore::SQLiteFileSystem::getFileNameForNewDatabase): Deleted.
+        * platform/sql/SQLiteFileSystem.h:
+
 2015-06-02  Dean Jackson  <dino@apple.com>
 
         Crash in GraphicsContext3D::getInternalFramebufferSize
index 64c6014..7bcdbf0 100644 (file)
@@ -45,6 +45,7 @@
 #include "SecurityOriginHash.h"
 #include "SQLiteFileSystem.h"
 #include "SQLiteStatement.h"
+#include "UUID.h"
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/StdLibExtras.h>
@@ -358,6 +359,16 @@ String DatabaseTracker::originPath(SecurityOrigin* origin) const
     return SQLiteFileSystem::appendDatabaseFileNameToPath(m_databaseDirectoryPath.isolatedCopy(), origin->databaseIdentifier());
 }
 
+static String generateDatabaseFileName()
+{
+    StringBuilder stringBuilder;
+
+    stringBuilder.append(createCanonicalUUIDString());
+    stringBuilder.appendLiteral(".db");
+
+    return stringBuilder.toString();
+}
+
 String DatabaseTracker::fullPathForDatabaseNoLock(SecurityOrigin* origin, const String& name, bool createIfNotExists)
 {
     ASSERT(!m_databaseGuard.tryLock());
@@ -393,7 +404,8 @@ String DatabaseTracker::fullPathForDatabaseNoLock(SecurityOrigin* origin, const
     }
     statement.finalize();
 
-    String fileName = SQLiteFileSystem::getFileNameForNewDatabase(originPath, name, originIdentifier, &m_database);
+    String fileName = generateDatabaseFileName();
+
     if (!addDatabase(origin, name, fileName))
         return String();
 
index 30f7a83..98de996 100644 (file)
@@ -53,32 +53,6 @@ int SQLiteFileSystem::openDatabase(const String& filename, sqlite3** database, b
     return sqlite3_open(fileSystemRepresentation(filename).data(), database);
 }
 
-String SQLiteFileSystem::getFileNameForNewDatabase(const String& dbDir, const String&,
-                                                   const String&, SQLiteDatabase* db)
-{
-    // try to get the next sequence number from the given database
-    // if we can't get a number, return an empty string
-    SQLiteStatement sequenceStatement(*db, "SELECT seq FROM sqlite_sequence WHERE name='Databases';");
-    if (sequenceStatement.prepare() != SQLITE_OK)
-        return String();
-    int result = sequenceStatement.step();
-    int64_t seq = 0;
-    if (result == SQLITE_ROW)
-        seq = sequenceStatement.getColumnInt64(0);
-    else if (result != SQLITE_DONE)
-        return String();
-    sequenceStatement.finalize();
-
-    // increment the number until we can use it to form a file name that doesn't exist
-    String fileName;
-    do {
-        ++seq;
-        fileName = pathByAppendingComponent(dbDir, String::format("%016" PRIx64 ".db", seq));
-    } while (fileExists(fileName));
-
-    return String::format("%016" PRIx64 ".db", seq);
-}
-
 String SQLiteFileSystem::appendDatabaseFileNameToPath(const String& path, const String& fileName)
 {
     return pathByAppendingComponent(path, fileName);
index 9c5f295..d3e4c43 100644 (file)
@@ -54,15 +54,6 @@ public:
     //                     using a custom VFS.
     static int openDatabase(const String& filename, sqlite3** database, bool forWebSQLDatabase);
 
-    // Returns the file name for a database.
-    //
-    // dbDir - The directory where all databases are stored.
-    // dbName - The name of the database.
-    // originIdentifier - The origin that wants to use this database.
-    // db - A database with a number generator used to create unique file names.
-    static String getFileNameForNewDatabase(const String& dbDir, const String& dbName,
-                                            const String& originIdentifier, SQLiteDatabase* db);
-
     // Creates an absolute file path given a directory and a file name.
     //
     // path - The directory.