Changeset 213547 in webkit

Timestamp:
Mar 7, 2017, 3:12:34 PM (7 years ago)
Author:
Ryan Haddad
Message:

Correctly check for an empty database file.
<rdar://problem/30542242> Removing Website Data not working (WebSQL directories being left behind)
https://bugs.webkit.org/show_bug.cgi?id=169256

Patch by Maureen Daum <mdaum@apple.com> on 2017-03-07
Reviewed by Brady Eidson.

Source/WebCore:

Tests: DatabaseTrackerTest.DeleteDatabaseFileIfEmpty verifies that we actually delete an empty file.

Instead of checking that a database file's size is zero bytes, we should check if it contains
any tables. Once we open an empty database file and set its journal mode to WAL, it will have a
valid SQLite header and therefore will no longer be empty. We can know that the database was empty
if it does not contain any tables.

  • Modules/webdatabase/DatabaseTracker.cpp:

(WebCore::DatabaseTracker::deleteDatabaseFileIfEmpty):
Use BEGIN EXCLUSIVE TRANSACTION in order to obtain the exclusive lock. If the database doesn't contain
any tables, it is empty and can be deleted.

Source/WebKit/mac:

Check if the folder for an origin's WebSQL databases is empty after trying to delete
all of its files. Currently we check if the deletedDatabaseFileCount matches the number
of files that were in the folder. However, when we delete the actual database file in
DatabaseTracker::deleteDatabaseFileIfEmpty(), the shm and wal files get deleted along with
the database file, but deletedDatabaseFileCount only gets incremented once.

  • Storage/WebDatabaseManager.mm:

(+[WebDatabaseManager removeEmptyDatabaseFiles]):
Delete the folder if it is empty.

Tools:

Add a test for DatabaseTracker::deleteDatabaseFileIfEmpty that verifies
that if we pass in an empty file it actually gets deleted.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:

Add TestWebKitAPI/Tests/WebCore/DatabaseTrackerTest.cpp.

  • TestWebKitAPI/Tests/WebCore/DatabaseTrackerTest.cpp: Added.

(TestWebKitAPI::TEST):

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r213546 r213547  
     1
     2
     3
     4
     5
     6
     7
     8
     9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
    1212017-03-07  Alex Christensen  <achristensen@webkit.org>
    222
  • trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp

    r211035 r213547  
    12171217        return false;
    12181218   
    1219     // Specify that we want the exclusive locking mode, so after the next read,
     1219    // Specify that we want the exclusive locking mode, so after the next ,
    12201220    // we'll be holding the lock to this database file.
    12211221    SQLiteStatement lockStatement(database, "PRAGMA locking_mode=EXCLUSIVE;");
     
    12271227    lockStatement.finalize();
    12281228
    1229     // Every sqlite database has a sqlite_master table that contains the schema for the database.
    1230     // http://www.sqlite.org/faq.html#q7
    1231     SQLiteStatement readStatement(database, "SELECT * FROM sqlite_master LIMIT 1;");   
    1232     if (readStatement.prepare() != SQLITE_OK)
    1233         return false;
    1234     // We shouldn't expect any result.
    1235     if (readStatement.step() != SQLITE_DONE)
    1236         return false;
    1237     readStatement.finalize();
    1238    
    1239     // At this point, we hold the exclusive lock to this file.  Double-check again to make sure
    1240     // it's still zero bytes.
    1241     if (!isZeroByteFile(path))
    1242         return false;
    1243    
     1229    if (!database.executeCommand("BEGIN EXCLUSIVE TRANSACTION;"))
     1230        return false;
     1231
     1232    // At this point, we hold the exclusive lock to this file.
     1233    // Check that the database doesn't contain any tables.
     1234    if (!database.executeCommand("SELECT name FROM sqlite_master WHERE type='table';"))
     1235        return false;
     1236
     1237    database.executeCommand("COMMIT TRANSACTION;");
     1238
     1239    database.close();
     1240
    12441241    return SQLiteFileSystem::deleteDatabaseFile(path);
    12451242}
  • trunk/Source/WebKit/mac/ChangeLog

    r213500 r213547  
     1
     2
     3
     4
     5
     6
     7
     8
     9
     10
     11
     12
     13
     14
     15
     16
     17
     18
    1192017-03-06  Michael Saboff  <msaboff@apple.com>
    220
  • trunk/Source/WebKit/mac/Storage/WebDatabaseManager.mm

    r211551 r213547  
    214214       
    215215        // If we have removed every database file for this origin, delete the folder for this origin.
    216         if (databaseFileCount == deletedDatabaseFileCount) {
     216        if (databaseFileCount == deletedDatabaseFileCount) {
    217217            // Use rmdir - we don't want the deletion to happen if the folder is not empty.
    218218            rmdir([path fileSystemRepresentation]);
  • trunk/Tools/ChangeLog

    r213546 r213547  
     1
     2
     3
     4
     5
     6
     7
     8
     9
     10
     11
     12
     13
     14
     15
     16
    1172017-03-07  Alex Christensen  <achristensen@webkit.org>
    218
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r213541 r213547  
    189189                5E4B1D2E1D404C6100053621 /* WKScrollViewDelegateCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5E4B1D2C1D404C6100053621 /* WKScrollViewDelegateCrash.mm */; };
    190190                6BFD294C1D5E6C1D008EC968 /* HashCountedSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */; };
     191
    191192                764322D71B61CCC30024F801 /* WordBoundaryTypingAttributes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 764322D51B61CCA40024F801 /* WordBoundaryTypingAttributes.mm */; };
    192193                7673499D1930C5BB00E44DF9 /* StopLoadingDuringDidFailProvisionalLoad_bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7673499A1930182E00E44DF9 /* StopLoadingDuringDidFailProvisionalLoad_bundle.cpp */; };
     
    10871088                5C9E59401D3EB1DE00E3C62E /* ApplicationCache.db-wal */ = {isa = PBXFileReference; lastKnownFileType = file; path = "ApplicationCache.db-wal"; sourceTree = "<group>"; };
    10881089                5E4B1D2C1D404C6100053621 /* WKScrollViewDelegateCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKScrollViewDelegateCrash.mm; path = ../ios/WKScrollViewDelegateCrash.mm; sourceTree = "<group>"; };
     1090
    10891091                7560917719259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCacheAddImageToCacheIOS.mm; sourceTree = "<group>"; };
    10901092                75F3133F18C171B70041CAEC /* EphemeralSessionPushStateNoHistoryCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EphemeralSessionPushStateNoHistoryCallback.cpp; sourceTree = "<group>"; };
     
    16821684                                7CB184C41AA3F2100066EDFD /* ContentExtensions.cpp */,
    16831685                                CD5451E919E41F9D0016936F /* CSSParser.cpp */,
     1686
    16841687                                260BA5781B1D2E7B004FA07C /* DFACombiner.cpp */,
    16851688                                260BA57A1B1D2EE2004FA07C /* DFAHelpers.h */,
     
    28002803                                7CCE7EC81A411A7E00447C4C /* PublicSuffix.mm in Sources */,
    28012804                                7C83E0C21D0A653500FEBCF3 /* QuickLook.mm in Sources */,
     2805
    28022806                                7CCE7F0D1A411AE600447C4C /* ReloadPageAfterCrash.cpp in Sources */,
    28032807                                7C83E0C31D0A653A00FEBCF3 /* RemoteObjectRegistry.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.