Changeset 290239 in webkit


Ignore:
Timestamp:
Feb 21, 2022 1:23:39 AM (5 months ago)
Author:
sihui_liu@apple.com
Message:

Fetching website data may get wrong record after migrating data to general storage directory
https://bugs.webkit.org/show_bug.cgi?id=236905

Reviewed by Chris Dumez.

Source/WebKit:

To decide if an origin has data, we need to not only check if its directory exists but also if the directory is
empty.

Modified existing test to add test coverage.

  • NetworkProcess/storage/OriginStorageManager.cpp:

(WebKit::OriginStorageManager::StorageBucket::resolvedLocalStoragePath):
(WebKit::OriginStorageManager::StorageBucket::resolvedIDBStoragePath): directory should be created before moving
files.
(WebKit::OriginStorageManager::StorageBucket::fetchDataTypesInListFromDisk): given that IndexedDB and
LocalStorage can have custom paths, we may just check data by type.

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:

(TEST):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r290237 r290239  
     12022-02-21  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Fetching website data may get wrong record after migrating data to general storage directory
     4        https://bugs.webkit.org/show_bug.cgi?id=236905
     5
     6        Reviewed by Chris Dumez.
     7
     8        To decide if an origin has data, we need to not only check if its directory exists but also if the directory is
     9        empty.
     10
     11        Modified existing test to add test coverage.
     12
     13        * NetworkProcess/storage/OriginStorageManager.cpp:
     14        (WebKit::OriginStorageManager::StorageBucket::resolvedLocalStoragePath):
     15        (WebKit::OriginStorageManager::StorageBucket::resolvedIDBStoragePath): directory should be created before moving
     16        files.
     17        (WebKit::OriginStorageManager::StorageBucket::fetchDataTypesInListFromDisk): given that IndexedDB and
     18        LocalStorage can have custom paths, we may just check data by type.
     19
    1202022-02-19  Jon Lee  <jonlee@apple.com>
    221
  • trunk/Source/WebKit/NetworkProcess/storage/OriginStorageManager.cpp

    r290115 r290239  
    259259
    260260            auto localStoragePath = LocalStorageManager::localStorageFilePath(localStorageDirectory);
    261             if (!m_customLocalStoragePath.isEmpty() && !FileSystem::fileExists(localStoragePath))
     261            if (!m_customLocalStoragePath.isEmpty() && !FileSystem::fileExists(localStoragePath) && FileSystem::fileExists(m_customLocalStoragePath))
    262262                WebCore::SQLiteFileSystem::moveDatabaseFile(m_customLocalStoragePath, localStoragePath);
    263263
     
    281281        } else {
    282282            auto idbStoragePath = typeStoragePath(StorageType::IndexedDB);
    283             if (!m_customIDBStoragePath.isEmpty() && !FileSystem::fileExists(idbStoragePath)) {
     283            if (!m_customIDBStoragePath.isEmpty() && !FileSystem::fileExists(idbStoragePath) && FileSystem::fileExists(m_customIDBStoragePath)) {
     284                FileSystem::makeAllDirectories(idbStoragePath);
    284285                FileSystem::moveFile(m_customIDBStoragePath, idbStoragePath);
    285                 FileSystem::makeAllDirectories(idbStoragePath);
    286286            }
    287287
     
    318318    {
    319319        OptionSet<WebsiteDataType> result;
    320         for (auto& storageType : FileSystem::listDirectory(m_rootPath)) {
    321             if (auto type = toWebsiteDataType(storageType); type && types.contains(*type))
    322                 result.add(*type);
    323         }
    324 
    325         if (types.contains(WebsiteDataType::LocalStorage) && !result.contains(WebsiteDataType::LocalStorage)) {
     320        if (types.contains(WebsiteDataType::FileSystem)) {
     321            auto fileSystemStoragePath = typeStoragePath(StorageType::FileSystem);
     322            if (auto files = FileSystem::listDirectory(fileSystemStoragePath); !files.isEmpty())
     323                result.add(WebsiteDataType::FileSystem);
     324        }
     325
     326        if (types.contains(WebsiteDataType::LocalStorage)) {
    326327            if (FileSystem::fileExists(resolvedLocalStoragePath()))
    327328                result.add(WebsiteDataType::LocalStorage);
    328329        }
    329330
    330         if (types.contains(WebsiteDataType::IndexedDBDatabases) && !result.contains(WebsiteDataType::IndexedDBDatabases)) {
     331        if (types.contains(WebsiteDataType::IndexedDBDatabases)) {
    331332            if (auto databases = FileSystem::listDirectory(resolvedIDBStoragePath()); !databases.isEmpty())
    332333                result.add(WebsiteDataType::IndexedDBDatabases);
  • trunk/Tools/ChangeLog

    r290233 r290239  
     12022-02-21  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Fetching website data may get wrong record after migrating data to general storage directory
     4        https://bugs.webkit.org/show_bug.cgi?id=236905
     5
     6        Reviewed by Chris Dumez.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:
     9        (TEST):
     10
    1112022-02-20  Sihui Liu  <sihui_liu@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm

    r290233 r290239  
    10831083    EXPECT_FALSE([fileManager fileExistsAtPath:appleGeneralLocalStorageFile.path]);
    10841084    EXPECT_FALSE([fileManager fileExistsAtPath:appleGeneralIndexedDBDatabaseFile.path]);
    1085 }
     1085
     1086    // Ensure data records do not exist after deletion.
     1087    done = false;
     1088    [websiteDataStore fetchDataRecordsOfTypes:dataTypes completionHandler:^(NSArray<WKWebsiteDataRecord *> *records) {
     1089        EXPECT_EQ(records.count, 0u);
     1090        done = true;
     1091    }];
     1092    TestWebKitAPI::Util::run(&done);
     1093}
Note: See TracChangeset for help on using the changeset viewer.