Changeset 243019 in webkit


Ignore:
Timestamp:
Mar 15, 2019 3:32:38 PM (5 years ago)
Author:
sihui_liu@apple.com
Message:

[ Mojave WK1 ] Layout Test storage/indexeddb/database-odd-names.html is failing
https://bugs.webkit.org/show_bug.cgi?id=190350
<rdar://problem/45089503>

Reviewed by Geoffrey Garen.

Source/WebCore:

Start to use hash for database file names so that the files can work on any filesystem.

We created v0 folder in IndexedDB directory to put the legacy databases, and v1 folder to put the upgraded
databases.

Tests: TestWebKitAPI.IndexedDB.IndexedDBFileName

TestWebKitAPI.IndexedDB.IndexedDBFileNameV0
TestWebKitAPI.IndexedDB.IndexedDBFileNameV1
TestWebKitAPI.IndexedDB.IndexedDBFileNameAPI
TestWebKitAPI.IndexedDB.HashCollision

  • Modules/indexeddb/IDBDatabaseIdentifier.cpp:

(WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot const):
(WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot):

  • Modules/indexeddb/IDBDatabaseIdentifier.h:
  • Modules/indexeddb/server/IDBServer.cpp:

(WebCore::IDBServer::m_quotaManagerGetter):
(WebCore::IDBServer::IDBServer::performGetAllDatabaseNames):
(WebCore::IDBServer::removeAllDatabasesForFullOriginPath):
(WebCore::IDBServer::removeAllDatabasesForOriginPath):
(WebCore::IDBServer::IDBServer::removeDatabasesModifiedSinceForVersion):
(WebCore::IDBServer::IDBServer::performCloseAndDeleteDatabasesModifiedSince):
(WebCore::IDBServer::IDBServer::removeDatabasesWithOriginsForVersion):
(WebCore::IDBServer::IDBServer::performCloseAndDeleteDatabasesForOrigins):
(WebCore::IDBServer::IDBServer::computeSpaceUsedForOrigin):
(WebCore::IDBServer::IDBServer::upgradeFilesIfNecessary):

  • Modules/indexeddb/server/IDBServer.h:
  • Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:

(WebCore::IDBServer::SQLiteIDBBackingStore::SQLiteIDBBackingStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::fullDatabasePathForDirectory):
(WebCore::IDBServer::SQLiteIDBBackingStore::fullDatabasePath const):
(WebCore::IDBServer::SQLiteIDBBackingStore::databaseNameFromFile):
(WebCore::IDBServer::SQLiteIDBBackingStore::fullDatabaseDirectoryWithUpgrade):
(WebCore::IDBServer::SQLiteIDBBackingStore::getOrEstablishDatabaseInfo):
(WebCore::IDBServer::SQLiteIDBBackingStore::quotaForOrigin const):
(WebCore::IDBServer::SQLiteIDBBackingStore::databasesSizeForOrigin const):
(WebCore::IDBServer::SQLiteIDBBackingStore::getBlobRecordsForObjectStoreRecord):
(WebCore::IDBServer::SQLiteIDBBackingStore::deleteBackingStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::fullDatabaseDirectory const): Deleted.

  • Modules/indexeddb/server/SQLiteIDBBackingStore.h:

(WebCore::IDBServer::SQLiteIDBBackingStore::databaseDirectory const):

  • Modules/indexeddb/server/SQLiteIDBTransaction.cpp:

(WebCore::IDBServer::SQLiteIDBTransaction::moveBlobFilesIfNecessary):
(WebCore::IDBServer::SQLiteIDBTransaction::deleteBlobFilesIfNecessary):

  • platform/sql/SQLiteFileSystem.cpp:

(WebCore::SQLiteFileSystem::computeHashForFileName):

  • platform/sql/SQLiteFileSystem.h:

Source/WebKit:

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::collectIndexedDatabaseOriginsForVersion):
(WebKit::NetworkProcess::indexedDatabaseOrigins):

  • NetworkProcess/NetworkProcess.h:
  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::addSession):
(WebKit::NetworkProcessProxy::createSymLinkForFileUpgrade): For efficientcy and atomicity, we choose to use
symlink to create v0 folder. Because network process does not have the permission to create a symlink, we need
to do this in UI process. UI process would create v0 folder inside the IndexedDB directory if there isn't one.
Also if there is a v0 directory but it doesn't have content, it means it's not a correct symlink and we need to
delete it and create again.

  • UIProcess/Network/NetworkProcessProxy.h:
  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::ensureNetworkProcess):

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/IDBIndexUpgradeToV2.mm:

(TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3:
  • TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-shm:
  • TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-wal:
  • TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName-1.html: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName-2.html: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName.mm: Added.

(-[IndexedDBFileNameMessageHandler userContentController:didReceiveScriptMessage:]):
(runTest):
(createDirectories):
(TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/IndexedDBTempFileSize.mm:

(TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/StoreBlobThenDelete.mm:

(TEST):

Location:
trunk
Files:
3 added
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r243017 r243019  
     12019-03-15  Sihui Liu  <sihui_liu@apple.com>
     2
     3        [ Mojave WK1 ] Layout Test storage/indexeddb/database-odd-names.html is failing
     4        https://bugs.webkit.org/show_bug.cgi?id=190350
     5        <rdar://problem/45089503>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Start to use hash for database file names so that the files can work on any filesystem.
     10
     11        We created v0 folder in IndexedDB directory to put the legacy databases, and v1 folder to put the upgraded
     12        databases.
     13
     14        Tests: TestWebKitAPI.IndexedDB.IndexedDBFileName
     15               TestWebKitAPI.IndexedDB.IndexedDBFileNameV0
     16               TestWebKitAPI.IndexedDB.IndexedDBFileNameV1
     17               TestWebKitAPI.IndexedDB.IndexedDBFileNameAPI
     18               TestWebKitAPI.IndexedDB.HashCollision
     19
     20        * Modules/indexeddb/IDBDatabaseIdentifier.cpp:
     21        (WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot const):
     22        (WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot):
     23        * Modules/indexeddb/IDBDatabaseIdentifier.h:
     24        * Modules/indexeddb/server/IDBServer.cpp:
     25        (WebCore::IDBServer::m_quotaManagerGetter):
     26        (WebCore::IDBServer::IDBServer::performGetAllDatabaseNames):
     27        (WebCore::IDBServer::removeAllDatabasesForFullOriginPath):
     28        (WebCore::IDBServer::removeAllDatabasesForOriginPath):
     29        (WebCore::IDBServer::IDBServer::removeDatabasesModifiedSinceForVersion):
     30        (WebCore::IDBServer::IDBServer::performCloseAndDeleteDatabasesModifiedSince):
     31        (WebCore::IDBServer::IDBServer::removeDatabasesWithOriginsForVersion):
     32        (WebCore::IDBServer::IDBServer::performCloseAndDeleteDatabasesForOrigins):
     33        (WebCore::IDBServer::IDBServer::computeSpaceUsedForOrigin):
     34        (WebCore::IDBServer::IDBServer::upgradeFilesIfNecessary):
     35        * Modules/indexeddb/server/IDBServer.h:
     36        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
     37        (WebCore::IDBServer::SQLiteIDBBackingStore::SQLiteIDBBackingStore):
     38        (WebCore::IDBServer::SQLiteIDBBackingStore::fullDatabasePathForDirectory):
     39        (WebCore::IDBServer::SQLiteIDBBackingStore::fullDatabasePath const):
     40        (WebCore::IDBServer::SQLiteIDBBackingStore::databaseNameFromFile):
     41        (WebCore::IDBServer::SQLiteIDBBackingStore::fullDatabaseDirectoryWithUpgrade):
     42        (WebCore::IDBServer::SQLiteIDBBackingStore::getOrEstablishDatabaseInfo):
     43        (WebCore::IDBServer::SQLiteIDBBackingStore::quotaForOrigin const):
     44        (WebCore::IDBServer::SQLiteIDBBackingStore::databasesSizeForOrigin const):
     45        (WebCore::IDBServer::SQLiteIDBBackingStore::getBlobRecordsForObjectStoreRecord):
     46        (WebCore::IDBServer::SQLiteIDBBackingStore::deleteBackingStore):
     47        (WebCore::IDBServer::SQLiteIDBBackingStore::fullDatabaseDirectory const): Deleted.
     48        * Modules/indexeddb/server/SQLiteIDBBackingStore.h:
     49        (WebCore::IDBServer::SQLiteIDBBackingStore::databaseDirectory const):
     50        * Modules/indexeddb/server/SQLiteIDBTransaction.cpp:
     51        (WebCore::IDBServer::SQLiteIDBTransaction::moveBlobFilesIfNecessary):
     52        (WebCore::IDBServer::SQLiteIDBTransaction::deleteBlobFilesIfNecessary):
     53        * platform/sql/SQLiteFileSystem.cpp:
     54        (WebCore::SQLiteFileSystem::computeHashForFileName):
     55        * platform/sql/SQLiteFileSystem.h:
     56
    1572019-03-15  Zalan Bujtas  <zalan@apple.com>
    258
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.cpp

    r242729 r243019  
    5656}
    5757
    58 String IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(const String& rootDirectory) const
     58String IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(const String& rootDirectory, const String& versionString) const
    5959{
    60     return databaseDirectoryRelativeToRoot(m_origin.topOrigin, m_origin.clientOrigin, rootDirectory);
     60    return databaseDirectoryRelativeToRoot(m_origin.topOrigin, m_origin.clientOrigin, rootDirectory, versionString);
    6161}
    6262
    63 String IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(const SecurityOriginData& topLevelOrigin, const SecurityOriginData& openingOrigin, const String& rootDirectory)
     63String IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(const SecurityOriginData& topLevelOrigin, const SecurityOriginData& openingOrigin, const String& rootDirectory, const String& versionString)
    6464{
    65     String mainFrameDirectory = FileSystem::pathByAppendingComponent(rootDirectory, topLevelOrigin.databaseIdentifier());
     65    String versionDirectory = FileSystem::pathByAppendingComponent(rootDirectory, versionString);
     66    String mainFrameDirectory = FileSystem::pathByAppendingComponent(versionDirectory, topLevelOrigin.databaseIdentifier());
    6667
    6768    // If the opening origin and main frame origins are the same, there is no partitioning.
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h

    r242729 r243019  
    8585    const ClientOrigin& origin() const { return m_origin; }
    8686
    87     String databaseDirectoryRelativeToRoot(const String& rootDirectory) const;
    88     static String databaseDirectoryRelativeToRoot(const SecurityOriginData& topLevelOrigin, const SecurityOriginData& openingOrigin, const String& rootDirectory);
     87    String databaseDirectoryRelativeToRoot(const String& rootDirectory, const String& versionString="v1") const;
     88    static String databaseDirectoryRelativeToRoot(const SecurityOriginData& topLevelOrigin, const SecurityOriginData& openingOrigin, const String& rootDirectory, const String& versionString);
    8989
    9090    template<class Encoder> void encode(Encoder&) const;
  • trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp

    r242947 r243019  
    3333#include "Logging.h"
    3434#include "MemoryIDBBackingStore.h"
     35#include "SQLiteDatabase.h"
    3536#include "SQLiteFileSystem.h"
    3637#include "SQLiteIDBBackingStore.h"
     38#include "SQLiteStatement.h"
    3739#include "SecurityOrigin.h"
    3840#include "StorageQuotaManager.h"
     
    7476{
    7577    LOG(IndexedDB, "IDBServer created at path %s", databaseDirectoryPath.utf8().data());
     78    postDatabaseTask(createCrossThreadTask(*this, &IDBServer::upgradeFilesIfNecessary));
    7679}
    7780
     
    467470void IDBServer::performGetAllDatabaseNames(uint64_t serverConnectionIdentifier, const SecurityOriginData& mainFrameOrigin, const SecurityOriginData& openingOrigin, uint64_t callbackID)
    468471{
    469     String directory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(mainFrameOrigin, openingOrigin, m_databaseDirectoryPath);
    470 
    471     Vector<String> entries = FileSystem::listDirectory(directory, "*"_s);
     472    String oldDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(mainFrameOrigin, openingOrigin, m_databaseDirectoryPath, "v0");
     473    Vector<String> files = FileSystem::listDirectory(oldDirectory, "*"_s);
    472474    Vector<String> databases;
    473     databases.reserveInitialCapacity(entries.size());
    474     for (auto& entry : entries) {
    475         String encodedName = FileSystem::lastComponentOfPathIgnoringTrailingSlash(entry);
    476         databases.uncheckedAppend(SQLiteIDBBackingStore::databaseNameFromEncodedFilename(encodedName));
     475    for (auto& file : files) {
     476        String encodedName = FileSystem::lastComponentOfPathIgnoringTrailingSlash(file);
     477        databases.append(SQLiteIDBBackingStore::databaseNameFromEncodedFilename(encodedName));
     478    }
     479
     480    String directory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(mainFrameOrigin, openingOrigin, m_databaseDirectoryPath, "v1");
     481    files = FileSystem::listDirectory(directory, "*"_s);
     482    for (auto& file : files) {
     483        auto databaseName = SQLiteIDBBackingStore::databaseNameFromFile(SQLiteIDBBackingStore::fullDatabasePathForDirectory(file));
     484        if (!databaseName.isEmpty())
     485            databases.append(databaseName);
    477486    }
    478487
     
    551560}
    552561
    553 static void removeAllDatabasesForOriginPath(const String& originPath, WallTime modifiedSince)
     562static void removeAllDatabasesForFullOriginPath(const String& originPath, WallTime modifiedSince)
    554563{
    555564    LOG(IndexedDB, "removeAllDatabasesForOriginPath with originPath %s", originPath.utf8().data());
     
    557566
    558567    for (auto& databasePath : databasePaths) {
    559         if (FileSystem::fileIsDirectory(databasePath, FileSystem::ShouldFollowSymbolicLinks::No))
    560             removeAllDatabasesForOriginPath(databasePath, modifiedSince);
    561 
    562568        String databaseFile = FileSystem::pathByAppendingComponent(databasePath, "IndexedDB.sqlite3");
    563569        if (modifiedSince > -WallTime::infinity() && FileSystem::fileExists(databaseFile)) {
     
    619625}
    620626
     627static void removeAllDatabasesForOriginPath(const String& originPath, WallTime modifiedSince)
     628{
     629    String databaseIdentifier = FileSystem::lastComponentOfPathIgnoringTrailingSlash(originPath);
     630    if (!SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
     631        return;
     632   
     633    auto directories = FileSystem::listDirectory(originPath, "*"_s);
     634    for (auto& directory : directories) {
     635        String databaseIdentifier = FileSystem::lastComponentOfPathIgnoringTrailingSlash(directory);
     636        if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
     637            removeAllDatabasesForFullOriginPath(directory, modifiedSince);
     638    }
     639   
     640    removeAllDatabasesForFullOriginPath(originPath, modifiedSince);
     641}
     642
     643void IDBServer::removeDatabasesModifiedSinceForVersion(WallTime modifiedSince, const String& version)
     644{
     645    String versionPath = FileSystem::pathByAppendingComponent(m_databaseDirectoryPath, version);
     646    for (auto& originPath : FileSystem::listDirectory(versionPath, "*")) {
     647        String databaseIdentifier = FileSystem::lastComponentOfPathIgnoringTrailingSlash(originPath);
     648        if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
     649            removeAllDatabasesForOriginPath(originPath, modifiedSince);
     650    }
     651}
     652
    621653void IDBServer::performCloseAndDeleteDatabasesModifiedSince(WallTime modifiedSince, uint64_t callbackID)
    622654{
    623655    if (!m_databaseDirectoryPath.isEmpty()) {
    624         Vector<String> originPaths = FileSystem::listDirectory(m_databaseDirectoryPath, "*");
    625         for (auto& originPath : originPaths)
    626             removeAllDatabasesForOriginPath(originPath, modifiedSince);
     656        removeDatabasesModifiedSinceForVersion(modifiedSince, "v0");
     657        removeDatabasesModifiedSinceForVersion(modifiedSince, "v1");
    627658    }
    628659
     
    630661}
    631662
     663void IDBServer::removeDatabasesWithOriginsForVersion(const Vector<SecurityOriginData> &origins, const String& version)
     664{
     665    String versionPath = FileSystem::pathByAppendingComponent(m_databaseDirectoryPath, version);
     666    for (const auto& origin : origins) {
     667        String originPath = FileSystem::pathByAppendingComponent(versionPath, origin.databaseIdentifier());
     668        removeAllDatabasesForOriginPath(originPath, -WallTime::infinity());
     669       
     670        for (auto& topOriginPath : FileSystem::listDirectory(versionPath, "*")) {
     671            originPath = FileSystem::pathByAppendingComponent(topOriginPath, origin.databaseIdentifier());
     672            removeAllDatabasesForOriginPath(originPath, -WallTime::infinity());
     673        }
     674    }
     675}
     676   
    632677void IDBServer::performCloseAndDeleteDatabasesForOrigins(const Vector<SecurityOriginData>& origins, uint64_t callbackID)
    633678{
    634679    if (!m_databaseDirectoryPath.isEmpty()) {
    635         for (const auto& origin : origins) {
    636             String originPath = FileSystem::pathByAppendingComponent(m_databaseDirectoryPath, origin.databaseIdentifier());
    637             removeAllDatabasesForOriginPath(originPath, -WallTime::infinity());
    638 
    639             for (const auto& topOriginPath : FileSystem::listDirectory(m_databaseDirectoryPath, "*")) {
    640                 originPath = FileSystem::pathByAppendingComponent(topOriginPath, origin.databaseIdentifier());
    641                 removeAllDatabasesForOriginPath(originPath, -WallTime::infinity());
    642             }
    643         }
     680        removeDatabasesWithOriginsForVersion(origins, "v0");
     681        removeDatabasesWithOriginsForVersion(origins, "v1");
    644682    }
    645683
     
    764802    ASSERT(!isMainThread());
    765803
    766     auto path = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, m_databaseDirectoryPath);
    767     auto size = SQLiteIDBBackingStore::databasesSizeForFolder(path);
     804    auto oldVersionOriginDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, m_databaseDirectoryPath, "v0");
     805    auto newVersionOriginDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, m_databaseDirectoryPath, "v1");
     806    auto size = SQLiteIDBBackingStore::databasesSizeForFolder(oldVersionOriginDirectory) + SQLiteIDBBackingStore::databasesSizeForFolder(newVersionOriginDirectory);
    768807
    769808    postDatabaseTaskReply(createCrossThreadTask(*this, &IDBServer::finishComputingSpaceUsedForOrigin, origin, size));
     
    807846}
    808847
     848void IDBServer::upgradeFilesIfNecessary()
     849{
     850    if (m_databaseDirectoryPath.isEmpty() || !FileSystem::fileExists(m_databaseDirectoryPath))
     851        return;
     852
     853    String newVersionDirectory = FileSystem::pathByAppendingComponent(m_databaseDirectoryPath, "v1");
     854    if (!FileSystem::fileExists(newVersionDirectory))
     855        FileSystem::makeAllDirectories(newVersionDirectory);
     856}
     857
    809858} // namespace IDBServer
    810859} // namespace WebCore
  • trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h

    r242911 r243019  
    139139    void didPerformCloseAndDeleteDatabases(uint64_t callbackID);
    140140
     141    void upgradeFilesIfNecessary();
     142    void removeDatabasesModifiedSinceForVersion(WallTime, const String&);
     143    void removeDatabasesWithOriginsForVersion(const Vector<SecurityOriginData>&, const String&);
     144
    141145    class QuotaUser final : public StorageQuotaUser {
    142146        WTF_MAKE_FAST_ALLOCATED;
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp

    r242911 r243019  
    233233SQLiteIDBBackingStore::SQLiteIDBBackingStore(const IDBDatabaseIdentifier& identifier, const String& databaseRootDirectory, IDBBackingStoreTemporaryFileHandler& fileHandler, uint64_t quota)
    234234    : m_identifier(identifier)
     235    , m_databaseRootDirectory(databaseRootDirectory)
    235236    , m_temporaryFileHandler(fileHandler)
    236237    , m_quota(quota)
    237238{
    238     m_absoluteDatabaseDirectory = identifier.databaseDirectoryRelativeToRoot(databaseRootDirectory);
     239    m_databaseDirectory = fullDatabaseDirectoryWithUpgrade();
    239240}
    240241
     
    765766}
    766767
    767 String SQLiteIDBBackingStore::fullDatabaseDirectory() const
    768 {
    769     ASSERT(!m_identifier.databaseName().isNull());
    770 
    771     return FileSystem::pathByAppendingComponent(m_absoluteDatabaseDirectory, filenameForDatabaseName());
     768String SQLiteIDBBackingStore::fullDatabasePathForDirectory(const String& fullDatabaseDirectory)
     769{
     770    return FileSystem::pathByAppendingComponent(fullDatabaseDirectory, "IndexedDB.sqlite3");
    772771}
    773772
    774773String SQLiteIDBBackingStore::fullDatabasePath() const
    775774{
    776     ASSERT(!m_identifier.databaseName().isNull());
    777 
    778     return FileSystem::pathByAppendingComponent(fullDatabaseDirectory(), "IndexedDB.sqlite3");
     775    return fullDatabasePathForDirectory(m_databaseDirectory);
     776}
     777
     778String SQLiteIDBBackingStore::databaseNameFromFile(const String& databasePath)
     779{
     780    SQLiteDatabase database;
     781    if (!database.open(databasePath)) {
     782        LOG_ERROR("Failed to open SQLite database at path '%s' when getting database name", databasePath.utf8().data());
     783        return { };
     784    }
     785    if (!database.tableExists("IDBDatabaseInfo"_s)) {
     786        LOG_ERROR("Could not find IDBDatabaseInfo table and get database name(%i) - %s", database.lastError(), database.lastErrorMsg());
     787        database.close();
     788        return { };
     789    }
     790    SQLiteStatement sql(database, "SELECT value FROM IDBDatabaseInfo WHERE key = 'DatabaseName';");
     791    auto databaseName = sql.getColumnText(0);
     792    database.close();
     793    return databaseName;
     794}
     795
     796String SQLiteIDBBackingStore::fullDatabaseDirectoryWithUpgrade()
     797{
     798    String oldOriginDirectory = m_identifier.databaseDirectoryRelativeToRoot(m_databaseRootDirectory, "v0");
     799    String oldDatabaseDirectory = FileSystem::pathByAppendingComponent(oldOriginDirectory, filenameForDatabaseName());
     800    String newOriginDirectory = m_identifier.databaseDirectoryRelativeToRoot(m_databaseRootDirectory, "v1");
     801    String fileNameHash = SQLiteFileSystem::computeHashForFileName(m_identifier.databaseName());
     802    Vector<String> directoriesWithSameHash = FileSystem::listDirectory(newOriginDirectory, fileNameHash + "*");
     803    String newDatabaseDirectory = FileSystem::pathByAppendingComponent(newOriginDirectory, fileNameHash);
     804    FileSystem::makeAllDirectories(newDatabaseDirectory);
     805
     806    if (FileSystem::fileExists(oldDatabaseDirectory)) {
     807        FileSystem::moveFile(oldDatabaseDirectory, newDatabaseDirectory);
     808        FileSystem::deleteEmptyDirectory(oldOriginDirectory);
     809    }
     810
     811    return newDatabaseDirectory;
    779812}
    780813
     
    788821    }
    789822
    790     FileSystem::makeAllDirectories(fullDatabaseDirectory());
    791823    String dbFilename = fullDatabasePath();
    792824
     
    847879    ASSERT(!isMainThread());
    848880    uint64_t diskFreeSpaceSize = 0;
    849     FileSystem::getVolumeFreeSpace(m_absoluteDatabaseDirectory, diskFreeSpaceSize);
     881    FileSystem::getVolumeFreeSpace(m_identifier.databaseDirectoryRelativeToRoot(m_databaseRootDirectory), diskFreeSpaceSize);
    850882    return std::min(diskFreeSpaceSize / 2, m_quota);
    851883}
     
    863895uint64_t SQLiteIDBBackingStore::databasesSizeForOrigin() const
    864896{
    865     return databasesSizeForFolder(m_absoluteDatabaseDirectory);
     897    String oldVersionOriginDirectory = m_identifier.databaseDirectoryRelativeToRoot(m_databaseRootDirectory, "v0");
     898    String newVersionOriginDirectory = m_identifier.databaseDirectoryRelativeToRoot(m_databaseRootDirectory, "v1");
     899    return databasesSizeForFolder(oldVersionOriginDirectory) + databasesSizeForFolder(newVersionOriginDirectory);
    866900}
    867901
     
    19101944
    19111945    ASSERT(!blobURLSet.isEmpty());
    1912     String databaseDirectory = fullDatabaseDirectory();
    19131946    for (auto& blobURL : blobURLSet) {
    19141947        auto* sql = cachedStatement(SQL::BlobFilenameForBlobURL, "SELECT fileName FROM BlobFiles WHERE blobURL = ?;"_s);
     
    19271960
    19281961        String fileName = sql->getColumnText(0);
    1929         blobFilePaths.append(FileSystem::pathByAppendingComponent(databaseDirectory, fileName));
     1962        blobFilePaths.append(FileSystem::pathByAppendingComponent(m_databaseDirectory, fileName));
    19301963    }
    19311964    sessionID = m_identifier.sessionID();
     
    26062639    }
    26072640
    2608     String databaseDirectory = fullDatabaseDirectory();
    26092641    for (auto& file : blobFiles) {
    2610         String fullPath = FileSystem::pathByAppendingComponent(databaseDirectory, file);
     2642        String fullPath = FileSystem::pathByAppendingComponent(m_databaseDirectory, file);
    26112643        if (!FileSystem::deleteFile(fullPath))
    26122644            LOG_ERROR("Error deleting blob file %s", fullPath.utf8().data());
     
    26172649
    26182650    SQLiteFileSystem::deleteDatabaseFile(dbFilename);
    2619     SQLiteFileSystem::deleteEmptyDatabaseDirectory(fullDatabaseDirectory());
    2620     SQLiteFileSystem::deleteEmptyDatabaseDirectory(m_absoluteDatabaseDirectory);
     2651    SQLiteFileSystem::deleteEmptyDatabaseDirectory(m_databaseDirectory);
     2652    SQLiteFileSystem::deleteEmptyDatabaseDirectory(m_identifier.databaseDirectoryRelativeToRoot(m_databaseRootDirectory));
    26212653}
    26222654
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h

    r242911 r243019  
    9090    void unregisterCursor(SQLiteIDBCursor&);
    9191
    92     String fullDatabaseDirectory() const;
    93 
    9492    IDBBackingStoreTemporaryFileHandler& temporaryFileHandler() const { return m_temporaryFileHandler; }
    9593
     
    9896    static String databaseNameFromEncodedFilename(const String&);
    9997    static uint64_t databasesSizeForFolder(const String& folder);
     98
     99    String databaseDirectory() const { return m_databaseDirectory; };
     100    static String fullDatabasePathForDirectory(const String&);
     101    static String databaseNameFromFile(const String&);
    100102
    101103private:
    102104    String filenameForDatabaseName() const;
    103105    String fullDatabasePath() const;
     106    String fullDatabaseDirectoryWithUpgrade();
    104107
    105108    uint64_t quotaForOrigin() const;
     
    197200    HashMap<IDBResourceIdentifier, SQLiteIDBCursor*> m_cursors;
    198201
    199     String m_absoluteDatabaseDirectory;
     202    String m_databaseRootDirectory;
     203    String m_databaseDirectory;
    200204
    201205    RefPtr<JSC::VM> m_vm;
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBTransaction.cpp

    r240437 r243019  
    8888void SQLiteIDBTransaction::moveBlobFilesIfNecessary()
    8989{
    90     String databaseDirectory = m_backingStore.fullDatabaseDirectory();
     90    String databaseDirectory = m_backingStore.databaseDirectory();
    9191    for (auto& entry : m_blobTemporaryAndStoredFilenames) {
    9292        if (!FileSystem::hardLinkOrCopyFile(entry.first, FileSystem::pathByAppendingComponent(databaseDirectory, entry.second)))
     
    104104        return;
    105105
    106     String databaseDirectory = m_backingStore.fullDatabaseDirectory();
     106    String databaseDirectory = m_backingStore.databaseDirectory();
    107107    for (auto& entry : m_blobRemovedFilenames) {
    108108        String fullPath = FileSystem::pathByAppendingComponent(databaseDirectory, entry);
  • trunk/Source/WebCore/platform/sql/SQLiteFileSystem.cpp

    r242251 r243019  
    3434#include "SQLiteDatabase.h"
    3535#include "SQLiteStatement.h"
     36#include <pal/crypto/CryptoDigest.h>
    3637#include <sqlite3.h>
    3738#include <wtf/FileSystem.h>
     
    113114    return FileSystem::getFileModificationTime(fileName);
    114115}
     116   
     117String SQLiteFileSystem::computeHashForFileName(const String& fileName)
     118{
     119    auto cryptoDigest = PAL::CryptoDigest::create(PAL::CryptoDigest::Algorithm::SHA_256);
     120    cryptoDigest->addBytes(fileName.utf8().data(), fileName.utf8().length());
     121    auto digest = cryptoDigest->computeHash();
     122   
     123    // Convert digest to hex.
     124    char* start = 0;
     125    unsigned digestLength = digest.size();
     126    CString result = CString::newUninitialized(digestLength * 2, start);
     127    char* buffer = start;
     128    for (size_t i = 0; i < digestLength; ++i) {
     129        snprintf(buffer, 3, "%02X", digest.at(i));
     130        buffer += 2;
     131    }
     132    return String::fromUTF8(result);
     133}
    115134
    116135} // namespace WebCore
  • trunk/Source/WebCore/platform/sql/SQLiteFileSystem.h

    r242251 r243019  
    8181    WEBCORE_EXPORT static bool deleteDatabaseFile(const String& fileName);
    8282
     83    WEBCORE_EXPORT static String computeHashForFileName(const String& fileName);
     84
    8385#if PLATFORM(IOS_FAMILY)
    8486    // Truncates a database file. Used when MobileSafariSettings deletes a database file,
  • trunk/Source/WebKit/ChangeLog

    r243018 r243019  
     12019-03-15  Sihui Liu  <sihui_liu@apple.com>
     2
     3        [ Mojave WK1 ] Layout Test storage/indexeddb/database-odd-names.html is failing
     4        https://bugs.webkit.org/show_bug.cgi?id=190350
     5        <rdar://problem/45089503>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        * NetworkProcess/NetworkProcess.cpp:
     10        (WebKit::NetworkProcess::collectIndexedDatabaseOriginsForVersion):
     11        (WebKit::NetworkProcess::indexedDatabaseOrigins):
     12        * NetworkProcess/NetworkProcess.h:
     13        * UIProcess/Network/NetworkProcessProxy.cpp:
     14        (WebKit::NetworkProcessProxy::addSession):
     15        (WebKit::NetworkProcessProxy::createSymLinkForFileUpgrade): For efficientcy and atomicity, we choose to use
     16        symlink to create v0 folder. Because network process does not have the permission to create a symlink, we need
     17        to do this in UI process. UI process would create v0 folder inside the IndexedDB directory if there isn't one.
     18        Also if there is a v0 directory but it doesn't have content, it means it's not a correct symlink and we need to
     19        delete it and create again.
     20
     21        * UIProcess/Network/NetworkProcessProxy.h:
     22        * UIProcess/WebProcessPool.cpp:
     23        (WebKit::WebProcessPool::ensureNetworkProcess):
     24
     252019-03-15  Sihui Liu  <sihui_liu@apple.com>
     26
     27        [ Mojave WK1 ] Layout Test storage/indexeddb/database-odd-names.html is failing
     28        https://bugs.webkit.org/show_bug.cgi?id=190350
     29        <rdar://problem/45089503>
     30
     31        Reviewed by Geoffrey Garen.
     32
     33        * NetworkProcess/NetworkProcess.cpp:
     34        (WebKit::NetworkProcess::collectIndexedDatabaseOriginsForVersion):
     35        (WebKit::NetworkProcess::indexedDatabaseOrigins):
     36        * NetworkProcess/NetworkProcess.h:
     37        * UIProcess/Network/NetworkProcessProxy.cpp:
     38        (WebKit::NetworkProcessProxy::addSession):
     39        (WebKit::NetworkProcessProxy::createSymLinkForFileUpgrade):
     40        * UIProcess/Network/NetworkProcessProxy.h:
     41        * UIProcess/WebProcessPool.cpp:
     42        (WebKit::WebProcessPool::ensureNetworkProcess):
     43
    1442019-03-15  Per Arne Vollan  <pvollan@apple.com>
    245
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r242975 r243019  
    21222122}
    21232123
     2124void NetworkProcess::collectIndexedDatabaseOriginsForVersion(const String& path, HashSet<WebCore::SecurityOriginData>& securityOrigins)
     2125{
     2126    if (path.isEmpty())
     2127        return;
     2128
     2129    for (auto& topOriginPath : FileSystem::listDirectory(path, "*")) {
     2130        auto databaseIdentifier = FileSystem::pathGetFileName(topOriginPath);
     2131        if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier)) {
     2132            securityOrigins.add(WTFMove(*securityOrigin));
     2133       
     2134            for (auto& originPath : FileSystem::listDirectory(topOriginPath, "*")) {
     2135                databaseIdentifier = FileSystem::pathGetFileName(originPath);
     2136                if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
     2137                    securityOrigins.add(WTFMove(*securityOrigin));
     2138            }
     2139        }
     2140    }
     2141}
     2142
    21242143HashSet<WebCore::SecurityOriginData> NetworkProcess::indexedDatabaseOrigins(const String& path)
    21252144{
     
    21282147   
    21292148    HashSet<WebCore::SecurityOriginData> securityOrigins;
    2130     for (auto& topOriginPath : FileSystem::listDirectory(path, "*")) {
    2131         auto databaseIdentifier = FileSystem::pathGetFileName(topOriginPath);
    2132         if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
    2133             securityOrigins.add(WTFMove(*securityOrigin));
    2134        
    2135         for (auto& originPath : FileSystem::listDirectory(topOriginPath, "*")) {
    2136             databaseIdentifier = FileSystem::pathGetFileName(originPath);
    2137             if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
    2138                 securityOrigins.add(WTFMove(*securityOrigin));
    2139         }
    2140     }
     2149    collectIndexedDatabaseOriginsForVersion(FileSystem::pathByAppendingComponent(path, "v0"), securityOrigins);
     2150    collectIndexedDatabaseOriginsForVersion(FileSystem::pathByAppendingComponent(path, "v1"), securityOrigins);
    21412151
    21422152    return securityOrigins;
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r242947 r243019  
    430430#if ENABLE(INDEXED_DATABASE)
    431431    void addIndexedDatabaseSession(PAL::SessionID, String&, SandboxExtension::Handle&);
     432    void collectIndexedDatabaseOriginsForVersion(const String&, HashSet<WebCore::SecurityOriginData>&);
    432433    HashSet<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
    433434    Ref<WebCore::IDBServer::IDBServer> createIDBServer(PAL::SessionID);
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r242905 r243019  
    10641064        send(Messages::NetworkProcess::AddWebsiteDataStore { store->parameters() }, 0);
    10651065    auto sessionID = store->sessionID();
    1066     if (!sessionID.isEphemeral())
     1066    if (!sessionID.isEphemeral()) {
     1067#if ENABLE(INDEXED_DATABASE)
     1068        createSymLinkForFileUpgrade(store->resolvedIndexedDatabaseDirectory());
     1069#endif
    10671070        m_websiteDataStores.set(sessionID, WTFMove(store));
     1071    }
    10681072}
    10691073
     
    12141218}
    12151219
     1220#if ENABLE(INDEXED_DATABASE)
     1221void NetworkProcessProxy::createSymLinkForFileUpgrade(const String& indexedDatabaseDirectory)
     1222{
     1223    if (indexedDatabaseDirectory.isEmpty())
     1224        return;
     1225
     1226    String oldVersionDirectory = FileSystem::pathByAppendingComponent(indexedDatabaseDirectory, "v0");
     1227    FileSystem::deleteEmptyDirectory(oldVersionDirectory);
     1228    if (!FileSystem::fileExists(oldVersionDirectory))
     1229        FileSystem::createSymbolicLink(indexedDatabaseDirectory, oldVersionDirectory);
     1230}
     1231#endif
     1232
    12161233} // namespace WebKit
    12171234
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r242905 r243019  
    177177    void takeUploadAssertion();
    178178    void clearUploadAssertion();
     179   
     180#if ENABLE(INDEXED_DATABASE)
     181    void createSymLinkForFileUpgrade(const String& indexedDatabaseDirectory);
     182#endif
    179183
    180184private:
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r243009 r243019  
    552552   
    553553    SandboxExtension::createHandleForReadWriteDirectory(parameters.defaultDataStoreParameters.indexedDatabaseDirectory, parameters.defaultDataStoreParameters.indexedDatabaseDirectoryExtensionHandle);
     554    m_networkProcess->createSymLinkForFileUpgrade(parameters.defaultDataStoreParameters.indexedDatabaseDirectory);
    554555#endif
    555556
  • trunk/Tools/ChangeLog

    r243012 r243019  
     12019-03-15  Sihui Liu  <sihui_liu@apple.com>
     2
     3        [ Mojave WK1 ] Layout Test storage/indexeddb/database-odd-names.html is failing
     4        https://bugs.webkit.org/show_bug.cgi?id=190350
     5        <rdar://problem/45089503>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKitCocoa/IDBIndexUpgradeToV2.mm:
     11        (TEST):
     12        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3:
     13        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-shm:
     14        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDB.sqlite3-wal:
     15        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName-1.html: Added.
     16        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName-2.html: Added.
     17        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDBFileName.mm: Added.
     18        (-[IndexedDBFileNameMessageHandler userContentController:didReceiveScriptMessage:]):
     19        (runTest):
     20        (createDirectories):
     21        (TEST):
     22        * TestWebKitAPI/Tests/WebKitCocoa/IndexedDBTempFileSize.mm:
     23        (TEST):
     24        * TestWebKitAPI/Tests/WebKitCocoa/StoreBlobThenDelete.mm:
     25        (TEST):
     26
    1272019-03-15  Timothy Hatcher  <timothy@apple.com>
    228
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r242932 r243019  
    775775                CA97B394219366600045DF6F /* IndexedDBUserDelete.mm in Sources */ = {isa = PBXBuildFile; fileRef = CA97B3922193663B0045DF6F /* IndexedDBUserDelete.mm */; };
    776776                CA97B3952193667A0045DF6F /* IndexedDBUserDelete.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CA97B393219366470045DF6F /* IndexedDBUserDelete.html */; };
     777                CAB0FF5222332407006CA5B0 /* IndexedDBFileName-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CAB0FF51223323F6006CA5B0 /* IndexedDBFileName-1.html */; };
     778                CAB0FF5322332407006CA5B0 /* IndexedDBFileName-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CAB0FF50223323F6006CA5B0 /* IndexedDBFileName-2.html */; };
     779                CAB0FF5522332C57006CA5B0 /* IndexedDBFileName.mm in Sources */ = {isa = PBXBuildFile; fileRef = CAB0FF5422332C3A006CA5B0 /* IndexedDBFileName.mm */; };
    777780                CD0BD0A61F79924D001AB2CF /* ContextMenuImgWithVideo.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD0BD0A51F799220001AB2CF /* ContextMenuImgWithVideo.mm */; };
    778781                CD0BD0A81F79982D001AB2CF /* ContextMenuImgWithVideo.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD0BD0A71F7997C2001AB2CF /* ContextMenuImgWithVideo.html */; };
     
    11441147                                935786CC20F6A2700000CDFC /* IndexedDB.sqlite3-wal in Copy Resources */,
    11451148                                51A587851D2739E3004BA9AF /* IndexedDBDatabaseProcessKill-1.html in Copy Resources */,
     1149                                CAB0FF5222332407006CA5B0 /* IndexedDBFileName-1.html in Copy Resources */,
     1150                                CAB0FF5322332407006CA5B0 /* IndexedDBFileName-2.html in Copy Resources */,
    11461151                                51BCEE4E1C84F53B0042C82E /* IndexedDBMultiProcess-1.html in Copy Resources */,
    11471152                                51BCEE4F1C84F53B0042C82E /* IndexedDBMultiProcess-2.html in Copy Resources */,
     
    20982103                CA97B3922193663B0045DF6F /* IndexedDBUserDelete.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IndexedDBUserDelete.mm; sourceTree = "<group>"; };
    20992104                CA97B393219366470045DF6F /* IndexedDBUserDelete.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = IndexedDBUserDelete.html; sourceTree = "<group>"; };
     2105                CAB0FF50223323F6006CA5B0 /* IndexedDBFileName-2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "IndexedDBFileName-2.html"; sourceTree = "<group>"; };
     2106                CAB0FF51223323F6006CA5B0 /* IndexedDBFileName-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "IndexedDBFileName-1.html"; sourceTree = "<group>"; };
     2107                CAB0FF5422332C3A006CA5B0 /* IndexedDBFileName.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IndexedDBFileName.mm; sourceTree = "<group>"; };
    21002108                CD0BD0A51F799220001AB2CF /* ContextMenuImgWithVideo.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuImgWithVideo.mm; sourceTree = "<group>"; };
    21012109                CD0BD0A71F7997C2001AB2CF /* ContextMenuImgWithVideo.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = ContextMenuImgWithVideo.html; sourceTree = "<group>"; };
     
    25332541                                5110FCEF1E01CBAA006F8D0B /* IDBIndexUpgradeToV2.mm */,
    25342542                                51A587841D272EF3004BA9AF /* IndexedDBDatabaseProcessKill.mm */,
     2543                                CAB0FF5422332C3A006CA5B0 /* IndexedDBFileName.mm */,
    25352544                                51BCEE491C84F4AF0042C82E /* IndexedDBMultiProcess.mm */,
    25362545                                51B1EE8D1C80F5880064FB98 /* IndexedDBPersistence.mm */,
     
    29232932                                934FA5C520F69FED0040DC1B /* IndexedDB.sqlite3-wal */,
    29242933                                51A587821D272EB5004BA9AF /* IndexedDBDatabaseProcessKill-1.html */,
     2934                                CAB0FF51223323F6006CA5B0 /* IndexedDBFileName-1.html */,
     2935                                CAB0FF50223323F6006CA5B0 /* IndexedDBFileName-2.html */,
    29252936                                51BCEE4C1C84F52C0042C82E /* IndexedDBMultiProcess-1.html */,
    29262937                                51BCEE4D1C84F52C0042C82E /* IndexedDBMultiProcess-2.html */,
     
    41074118                                5110FCFA1E01CDB8006F8D0B /* IDBIndexUpgradeToV2.mm in Sources */,
    41084119                                51A587861D273AA9004BA9AF /* IndexedDBDatabaseProcessKill.mm in Sources */,
     4120                                CAB0FF5522332C57006CA5B0 /* IndexedDBFileName.mm in Sources */,
    41094121                                7C83E0BE1D0A651300FEBCF3 /* IndexedDBMultiProcess.mm in Sources */,
    41104122                                7C83E0BF1D0A652200FEBCF3 /* IndexedDBPersistence.mm in Sources */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IDBIndexUpgradeToV2.mm

    r242339 r243019  
    2828#import "PlatformUtilities.h"
    2929#import "Test.h"
     30#import <WebCore/SQLiteFileSystem.h>
    3031#import <WebKit/WKProcessPoolPrivate.h>
    3132#import <WebKit/WKUserContentControllerPrivate.h>
     
    6465    NSURL *url2 = [[NSBundle mainBundle] URLForResource:@"IndexUpgrade" withExtension:@"blob" subdirectory:@"TestWebKitAPI.resources"];
    6566
    66     NSURL *targetURL = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/index-upgrade-test" stringByExpandingTildeInPath]];
     67    NSString *hash = WebCore::SQLiteFileSystem::computeHashForFileName("index-upgrade-test");
     68    NSString *originDirectory = @"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/v1/file__0/";
     69    NSString *databaseDirectory = [[originDirectory stringByAppendingString:hash] stringByExpandingTildeInPath];
     70    NSURL *targetURL = [NSURL fileURLWithPath:databaseDirectory];
    6771    [[NSFileManager defaultManager] removeItemAtURL:targetURL error:nil];
    6872    [[NSFileManager defaultManager] createDirectoryAtURL:targetURL withIntermediateDirectories:YES attributes:nil error:nil];
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IndexedDBTempFileSize.mm

    r242339 r243019  
    2828#import "PlatformUtilities.h"
    2929#import "Test.h"
     30#import <WebCore/SQLiteFileSystem.h>
    3031#import <WebKit/WKProcessPoolPrivate.h>
    3132#import <WebKit/WKUserContentControllerPrivate.h>
     
    6263    [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
    6364
    64     RetainPtr<NSURL> idbPath = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/CustomWebsiteData/IndexedDB/" stringByExpandingTildeInPath] isDirectory:YES];
    65     RetainPtr<NSURL> walFilePath = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/CustomWebsiteData/IndexedDB/file__0/IndexedDBTempFileSize/IndexedDB.sqlite3-wal" stringByExpandingTildeInPath] isDirectory:NO];
     65    NSString *hash = WebCore::SQLiteFileSystem::computeHashForFileName("IndexedDBTempFileSize");
     66    NSString *databaseRootDirectory = [@"~/Library/WebKit/TestWebKitAPI/CustomWebsiteData/IndexedDB/" stringByExpandingTildeInPath];
     67    NSString *databaseDirectory = [[[databaseRootDirectory stringByAppendingPathComponent:@"v1"] stringByAppendingPathComponent:@"file__0"] stringByAppendingPathComponent:hash];
     68    RetainPtr<NSURL> idbPath = [NSURL fileURLWithPath:databaseRootDirectory isDirectory:YES];
     69    RetainPtr<NSURL> walFilePath = [NSURL fileURLWithPath:[databaseDirectory stringByAppendingPathComponent:@"IndexedDB.sqlite3-wal"] isDirectory:NO];
    6670
    6771    auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/StoreBlobThenDelete.mm

    r242339 r243019  
    2828#import "PlatformUtilities.h"
    2929#import "Test.h"
     30#import <WebCore/SQLiteFileSystem.h>
    3031#import <WebKit/WebKit.h>
    3132#import <WebKit/WKProcessPoolPrivate.h>
     
    6667    EXPECT_WK_STREQ(@"Success", (NSString *)[lastScriptMessage body]);
    6768
    68     NSString *blobFilePath = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/1.blob" stringByExpandingTildeInPath];
    69     NSString *databaseFilePath = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/IndexedDB.sqlite3" stringByExpandingTildeInPath];
     69    NSString *hash = WebCore::SQLiteFileSystem::computeHashForFileName("StoreBlobToBeDeleted");
     70    NSString *originDirectory = @"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/v1/file__0/";
     71    NSString *databaseDirectory = [[originDirectory stringByAppendingString:hash] stringByExpandingTildeInPath];
     72    NSString *blobFilePath = [databaseDirectory stringByAppendingPathComponent:@"1.blob"];
     73    NSString *databaseFilePath = [databaseDirectory stringByAppendingPathComponent:@"IndexedDB.sqlite3"];
    7074
    7175    // The database file and blob file should definitely be there right now.
     
    7882    // 2 - Move -wal and -shm files into that directory
    7983    // 3 - Make sure the entire directory is deleted
    80     NSString *fakeDatabasePath = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/FakeDatabasePath" stringByExpandingTildeInPath];
    81     NSString *fakeShmPath = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/FakeDatabasePath/IndexedDB.sqlite3-wal" stringByExpandingTildeInPath];
    82     NSString *fakeWalPath = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/FakeDatabasePath/IndexedDB.sqlite3-shm" stringByExpandingTildeInPath];
    83     [[NSFileManager defaultManager] createDirectoryAtPath:fakeDatabasePath withIntermediateDirectories:NO attributes:nil error:nil];
     84    NSString *fakeHash = WebCore::SQLiteFileSystem::computeHashForFileName("FakeDatabasePath");
     85    NSString *fakeDatabaseDirectory = [[originDirectory stringByAppendingString:fakeHash] stringByExpandingTildeInPath];
     86    NSString *fakeShmPath = [fakeDatabaseDirectory stringByAppendingPathComponent:@"IndexedDB.sqlite3-wal"];
     87    NSString *fakeWalPath = [fakeDatabaseDirectory stringByAppendingPathComponent:@"IndexedDB.sqlite3-shm"];
     88    [[NSFileManager defaultManager] createDirectoryAtPath:fakeDatabaseDirectory withIntermediateDirectories:NO attributes:nil error:nil];
    8489    [[NSFileManager defaultManager] copyItemAtPath:databaseFilePath toPath:fakeShmPath error:nil];
    8590    [[NSFileManager defaultManager] copyItemAtPath:databaseFilePath toPath:fakeWalPath error:nil];
    8691
    8792    // Make some other .blob files in the database directory to later validate that only appropriate files are deleted.
    88     NSString *otherBlob1 = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/7182.blob" stringByExpandingTildeInPath];
    89     NSString *otherBlob2 = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/1a.blob" stringByExpandingTildeInPath];
    90     NSString *otherBlob3 = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/a1.blob" stringByExpandingTildeInPath];
    91     NSString *otherBlob4 = [@"~/Library/WebKit/TestWebKitAPI/WebsiteData/IndexedDB/file__0/StoreBlobToBeDeleted/.blob" stringByExpandingTildeInPath];
     93    NSString *otherBlob1 = [databaseDirectory stringByAppendingPathComponent:@"7182.blob"];
     94    NSString *otherBlob2 = [databaseDirectory stringByAppendingPathComponent:@"1a.blob"];
     95    NSString *otherBlob3 = [databaseDirectory stringByAppendingPathComponent:@"a1.blob"];
     96    NSString *otherBlob4 = [databaseDirectory stringByAppendingPathComponent:@".blob"];
    9297    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:otherBlob1 error:nil];
    9398    [[NSFileManager defaultManager] copyItemAtPath:blobFilePath toPath:otherBlob2 error:nil];
     
    111116        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeShmPath]);
    112117        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeWalPath]);
    113         EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeDatabasePath]);
     118        EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:fakeDatabaseDirectory]);
    114119
    115120        // Now delete them so we're not leaving files around.
Note: See TracChangeset for help on using the changeset viewer.