Skip to content

Commit

Permalink
Merge r223442 - If an origin doesn't have databases in the Databases …
Browse files Browse the repository at this point in the history
…table we should still remove its information from disk in DatabaseTracker::deleteOrigin()

https://bugs.webkit.org/show_bug.cgi?id=178281
<rdar://problem/34576132>

Patch by Maureen Daum <mdaum@apple.com> on 2017-10-16
Reviewed by Brent Fulgham.

Source/WebCore:

New test:
DatabaseTracker.DeleteOriginWithMissingEntryInDatabasesTable

* Modules/webdatabase/DatabaseTracker.cpp:
(WebCore::DatabaseTracker::deleteOrigin):
If databaseNames is empty, don't bail early. Instead, delete everything in the directory
containing the databases for this origin. This condition indicates that we previously
tried to remove the origin but didn't get all of the way through the deletion process.
Because we have lost track of the databases for this origin, we can assume that no
other process is accessing them. This means it should be safe to delete them outright.

Tools:

Verify that if there is an entry in the Origins table but no entries in the Databases
table that we still remove the directory for the origin, and that we remove the
entry from the Origins table.

* TestWebKitAPI/Tests/WebCore/cocoa/DatabaseTrackerTest.mm:
(TestWebKitAPI::TEST):
  • Loading branch information
Maureen Daum authored and carlosgcampos committed Oct 17, 2017
1 parent 782857a commit 6e93d4f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
19 changes: 19 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,22 @@
2017-10-16 Maureen Daum <mdaum@apple.com>

If an origin doesn't have databases in the Databases table we should still remove its information from disk in DatabaseTracker::deleteOrigin()
https://bugs.webkit.org/show_bug.cgi?id=178281
<rdar://problem/34576132>

Reviewed by Brent Fulgham.

New test:
DatabaseTracker.DeleteOriginWithMissingEntryInDatabasesTable

* Modules/webdatabase/DatabaseTracker.cpp:
(WebCore::DatabaseTracker::deleteOrigin):
If databaseNames is empty, don't bail early. Instead, delete everything in the directory
containing the databases for this origin. This condition indicates that we previously
tried to remove the origin but didn't get all of the way through the deletion process.
Because we have lost track of the databases for this origin, we can assume that no
other process is accessing them. This means it should be safe to delete them outright.

2017-10-16 Ryan Haddad <ryanhaddad@apple.com>

Unreviewed attempt to fix the Windows debug build.
Expand Down
19 changes: 16 additions & 3 deletions Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp
Expand Up @@ -823,10 +823,9 @@ bool DatabaseTracker::deleteOrigin(const SecurityOriginData& origin, DeletionMod
return false;

databaseNames = databaseNamesNoLock(origin);
if (databaseNames.isEmpty()) {
if (databaseNames.isEmpty())
LOG_ERROR("Unable to retrieve list of database names for origin %s", origin.databaseIdentifier().utf8().data());
return false;
}

if (!canDeleteOrigin(origin)) {
LOG_ERROR("Tried to delete an origin (%s) while either creating database in it or already deleting it", origin.databaseIdentifier().utf8().data());
ASSERT_NOT_REACHED();
Expand All @@ -845,6 +844,20 @@ bool DatabaseTracker::deleteOrigin(const SecurityOriginData& origin, DeletionMod
}
}

// If databaseNames is empty, delete everything in the directory containing the databases for this origin.
// This condition indicates that we previously tried to remove the origin but didn't get all of the way
// through the deletion process. Because we have lost track of the databases for this origin,
// we can assume that no other process is accessing them. This means it should be safe to delete them outright.
if (databaseNames.isEmpty()) {
#if PLATFORM(COCOA)
RELEASE_LOG_ERROR(DatabaseTracker, "Unable to retrieve list of database names for origin");
#endif
for (const auto& file : listDirectory(originPath(origin), "*")) {
if (!deleteFile(file))
failedToDeleteAnyDatabaseFile = true;
}
}

// If we failed to delete any database file, don't remove the origin from the tracker
// database because we didn't successfully remove all of its data.
if (failedToDeleteAnyDatabaseFile) {
Expand Down
15 changes: 15 additions & 0 deletions Tools/ChangeLog
@@ -1,3 +1,18 @@
2017-10-16 Maureen Daum <mdaum@apple.com>

If an origin doesn't have databases in the Databases table we should still remove its information from disk in DatabaseTracker::deleteOrigin()
https://bugs.webkit.org/show_bug.cgi?id=178281
<rdar://problem/34576132>

Reviewed by Brent Fulgham.

Verify that if there is an entry in the Origins table but no entries in the Databases
table that we still remove the directory for the origin, and that we remove the
entry from the Origins table.

* TestWebKitAPI/Tests/WebCore/cocoa/DatabaseTrackerTest.mm:
(TestWebKitAPI::TEST):

2017-10-16 Maureen Daum <mdaum@apple.com>

If we fail to delete any database file, don't remove its information from the tracker database
Expand Down
39 changes: 39 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebCore/cocoa/DatabaseTrackerTest.mm
Expand Up @@ -228,6 +228,45 @@ static void createFileAtPath(const String& path)
EXPECT_FALSE(fileExists(databaseDirectoryPath));
}

TEST(DatabaseTracker, DeleteOriginWithMissingEntryInDatabasesTable)
{
// Test the case where there is an entry in the Origins table but not
// the Databases table. There is an actual database on disk.
// The information should still be removed from the Origins table, and the
// database should be deleted from disk.
NSString *webSQLDirectory = createTemporaryDirectory(@"WebSQL");
String databaseDirectoryPath(webSQLDirectory.UTF8String);

std::unique_ptr<DatabaseTracker> databaseTracker = DatabaseTracker::trackerWithDatabasePath(databaseDirectoryPath);
SecurityOriginData origin("https", "webkit.org", 443);

databaseTracker->setQuota(origin, 5242880);
EXPECT_EQ((unsigned)1, databaseTracker->origins().size());

String databasePath = pathByAppendingComponent(databaseDirectoryPath, "Databases.db");
EXPECT_TRUE(fileExists(databasePath));

EXPECT_TRUE(databaseTracker->databaseNames(origin).isEmpty());

String originPath = pathByAppendingComponent(databaseDirectoryPath, origin.databaseIdentifier());
EXPECT_TRUE(makeAllDirectories(originPath));
EXPECT_TRUE(fileExists(originPath));

String webDatabasePath = pathByAppendingComponent(originPath, "database.db");
createFileAtPath(webDatabasePath);

EXPECT_TRUE(databaseTracker->deleteOrigin(origin));

EXPECT_FALSE(fileExists(webDatabasePath));
EXPECT_FALSE(fileExists(originPath));

EXPECT_TRUE(databaseTracker->origins().isEmpty());
EXPECT_TRUE(databaseTracker->databaseNames(origin).isEmpty());

removeDirectoryAndAllContents(databaseDirectoryPath);
EXPECT_FALSE(fileExists(databaseDirectoryPath));
}

TEST(DatabaseTracker, DeleteDatabase)
{
// Test the expected case. There is an entry in the Databases table
Expand Down

0 comments on commit 6e93d4f

Please sign in to comment.