Title: [185129] trunk/Source/WebCore
Revision
185129
Author
ander...@apple.com
Date
2015-06-02 15:14:23 -0700 (Tue, 02 Jun 2015)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (185128 => 185129)


--- trunk/Source/WebCore/ChangeLog	2015-06-02 22:11:32 UTC (rev 185128)
+++ trunk/Source/WebCore/ChangeLog	2015-06-02 22:14:23 UTC (rev 185129)
@@ -1,3 +1,20 @@
+2015-06-02  Anders Carlsson  <ander...@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  <d...@apple.com>
 
         Crash in GraphicsContext3D::getInternalFramebufferSize

Modified: trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp (185128 => 185129)


--- trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp	2015-06-02 22:11:32 UTC (rev 185128)
+++ trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp	2015-06-02 22:14:23 UTC (rev 185129)
@@ -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 @@
     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 @@
     }
     statement.finalize();
 
-    String fileName = SQLiteFileSystem::getFileNameForNewDatabase(originPath, name, originIdentifier, &m_database);
+    String fileName = generateDatabaseFileName();
+
     if (!addDatabase(origin, name, fileName))
         return String();
 

Modified: trunk/Source/WebCore/platform/sql/SQLiteFileSystem.cpp (185128 => 185129)


--- trunk/Source/WebCore/platform/sql/SQLiteFileSystem.cpp	2015-06-02 22:11:32 UTC (rev 185128)
+++ trunk/Source/WebCore/platform/sql/SQLiteFileSystem.cpp	2015-06-02 22:14:23 UTC (rev 185129)
@@ -53,32 +53,6 @@
     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);

Modified: trunk/Source/WebCore/platform/sql/SQLiteFileSystem.h (185128 => 185129)


--- trunk/Source/WebCore/platform/sql/SQLiteFileSystem.h	2015-06-02 22:11:32 UTC (rev 185128)
+++ trunk/Source/WebCore/platform/sql/SQLiteFileSystem.h	2015-06-02 22:14:23 UTC (rev 185129)
@@ -54,15 +54,6 @@
     //                     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.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to