Removing IndexedDB WebsiteData can fail for some users.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Aug 2016 21:28:12 +0000 (21:28 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 2 Aug 2016 21:28:12 +0000 (21:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=160463

Reviewed by Alex Christensen.

Source/WebCore:

Covered by changes to API test IndexedDB.StoreBlobThenDelete.

For a few months in trunk WebKit, deleting an IndexedDB using WebsiteDataStore API would only
delete the "IndexedDB.sqlite3" file, but would leave the "-wal" and "-shm" files behind.

We'd then fail to delete the directory itself, tricking API clients to think there are still
databases in the given origin.

Furthermore, the code to delete a database first checks for the existence of "IndexedDB.sqlite3"
then refuses to do any further cleanup if it doesn't exist.

We should just always run the entire delete procedure even if IndexedDB.sqlite does not exist.

* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::removeAllDatabasesForOriginPath):

* platform/sql/SQLiteFileSystem.cpp:
(WebCore::SQLiteFileSystem::deleteDatabaseFile):

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobThenDelete.mm:

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/server/IDBServer.cpp
Source/WebCore/platform/sql/SQLiteFileSystem.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobThenDelete.mm

index 7f90fd7..f09e03a 100644 (file)
@@ -1,3 +1,29 @@
+2016-08-02  Brady Eidson  <beidson@apple.com>
+
+        Removing IndexedDB WebsiteData can fail for some users.
+        https://bugs.webkit.org/show_bug.cgi?id=160463
+
+        Reviewed by Alex Christensen.
+
+        Covered by changes to API test IndexedDB.StoreBlobThenDelete.
+
+        For a few months in trunk WebKit, deleting an IndexedDB using WebsiteDataStore API would only
+        delete the "IndexedDB.sqlite3" file, but would leave the "-wal" and "-shm" files behind.
+        
+        We'd then fail to delete the directory itself, tricking API clients to think there are still
+        databases in the given origin.
+        
+        Furthermore, the code to delete a database first checks for the existence of "IndexedDB.sqlite3"
+        then refuses to do any further cleanup if it doesn't exist.
+        
+        We should just always run the entire delete procedure even if IndexedDB.sqlite does not exist.
+        
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::removeAllDatabasesForOriginPath):
+
+        * platform/sql/SQLiteFileSystem.cpp:
+        (WebCore::SQLiteFileSystem::deleteDatabaseFile):
+
 2016-08-02  Alex Christensen  <achristensen@webkit.org>
 
         Fix Mac CMake build.
index f249d40..f5dbbf5 100644 (file)
@@ -543,10 +543,7 @@ static void removeAllDatabasesForOriginPath(const String& originPath, std::chron
     for (auto& databasePath : databasePaths) {
         String databaseFile = pathByAppendingComponent(databasePath, "IndexedDB.sqlite3");
 
-        if (!fileExists(databaseFile))
-            continue;
-
-        if (modifiedSince > std::chrono::system_clock::time_point::min()) {
+        if (modifiedSince > std::chrono::system_clock::time_point::min() && fileExists(databaseFile)) {
             time_t modificationTime;
             if (!getFileModificationTime(databaseFile, modificationTime))
                 continue;
index 5b322e4..b03c455 100644 (file)
@@ -88,15 +88,13 @@ bool SQLiteFileSystem::deleteDatabaseFile(const String& fileName)
     String walFileName = makeString(fileName, ASCIILiteral("-wal"));
     String shmFileName = makeString(fileName, ASCIILiteral("-shm"));
 
-    if (!deleteFile(fileName))
-        return false;
-
-    // Try to delete both the wal and shm files, whether or not they are actually there.
+    // Try to delete all three files whether or not they are there.
+    deleteFile(fileName);
     deleteFile(walFileName);
     deleteFile(shmFileName);
 
-    // If either the wal or shm files remain after the delete attempt, the overall delete operation failed.
-    return !fileExists(walFileName) && !fileExists(shmFileName);
+    // If any of the wal or shm files remain after the delete attempt, the overall delete operation failed.
+    return !fileExists(fileName) && !fileExists(walFileName) && !fileExists(shmFileName);
 }
 
 #if PLATFORM(IOS)
index 4c33977..5696169 100644 (file)
@@ -1,3 +1,12 @@
+2016-08-02  Brady Eidson  <beidson@apple.com>
+
+        Removing IndexedDB WebsiteData can fail for some users.
+        https://bugs.webkit.org/show_bug.cgi?id=160463
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/StoreBlobThenDelete.mm:
+
 2016-08-01  Alex Christensen  <achristensen@webkit.org>
 
         _WKDownloadDelegate.didReceiveResponse should be called before decideDestinationWithSuggestedFilename
index 340b698..f6f5e16 100644 (file)
@@ -74,6 +74,18 @@ TEST(IndexedDB, StoreBlobThenDelete)
     EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:blobFilePath]);
     EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:databaseFilePath]);
 
+    // To make sure that the -wal and -shm files for a database are deleted even if the sqlite3 file is already missing,
+    // we need to:
+    // 1 - Create the path for a fake database that won't actively be in use
+    // 2 - Move -wal and -shm files into that directory
+    // 3 - Make sure the entire directory is deleted
+    NSString *fakeDatabasePath = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/FakeDatabasePath" stringByExpandingTildeInPath];
+    NSString *fakeShmPath = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/FakeDatabasePath/IndexedDB.sqlite3-wal" stringByExpandingTildeInPath];
+    NSString *fakeWalPath = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/FakeDatabasePath/IndexedDB.sqlite3-shm" stringByExpandingTildeInPath];
+    [[NSFileManager defaultManager] createDirectoryAtPath:fakeDatabasePath withIntermediateDirectories:NO attributes:nil error:nil];
+    [[NSFileManager defaultManager] copyItemAtPath:databaseFilePath toPath:fakeShmPath error:nil];
+    [[NSFileManager defaultManager] copyItemAtPath:databaseFilePath toPath:fakeWalPath error:nil];
+
     // Make some other .blob files in the database directory to later validate that only appropriate files are deleted.
     NSString *otherBlob1 = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/7182.blob" stringByExpandingTildeInPath];
     NSString *otherBlob2 = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/1a.blob" stringByExpandingTildeInPath];
@@ -97,6 +109,11 @@ TEST(IndexedDB, StoreBlobThenDelete)
         EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob3]);
         EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:otherBlob4]);
 
+        // Make sure everything related to the fake database is gone.
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeShmPath]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeWalPath]);
+        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeDatabasePath]);
+
         // Now delete them so we're not leaving files around.
         [[NSFileManager defaultManager] removeItemAtPath:otherBlob2 error:nil];
         [[NSFileManager defaultManager] removeItemAtPath:otherBlob3 error:nil];