Skip to content

Commit

Permalink
Allow truncateDatabaseFile on macOS
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259113
rdar://112086693

Reviewed by Chris Dumez.

The truncateDatabaseFile SPI is only enabled on iOS right now. Recently we have been trying to
unifying our SQLite implementation across macOS and iOS to make things more maintainable
(e.g. 265918@main and 265791@main). We should enable this SPI on all Cocoa platforms since there's
nothing iOS-specific about it.

Originally I was going to change the the two callers of truncateDatabaseFile (in StorageTracker in
WebKitLegacy and DatabaseTracker in WebDatabase) to also call this function on all Cocoa platforms
rather than on iOS only. But it turns out that that in turn required enabling a bunch of other logic
for all Cocoa platforms (e.g. cross-process database deletion notifications). This seems like it's
not worth doing considering that the callers are deprecated anyway. So I left DatabaseTracker and
StorageTracker alone in this patch.

* Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj:
* Source/WebCore/PAL/pal/PlatformMac.cmake:
* Source/WebCore/PAL/pal/spi/cocoa/SQLite3SPI.h: Renamed from Source/WebCore/PAL/pal/spi/ios/SQLite3SPI.h.
* Source/WebCore/platform/sql/SQLiteFileSystem.cpp:
* Source/WebCore/platform/sql/SQLiteFileSystem.h:
* Source/WebKitLegacy/Storage/StorageTracker.cpp:

Canonical link: https://commits.webkit.org/272753@main
  • Loading branch information
bnham committed Jan 8, 2024
1 parent 0d56bc1 commit 27d1774
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@
DD20DE1627BC90D80093D175 /* MobileGestaltSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C5AF9141F43A4C7002EAC02 /* MobileGestaltSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
DD20DE1727BC90D80093D175 /* OpenGLESSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C5AF9151F43A4C7002EAC02 /* OpenGLESSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
DD20DE1827BC90D80093D175 /* QuickLookSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C5AF9161F43A4C7002EAC02 /* QuickLookSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
DD20DE1927BC90D80093D175 /* SQLite3SPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C5AF9171F43A4C7002EAC02 /* SQLite3SPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
DD20DE1A27BC90D80093D175 /* SystemPreviewSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 31308B1320A21705003FB929 /* SystemPreviewSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
DD20DE1B27BC90D80093D175 /* UIKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 0C5AF9181F43A4C7002EAC02 /* UIKitSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
DD20DE1C27BC90D80093D175 /* CoreUISPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CCEE4F420D871930047B097 /* CoreUISPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -283,6 +282,7 @@
E34F26F62846D0D90076E549 /* PowerLogSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = E34F26F52846B7550076E549 /* PowerLogSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
E57B44B529AB45F4006069DE /* VisionSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = E57B44B329AB45F4006069DE /* VisionSoftLink.h */; settings = {ATTRIBUTES = (Private, ); }; };
E57B44B729AB462E006069DE /* VisionSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = E57B44B429AB45F4006069DE /* VisionSoftLink.mm */; };
EB3FE8E12A5DB94A00A20986 /* SQLite3SPI.h in Headers */ = {isa = PBXBuildFile; fileRef = EB3FE8E02A5DB94A00A20986 /* SQLite3SPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
F410F1552ACA2EBA00A79859 /* LinkPresentationSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F410F1542ACA2EBA00A79859 /* LinkPresentationSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
F43E89342AEDB71C00097D2D /* CoreTelephonySPI.h in Headers */ = {isa = PBXBuildFile; fileRef = F43E89332AEDB71C00097D2D /* CoreTelephonySPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
F43E89372AEDB8C800097D2D /* CoreTelephonySoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = F43E89362AEDB8C800097D2D /* CoreTelephonySoftLink.mm */; };
Expand Down Expand Up @@ -455,7 +455,6 @@
0C5AF9141F43A4C7002EAC02 /* MobileGestaltSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MobileGestaltSPI.h; sourceTree = "<group>"; };
0C5AF9151F43A4C7002EAC02 /* OpenGLESSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenGLESSPI.h; sourceTree = "<group>"; };
0C5AF9161F43A4C7002EAC02 /* QuickLookSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuickLookSPI.h; sourceTree = "<group>"; };
0C5AF9171F43A4C7002EAC02 /* SQLite3SPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLite3SPI.h; sourceTree = "<group>"; };
0C5AF9181F43A4C7002EAC02 /* UIKitSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIKitSPI.h; sourceTree = "<group>"; };
0C5FFF0B1F78D98F009EFF1A /* Clock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Clock.h; sourceTree = "<group>"; };
0C7785701F45130F00F4EBB6 /* AVFoundationSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AVFoundationSPI.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -673,6 +672,7 @@
E57B44B429AB45F4006069DE /* VisionSoftLink.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VisionSoftLink.mm; sourceTree = "<group>"; };
E5D45D112106A07400D2B738 /* NSColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSColorWellSPI.h; sourceTree = "<group>"; };
E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSPopoverColorWellSPI.h; sourceTree = "<group>"; };
EB3FE8E02A5DB94A00A20986 /* SQLite3SPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SQLite3SPI.h; sourceTree = "<group>"; };
EB8A8DC12509E87E00D1BF90 /* MediaToolboxSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaToolboxSPI.h; sourceTree = "<group>"; };
F410F1542ACA2EBA00A79859 /* LinkPresentationSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkPresentationSPI.h; sourceTree = "<group>"; };
F43E89332AEDB71C00097D2D /* CoreTelephonySPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreTelephonySPI.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -834,6 +834,7 @@
570AB8F020AE2E8D00B8BE87 /* SecKeyProxySPI.h */,
0C2DA13C1F3BEB4900DBC317 /* ServersSPI.h */,
93B38EC125821D2200198E63 /* SpeechSPI.h */,
EB3FE8E02A5DB94A00A20986 /* SQLite3SPI.h */,
4996C0F22717642B002C125D /* TCCSPI.h */,
F44C007D29A06BC200211F33 /* TranslationUIServicesSPI.h */,
0C2DA12B1F3BEB4900DBC317 /* URLFormattingSPI.h */,
Expand Down Expand Up @@ -861,7 +862,6 @@
0C5AF9151F43A4C7002EAC02 /* OpenGLESSPI.h */,
0C5AF9161F43A4C7002EAC02 /* QuickLookSPI.h */,
41E9EE2528BCA19E006A2298 /* SBSStatusBarSPI.h */,
0C5AF9171F43A4C7002EAC02 /* SQLite3SPI.h */,
31308B1320A21705003FB929 /* SystemPreviewSPI.h */,
0C5AF9181F43A4C7002EAC02 /* UIKitSPI.h */,
);
Expand Down Expand Up @@ -1455,7 +1455,7 @@
DD20DE4B27BC90D80093D175 /* Sound.h in Headers */,
DD20DD2427BC90D60093D175 /* SpeechSoftLink.h in Headers */,
DD20DE0A27BC90D80093D175 /* SpeechSPI.h in Headers */,
DD20DE1927BC90D80093D175 /* SQLite3SPI.h in Headers */,
EB3FE8E12A5DB94A00A20986 /* SQLite3SPI.h in Headers */,
DD20DE1A27BC90D80093D175 /* SystemPreviewSPI.h in Headers */,
DD20DE4127BC90D80093D175 /* SystemPreviewSPI.h in Headers */,
DD20DE4C27BC90D80093D175 /* SystemSleepListener.h in Headers */,
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/PAL/pal/PlatformMac.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ list(APPEND PAL_PUBLIC_HEADERS
spi/cocoa/PassKitSPI.h
spi/cocoa/QuartzCoreSPI.h
spi/cocoa/RevealSPI.h
spi/cocoa/SQLite3SPI.h
spi/cocoa/SceneKitSPI.h
spi/cocoa/SecKeyProxySPI.h
spi/cocoa/ServersSPI.h
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions Source/WebCore/platform/sql/SQLiteFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#include <sqlite3.h>
#include <wtf/FileSystem.h>

#if PLATFORM(IOS_FAMILY)
#include <pal/spi/ios/SQLite3SPI.h>
#if PLATFORM(COCOA)
#include <pal/spi/cocoa/SQLite3SPI.h>
#endif

#if PLATFORM(COCOA)
Expand Down Expand Up @@ -118,7 +118,7 @@ bool SQLiteFileSystem::moveDatabaseFile(const String& oldFilePath, const String&
return allMoved;
}

#if PLATFORM(IOS_FAMILY)
#if PLATFORM(COCOA)
bool SQLiteFileSystem::truncateDatabaseFile(sqlite3* database)
{
return sqlite3_file_control(database, 0, SQLITE_TRUNCATE_DATABASE, 0) == SQLITE_OK;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/sql/SQLiteFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SQLiteFileSystem {
WEBCORE_EXPORT static bool moveDatabaseFile(const String& oldFilePath, const String& newFilePath);
WEBCORE_EXPORT static String computeHashForFileName(StringView filePath);

#if PLATFORM(IOS_FAMILY)
#if PLATFORM(COCOA)
// Truncates a database file. Used when MobileSafariSettings deletes a database file,
// since deleting the file nukes the POSIX file locks which would potentially cause Safari
// to corrupt the new db if it's running in the background.
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKitLegacy/Storage/StorageTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
#include <wtf/Vector.h>
#include <wtf/text/CString.h>

#if PLATFORM(IOS_FAMILY)
#include <pal/spi/ios/SQLite3SPI.h>
#if PLATFORM(COCOA)
#include <pal/spi/cocoa/SQLite3SPI.h>
#endif

using namespace WebCore;
Expand Down

0 comments on commit 27d1774

Please sign in to comment.