⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 277357 in webkit


Ignore:
Timestamp:
May 11, 2021, 10:55:23 PM (5 years ago)
Author:
Chris Dumez
Message:

Port WTF::FileSystem::listDirectory to std::filesystem
https://bugs.webkit.org/show_bug.cgi?id=225633

Reviewed by Darin Adler.

Source/WebCore:

Update FileSystem::listDirectory() call sites to deal with the fact that:

  • The function now returns file names instead of full file paths
  • The callers now have to do filtering by themselves if they need it
  • Modules/entriesapi/DOMFileSystem.cpp:

(WebCore::listDirectoryWithMetadata):

  • Modules/indexeddb/server/IDBServer.cpp:

(WebCore::IDBServer::IDBServer::getAllDatabaseNamesAndVersions):
(WebCore::IDBServer::collectOriginsForVersion):
(WebCore::IDBServer::removeAllDatabasesForFullOriginPath):
(WebCore::IDBServer::removeAllDatabasesForOriginPath):
(WebCore::IDBServer::IDBServer::removeDatabasesModifiedSinceForVersion):
(WebCore::IDBServer::IDBServer::removeDatabasesWithOriginsForVersion):

  • Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:

(WebCore::IDBServer::SQLiteIDBBackingStore::fullDatabaseDirectoryWithUpgrade):
(WebCore::IDBServer::SQLiteIDBBackingStore::databasesSizeForDirectory):

  • Modules/webdatabase/DatabaseTracker.cpp:

(WebCore::DatabaseTracker::usage):
(WebCore::DatabaseTracker::deleteOrigin):

  • html/DirectoryFileListCreator.cpp:

(WebCore::appendDirectoryFiles):

  • platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:

(WebCore::MediaPlayerPrivateGStreamer::uriDecodeBinElementAddedCallback):
(WebCore::MediaPlayerPrivateGStreamer::purgeOldDownloadFiles):

  • platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:
  • platform/text/hyphen/HyphenationLibHyphen.cpp:

(WebCore::extractLocaleFromDictionaryFileName):
(WebCore::scanDirectoryForDictionaries):

Source/WebKit:

Update FileSystem::listDirectory() call sites to deal with the fact that:

  • The function now returns file names instead of full file paths
  • The callers now have to do filtering by themselves if they need it
  • NetworkProcess/WebStorage/LocalStorageDatabaseTracker.cpp:

(WebKit::LocalStorageDatabaseTracker::origins const):

  • NetworkProcess/cache/CacheStorageEngine.cpp:

(WebKit::CacheStorage::getDirectorySize):
(WebKit::CacheStorage::Engine::getDirectories):
(WebKit::CacheStorage::Engine::clearAllCachesFromDisk):

  • NetworkProcess/cache/NetworkCacheFileSystem.cpp:

(WebKit::NetworkCache::traverseDirectory):

  • UIProcess/API/APIContentRuleListStore.cpp:

(API::ContentRuleListStore::getAvailableContentRuleListIdentifiers):
(API::ContentRuleListStore::synchronousRemoveAllContentRuleLists):

  • UIProcess/DeviceIdHashSaltStorage.cpp:

(WebKit::DeviceIdHashSaltStorage::loadStorageFromDisk):

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::mediaKeyOrigins):
(WebKit::WebsiteDataStore::removeMediaKeys):

  • WebProcess/InjectedBundle/API/glib/WebKitExtensionManager.cpp:

(WebKit::WebKitExtensionManager::scanModules):

  • WebProcess/MediaCache/WebMediaKeyStorageManager.cpp:

(WebKit::WebMediaKeyStorageManager::getMediaKeyOrigins):
(WebKit::removeAllMediaKeyStorageForOriginPath):
(WebKit::WebMediaKeyStorageManager::deleteMediaKeyEntriesModifiedBetweenDates):
(WebKit::WebMediaKeyStorageManager::deleteAllMediaKeyEntries):

Source/WebKitLegacy:

Update FileSystem::listDirectory() call sites to deal with the fact that:

  • The function now returns file names instead of full file paths
  • The callers now have to do filtering by themselves if they need it
  • Storage/StorageTracker.cpp:

(WebKit::StorageTracker::syncFileSystemAndTrackerDatabase):

Source/WebKitLegacy/win:

Update FileSystem::listDirectory() call sites to deal with the fact that:

  • The function now returns file names instead of full file paths
  • The callers now have to do filtering by themselves if they need it
  • Plugins/PluginDatabase.cpp:

(WebCore::PluginDatabase::getPluginPathsInDirectories const):

Source/WTF:

Port WTF::FileSystem::listDirectory to std::filesystem with the following 2 changes:

  • The function no longer takes a (blob-style) filter parameter
  • The function now returns file names instead of file paths, allowing the call sites to more easily filter based on prefixes.
  • wtf/FileSystem.cpp:

(WTF::FileSystemImpl::listDirectory):

  • wtf/FileSystem.h:
  • wtf/glib/FileSystemGlib.cpp:
  • wtf/posix/FileSystemPOSIX.cpp:
  • wtf/win/FileSystemWin.cpp:

Tools:

Add API test coverage.

  • TestWebKitAPI/Tests/WTF/FileSystem.cpp:

(TestWebKitAPI::createTestFile):
(TestWebKitAPI::TEST_F):

  • TestWebKitAPI/Tests/WebCore/cocoa/DatabaseTrackerTest.mm:

(TestWebKitAPI::removeDirectoryAndAllContents):

Location:
trunk
Files:
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/Configurations/JavaScriptCore.xcconfig

    r277231 r277357  
    2828
    2929// Prevent C++ standard library operator new, delete and their related exception types from being exported as weak symbols.
    30 OTHER_LDFLAGS_HIDE_SYMBOLS = -Wl,-unexported_symbol,__ZTISt9bad_alloc -Wl,-unexported_symbol,__ZTISt9exception -Wl,-unexported_symbol,__ZTSSt9bad_alloc -Wl,-unexported_symbol,__ZTSSt9exception -Wl,-unexported_symbol,__ZdlPvS_ -Wl,-unexported_symbol,__ZnwmPv -Wl,-unexported_symbol,__ZNKSt3__18functionIFvvEEclEv -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEEC1EOS2_ -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEEC2EOS2_ -Wl,-unexported_symbol,__ZNKSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEEclES3_S5_ -Wl,-unexported_symbol,__ZNSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEED1Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEED2Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEED1Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEED2Ev -Wl,-unexported_symbol,__ZTVNSt3__117bad_function_callE -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE11__range_endES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE13__range_beginES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE14__append_rangeIPKcEENS_9enable_ifIXsr27__is_cpp17_forward_iteratorIT_EE5valueEvE4typeERNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEES8_S8_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE15__append_sourceIPKcEEvRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERKT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE14__append_rangeIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeERNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEES8_S8_ -Wl,-unexported_symbol,__ZNKSt3__14__fs10filesystem18directory_iteratordeEv -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem18directory_iteratorppEv -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIA10_cPccLb1EE11__range_endEPKc -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIA10_cPccLb1EE13__range_beginEPKc -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem4pathdVERKS2_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE15__append_sourceIA10_cEEvRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERKT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__throw_filesystem_errorIJRPKcRKNS1_4pathERKNS_10error_codeEEEEvDpOT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem14__is_separatorIcEENS_9enable_ifIXsr18__can_convert_charIT_EE5valueEbE4typeES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE15__first_or_nullES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem4path20__source_is_absoluteIcEEbT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem4path6appendIPKcEENS_9enable_ifIXsr13__is_pathableIT_EE5valueERS2_E4typeERKS7_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem6u8pathIPKcEENS_9enable_ifIXsr13__is_pathableIT_EE5valueENS1_4pathEE4typeERKS6_;
     30OTHER_LDFLAGS_HIDE_SYMBOLS = -Wl,-unexported_symbol,__ZTISt9bad_alloc -Wl,-unexported_symbol,__ZTISt9exception -Wl,-unexported_symbol,__ZTSSt9bad_alloc -Wl,-unexported_symbol,__ZTSSt9exception -Wl,-unexported_symbol,__ZdlPvS_ -Wl,-unexported_symbol,__ZnwmPv -Wl,-unexported_symbol,__ZNKSt3__18functionIFvvEEclEv -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEEC1EOS2_ -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEEC2EOS2_ -Wl,-unexported_symbol,__ZNKSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEEclES3_S5_ -Wl,-unexported_symbol,__ZNSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEED1Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvRN3JSC17BytecodeGeneratorEPNS1_10RegisterIDEEED2Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEED1Ev -Wl,-unexported_symbol,__ZNSt3__18functionIFvvEED2Ev -Wl,-unexported_symbol,__ZTVNSt3__117bad_function_callE -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE11__range_endES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE13__range_beginES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE14__append_rangeIPKcEENS_9enable_ifIXsr27__is_cpp17_forward_iteratorIT_EE5valueEvE4typeERNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEES8_S8_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE15__append_sourceIPKcEEvRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERKT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE14__append_rangeIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeERNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEES8_S8_ -Wl,-unexported_symbol,__ZNKSt3__14__fs10filesystem18directory_iteratordeEv -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem18directory_iteratorppEv -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIA10_cPccLb1EE11__range_endEPKc -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIA10_cPccLb1EE13__range_beginEPKc -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem4pathdVERKS2_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem8_PathCVTIcE15__append_sourceIA10_cEEvRNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEERKT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__throw_filesystem_errorIJRPKcRKNS1_4pathERKNS_10error_codeEEEEvDpOT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem14__is_separatorIcEENS_9enable_ifIXsr18__can_convert_charIT_EE5valueEbE4typeES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem24__is_pathable_char_arrayIPKcS4_cLb1EE15__first_or_nullES4_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem4path20__source_is_absoluteIcEEbT_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem4path6appendIPKcEENS_9enable_ifIXsr13__is_pathableIT_EE5valueERS2_E4typeERKS7_ -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem6u8pathIPKcEENS_9enable_ifIXsr13__is_pathableIT_EE5valueENS1_4pathEE4typeERKS6_ -Wl,-unexported_symbol,__ZNKSt3__14__fs10filesystem18directory_iteratorptEv -Wl,-unexported_symbol,__ZNSt3__14__fs10filesystem18directory_iterator9incrementERNS_10error_codeE;
    3131
    3232OTHER_LDFLAGS_BASE = $(OTHER_LDFLAGS_HIDE_SYMBOLS) -force_load "$(BUILT_PRODUCTS_DIR)/DerivedSources/JavaScriptCore/libWTF.a";
  • trunk/Source/WTF/ChangeLog

    r277355 r277357  
     12021-05-11  Chris Dumez  <cdumez@apple.com>
     2
     3        Port WTF::FileSystem::listDirectory to std::filesystem
     4        https://bugs.webkit.org/show_bug.cgi?id=225633
     5
     6        Reviewed by Darin Adler.
     7
     8        Port WTF::FileSystem::listDirectory to std::filesystem with the following 2 changes:
     9        - The function no longer takes a (blob-style) filter parameter
     10        - The function now returns file names instead of file paths, allowing the call sites
     11          to more easily filter based on prefixes.
     12
     13        * wtf/FileSystem.cpp:
     14        (WTF::FileSystemImpl::listDirectory):
     15        * wtf/FileSystem.h:
     16        * wtf/glib/FileSystemGlib.cpp:
     17        * wtf/posix/FileSystemPOSIX.cpp:
     18        * wtf/win/FileSystemWin.cpp:
     19
    1202021-05-11  Darin Adler  <darin@apple.com>
    221
  • trunk/Source/WTF/wtf/FileSystem.cpp

    r277315 r277357  
    563563#if PLATFORM(MAC)
    564564    bool containsSingleDSStoreFile = false;
    565     for (auto& entry : std::filesystem::directory_iterator(fsPath, ec)) {
    566         if (entry.path().filename() == ".DS_Store")
     565    auto entries = std::filesystem::directory_iterator(fsPath, ec);
     566    for (auto it = std::filesystem::begin(entries), end = std::filesystem::end(entries); !ec && it != end; it.increment(ec)) {
     567        if (it->path().filename() == ".DS_Store")
    567568            containsSingleDSStoreFile = true;
    568569        else {
     
    753754}
    754755
     756Vector<String> listDirectory(const String& path)
     757{
     758    Vector<String> fileNames;
     759    std::error_code ec;
     760    auto entries = std::filesystem::directory_iterator(toStdFileSystemPath(path), ec);
     761    for (auto it = std::filesystem::begin(entries), end = std::filesystem::end(entries); !ec && it != end; it.increment(ec)) {
     762        auto fileName = fromStdFileSystemPath(it->path().filename());
     763        if (!fileName.isNull())
     764            fileNames.append(WTFMove(fileName));
     765    }
     766    return fileNames;
     767}
     768
    755769} // namespace FileSystemImpl
    756770} // namespace WTF
  • trunk/Source/WTF/wtf/FileSystem.h

    r276879 r277357  
    138138bool excludeFromBackup(const String&); // Returns true if successful.
    139139
    140 WTF_EXPORT_PRIVATE Vector<String> listDirectory(const String& path, const String& filter);
     140WTF_EXPORT_PRIVATE Vector<String> listDirectory(const String& path); // Returns file names, not full paths.
    141141
    142142WTF_EXPORT_PRIVATE CString fileSystemRepresentation(const String&);
  • trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp

    r277231 r277357  
    142142}
    143143
    144 Vector<String> listDirectory(const String& path, const String& filter)
    145 {
    146     Vector<String> entries;
    147 
    148     auto filename = fileSystemRepresentation(path);
    149     if (!validRepresentation(filename))
    150         return entries;
    151 
    152     GUniquePtr<GDir> dir(g_dir_open(filename.data(), 0, nullptr));
    153     if (!dir)
    154         return entries;
    155 
    156     GUniquePtr<GPatternSpec> pspec(g_pattern_spec_new((filter.utf8()).data()));
    157     while (const char* name = g_dir_read_name(dir.get())) {
    158         if (!g_pattern_match_string(pspec.get(), name))
    159             continue;
    160 
    161         GUniquePtr<gchar> entry(g_build_filename(filename.data(), name, nullptr));
    162         entries.append(stringFromFileSystemRepresentation(entry.get()));
    163     }
    164 
    165     return entries;
    166 }
    167 
    168144String openTemporaryFile(const String& prefix, PlatformFileHandle& handle, const String& suffix)
    169145{
  • trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp

    r277231 r277357  
    187187}
    188188
    189 Vector<String> listDirectory(const String& path, const String& filter)
    190 {
    191     Vector<String> entries;
    192     CString cpath = fileSystemRepresentation(path);
    193     CString cfilter = fileSystemRepresentation(filter);
    194     DIR* dir = opendir(cpath.data());
    195     if (dir) {
    196         struct dirent* dp;
    197         while ((dp = readdir(dir))) {
    198             const char* name = dp->d_name;
    199             if (!strcmp(name, ".") || !strcmp(name, ".."))
    200                 continue;
    201             if (fnmatch(cfilter.data(), name, 0))
    202                 continue;
    203             char filePath[PATH_MAX];
    204             if (static_cast<int>(sizeof(filePath) - 1) < snprintf(filePath, sizeof(filePath), "%s/%s", cpath.data(), name))
    205                 continue; // buffer overflow
    206 
    207             auto string = stringFromFileSystemRepresentation(filePath);
    208 
    209             // Some file system representations cannot be represented as a UTF-16 string,
    210             // so this string might be null.
    211             if (!string.isNull())
    212                 entries.append(WTFMove(string));
    213         }
    214         closedir(dir);
    215     }
    216     return entries;
    217 }
    218 
    219189#if !USE(CF)
    220190String stringFromFileSystemRepresentation(const char* path)
  • trunk/Source/WTF/wtf/win/FileSystemWin.cpp

    r277231 r277357  
    365365}
    366366
    367 Vector<String> listDirectory(const String& directory, const String& filter)
    368 {
    369     Vector<String> entries;
    370 
    371     PathWalker walker(directory, filter);
    372     if (!walker.isValid())
    373         return entries;
    374 
    375     do {
    376         if (walker.data().dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
    377             && (!wcscmp(walker.data().cFileName, L".") || !wcscmp(walker.data().cFileName, L"..")))
    378             continue;
    379 
    380         entries.append(directory + "\\" + reinterpret_cast<const UChar*>(walker.data().cFileName));
    381     } while (walker.step());
    382 
    383     return entries;
    384 }
    385 
    386367Optional<int32_t> getFileDeviceId(const CString& fsFile)
    387368{
  • trunk/Source/WebCore/ChangeLog

    r277356 r277357  
     12021-05-11  Chris Dumez  <cdumez@apple.com>
     2
     3        Port WTF::FileSystem::listDirectory to std::filesystem
     4        https://bugs.webkit.org/show_bug.cgi?id=225633
     5
     6        Reviewed by Darin Adler.
     7
     8        Update FileSystem::listDirectory() call sites to deal with the fact that:
     9        - The function now returns file names instead of full file paths
     10        - The callers now have to do filtering by themselves if they need it
     11
     12        * Modules/entriesapi/DOMFileSystem.cpp:
     13        (WebCore::listDirectoryWithMetadata):
     14        * Modules/indexeddb/server/IDBServer.cpp:
     15        (WebCore::IDBServer::IDBServer::getAllDatabaseNamesAndVersions):
     16        (WebCore::IDBServer::collectOriginsForVersion):
     17        (WebCore::IDBServer::removeAllDatabasesForFullOriginPath):
     18        (WebCore::IDBServer::removeAllDatabasesForOriginPath):
     19        (WebCore::IDBServer::IDBServer::removeDatabasesModifiedSinceForVersion):
     20        (WebCore::IDBServer::IDBServer::removeDatabasesWithOriginsForVersion):
     21        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
     22        (WebCore::IDBServer::SQLiteIDBBackingStore::fullDatabaseDirectoryWithUpgrade):
     23        (WebCore::IDBServer::SQLiteIDBBackingStore::databasesSizeForDirectory):
     24        * Modules/webdatabase/DatabaseTracker.cpp:
     25        (WebCore::DatabaseTracker::usage):
     26        (WebCore::DatabaseTracker::deleteOrigin):
     27        * html/DirectoryFileListCreator.cpp:
     28        (WebCore::appendDirectoryFiles):
     29        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
     30        (WebCore::MediaPlayerPrivateGStreamer::uriDecodeBinElementAddedCallback):
     31        (WebCore::MediaPlayerPrivateGStreamer::purgeOldDownloadFiles):
     32        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:
     33        * platform/text/hyphen/HyphenationLibHyphen.cpp:
     34        (WebCore::extractLocaleFromDictionaryFileName):
     35        (WebCore::scanDirectoryForDictionaries):
     36
    1372021-05-11  Chris Dumez  <cdumez@apple.com>
    238
  • trunk/Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp

    r274482 r277357  
    5555        return Exception { NotFoundError, "Path no longer exists or is no longer a directory" };
    5656
    57     auto childPaths = FileSystem::listDirectory(fullPath, "*");
     57    auto childNames = FileSystem::listDirectory(fullPath);
    5858    Vector<ListedChild> listedChildren;
    59     listedChildren.reserveInitialCapacity(childPaths.size());
    60     for (auto& childPath : childPaths) {
    61         auto metadata = FileSystem::fileMetadata(childPath);
     59    listedChildren.reserveInitialCapacity(childNames.size());
     60    for (auto& childName : childNames) {
     61        auto metadata = FileSystem::fileMetadata(FileSystem::pathByAppendingComponent(fullPath, childName));
    6262        if (!metadata || metadata.value().isHidden)
    6363            continue;
    64         listedChildren.uncheckedAppend(ListedChild { FileSystem::pathGetFileName(childPath), metadata.value().type });
     64        listedChildren.uncheckedAppend(ListedChild { childName, metadata.value().type });
    6565    }
    6666    return listedChildren;
  • trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp

    r275891 r277357  
    515515
    516516    String oldDirectory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, m_databaseDirectoryPath, "v0");
    517     Vector<String> files = FileSystem::listDirectory(oldDirectory, "*"_s);
     517    Vector<String> fileNames = FileSystem::listDirectory(oldDirectory);
    518518    Vector<IDBDatabaseNameAndVersion> databases;
    519     for (auto& file : files) {
    520         auto databaseTuple = SQLiteIDBBackingStore::databaseNameAndVersionFromFile(SQLiteIDBBackingStore::fullDatabasePathForDirectory(file));
     519    for (auto& fileName : fileNames) {
     520        auto databaseTuple = SQLiteIDBBackingStore::databaseNameAndVersionFromFile(SQLiteIDBBackingStore::fullDatabasePathForDirectory(FileSystem::pathByAppendingComponent(oldDirectory, fileName)));
    521521        if (databaseTuple)
    522522            databases.append(WTFMove(*databaseTuple));
     
    524524
    525525    String directory = IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(origin.topOrigin, origin.clientOrigin, m_databaseDirectoryPath, "v1");
    526     files = FileSystem::listDirectory(directory, "*"_s);
    527     for (auto& file : files) {
    528         auto databaseTuple = SQLiteIDBBackingStore::databaseNameAndVersionFromFile(SQLiteIDBBackingStore::fullDatabasePathForDirectory(file));
     526    fileNames = FileSystem::listDirectory(directory);
     527    for (auto& fileName : fileNames) {
     528        auto databaseTuple = SQLiteIDBBackingStore::databaseNameAndVersionFromFile(SQLiteIDBBackingStore::fullDatabasePathForDirectory(FileSystem::pathByAppendingComponent(directory, fileName)));
    529529        if (databaseTuple)
    530530            databases.append(WTFMove(*databaseTuple));
     
    540540static void collectOriginsForVersion(const String& versionPath, HashSet<WebCore::SecurityOriginData>& securityOrigins)
    541541{
    542     for (auto& topOriginPath : FileSystem::listDirectory(versionPath, "*")) {
    543         auto databaseIdentifier = FileSystem::pathGetFileName(topOriginPath);
     542    for (auto& databaseIdentifier : FileSystem::listDirectory(versionPath)) {
    544543        if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier)) {
    545544            securityOrigins.add(WTFMove(*securityOrigin));
    546545       
    547             for (auto& originPath : FileSystem::listDirectory(topOriginPath, "*")) {
    548                 databaseIdentifier = FileSystem::pathGetFileName(originPath);
     546            for (auto& databaseIdentifier : FileSystem::listDirectory(FileSystem::pathByAppendingComponent(versionPath, databaseIdentifier))) {
    549547                if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
    550548                    securityOrigins.add(WTFMove(*securityOrigin));
     
    629627{
    630628    LOG(IndexedDB, "removeAllDatabasesForOriginPath with originPath %s", originPath.utf8().data());
    631     Vector<String> databasePaths = FileSystem::listDirectory(originPath, "*");
    632 
    633     for (auto& databasePath : databasePaths) {
     629    Vector<String> databaseNames = FileSystem::listDirectory(originPath);
     630
     631    for (auto& databaseName : databaseNames) {
     632        auto databasePath = FileSystem::pathByAppendingComponent(originPath, databaseName);
    634633        String databaseFile = FileSystem::pathByAppendingComponent(databasePath, "IndexedDB.sqlite3");
    635634        if (modifiedSince > -WallTime::infinity() && FileSystem::fileExists(databaseFile)) {
     
    650649        // To be conservative, we should *not* try to delete files that are unexpected;
    651650        // We should only delete files we think we put there.
    652         //
    653         // IndexedDB blob files are named "N.blob" where N is a decimal integer,
    654         // so those are the only blob files we should be trying to delete.
    655         for (auto& blobPath : FileSystem::listDirectory(databasePath, "[0-9]*.blob")) {
    656             // Globbing can't give us only filenames starting with 1-or-more digits.
    657             // The above globbing gives us files that start with a digit and ends with ".blob", but there might be non-digits in between.
    658             // We need to validate that each filename contains only digits before deleting it, as any other files are not ones we put there.
    659             String filename = FileSystem::pathGetFileName(blobPath);
    660             auto filenameLength = filename.length();
    661 
    662             ASSERT(filenameLength >= 6);
    663             ASSERT(filename.endsWith(".blob"));
    664 
    665             if (filename.length() < 6)
     651        for (auto& fileName : FileSystem::listDirectory(databasePath)) {
     652            // IndexedDB blob files are named "N.blob" where N is a decimal integer,
     653            // so those are the only blob files we should be trying to delete.
     654            auto fileNameLength = fileName.length();
     655            if (fileNameLength < 6)
    666656                continue;
    667             if (!filename.endsWith(".blob"))
     657            if (!fileName.endsWith(".blob"))
    668658                continue;
    669659
    670             bool validFilename = true;
    671             for (unsigned i = 0; i < filenameLength - 5; ++i) {
    672                 if (!isASCIIDigit(filename[i])) {
    673                     validFilename = false;
     660            bool validFileName = true;
     661            for (unsigned i = 0; i < fileNameLength - 5; ++i) {
     662                if (!isASCIIDigit(fileName[i])) {
     663                    validFileName = false;
    674664                    break;
    675665                }
    676666            }
    677667
    678             if (validFilename)
    679                 FileSystem::deleteFile(blobPath);
     668            if (validFileName)
     669                FileSystem::deleteFile(FileSystem::pathByAppendingComponent(databasePath, fileName));
    680670        }
    681671
     
    697687        return;
    698688   
    699     auto directories = FileSystem::listDirectory(originPath, "*"_s);
    700     for (auto& directory : directories) {
    701         String databaseIdentifier = FileSystem::lastComponentOfPathIgnoringTrailingSlash(directory);
     689    auto directoryNames = FileSystem::listDirectory(originPath);
     690    for (auto& databaseIdentifier : directoryNames) {
    702691        if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
    703             removeAllDatabasesForFullOriginPath(directory, modifiedSince);
     692            removeAllDatabasesForFullOriginPath(FileSystem::pathByAppendingComponent(originPath, databaseIdentifier), modifiedSince);
    704693    }
    705694   
     
    710699{
    711700    String versionPath = FileSystem::pathByAppendingComponent(m_databaseDirectoryPath, version);
    712     for (auto& originPath : FileSystem::listDirectory(versionPath, "*")) {
    713         String databaseIdentifier = FileSystem::lastComponentOfPathIgnoringTrailingSlash(originPath);
     701    for (auto& databaseIdentifier : FileSystem::listDirectory(versionPath)) {
    714702        if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(databaseIdentifier))
    715             removeAllDatabasesForOriginPath(originPath, modifiedSince);
     703            removeAllDatabasesForOriginPath(FileSystem::pathByAppendingComponent(versionPath, databaseIdentifier), modifiedSince);
    716704    }
    717705}
     
    724712        removeAllDatabasesForOriginPath(originPath, -WallTime::infinity());
    725713       
    726         for (auto& topOriginPath : FileSystem::listDirectory(versionPath, "*")) {
     714        for (auto& topOrigin : FileSystem::listDirectory(versionPath)) {
     715            auto topOriginPath = FileSystem::pathByAppendingComponent(versionPath, topOrigin);
    727716            originPath = FileSystem::pathByAppendingComponent(topOriginPath, origin.databaseIdentifier());
    728717            removeAllDatabasesForOriginPath(originPath, -WallTime::infinity());
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp

    r277343 r277357  
    11831183    String newOriginDirectory = m_identifier.databaseDirectoryRelativeToRoot(m_databaseRootDirectory, "v1");
    11841184    String fileNameHash = SQLiteFileSystem::computeHashForFileName(m_identifier.databaseName());
    1185     Vector<String> directoriesWithSameHash = FileSystem::listDirectory(newOriginDirectory, fileNameHash + "*");
    11861185    String newDatabaseDirectory = FileSystem::pathByAppendingComponent(newOriginDirectory, fileNameHash);
    11871186    FileSystem::makeAllDirectories(newDatabaseDirectory);
     
    12821281{
    12831282    uint64_t diskUsage = 0;
    1284     for (auto& dbDirectory : FileSystem::listDirectory(directory, "*")) {
    1285         for (auto& file : FileSystem::listDirectory(dbDirectory, "*.sqlite3"_s)) {
    1286             auto fileSize = SQLiteFileSystem::getDatabaseFileSize(file);
    1287             diskUsage += fileSize;
     1283    for (auto& dbDirectoryName : FileSystem::listDirectory(directory)) {
     1284        auto dbDirectoryPath = FileSystem::pathByAppendingComponent(directory, dbDirectoryName);
     1285        for (auto& fileName : FileSystem::listDirectory(dbDirectoryPath)) {
     1286            if (fileName.endsWith(".sqlite3"))
     1287                diskUsage += SQLiteFileSystem::getDatabaseFileSize(FileSystem::pathByAppendingComponent(dbDirectoryPath, fileName));
    12881288        }
    12891289    }
  • trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp

    r249313 r277357  
    656656    String originPath = this->originPath(origin);
    657657    unsigned long long diskUsage = 0;
    658     for (auto& fileName : FileSystem::listDirectory(originPath, "*.db"_s))
    659         diskUsage += SQLiteFileSystem::getDatabaseFileSize(fileName);
     658    for (auto& fileName : FileSystem::listDirectory(originPath)) {
     659        if (fileName.endsWith(".db"))
     660            diskUsage += SQLiteFileSystem::getDatabaseFileSize(FileSystem::pathByAppendingComponent(originPath, fileName));
     661    }
    660662    return diskUsage;
    661663}
     
    856858        RELEASE_LOG_ERROR(DatabaseTracker, "Unable to retrieve list of database names for origin");
    857859#endif
    858         for (const auto& file : FileSystem::listDirectory(originPath(origin), "*")) {
    859             if (!FileSystem::deleteFile(file))
     860        auto originPath = this->originPath(origin);
     861        for (const auto& fileName : FileSystem::listDirectory(originPath)) {
     862            if (!FileSystem::deleteFile(FileSystem::pathByAppendingComponent(originPath, fileName)))
    860863                failedToDeleteAnyDatabaseFile = true;
    861864        }
  • trunk/Source/WebCore/html/DirectoryFileListCreator.cpp

    r266168 r277357  
    5555{
    5656    ASSERT(!isMainThread());
    57     for (auto& childPath : FileSystem::listDirectory(directory, "*")) {
     57    for (auto& childName : FileSystem::listDirectory(directory)) {
     58        auto childPath = FileSystem::pathByAppendingComponent(directory, childName);
    5859        auto metadata = FileSystem::fileMetadata(childPath);
    5960        if (!metadata)
     
    6364            continue;
    6465
    65         String childRelativePath = relativePath + "/" + FileSystem::pathGetFileName(childPath);
     66        String childRelativePath = relativePath + "/" + childName;
    6667        if (metadata.value().type == FileMetadata::Type::Directory)
    6768            appendDirectoryFiles(childPath, childRelativePath, files);
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp

    r277088 r277357  
    21822182    GST_DEBUG_OBJECT(player->pipeline(), "Reconfigured file download template from '%s' to '%s'", oldDownloadTemplate.get(), newDownloadTemplate.get());
    21832183
    2184     player->purgeOldDownloadFiles(oldDownloadTemplate.get());
     2184    String newDownloadPrefixPath = newDownloadTemplate.get();
     2185    player->purgeOldDownloadFiles(newDownloadPrefixPath.replace("XXXXXX", ""));
    21852186}
    21862187
     
    22032204}
    22042205
    2205 void MediaPlayerPrivateGStreamer::purgeOldDownloadFiles(const char* downloadFileTemplate)
    2206 {
    2207     if (!downloadFileTemplate)
    2208         return;
    2209 
    2210     GUniquePtr<char> templatePath(g_path_get_dirname(downloadFileTemplate));
    2211     GUniquePtr<char> templateFile(g_path_get_basename(downloadFileTemplate));
    2212     String templatePattern = String(templateFile.get()).replace("X", "?");
    2213 
    2214     for (auto& filePath : FileSystem::listDirectory(templatePath.get(), templatePattern)) {
     2206void MediaPlayerPrivateGStreamer::purgeOldDownloadFiles(const String& downloadFilePrefixPath)
     2207{
     2208    if (downloadFilePrefixPath.isEmpty())
     2209        return;
     2210
     2211    auto templateDirectory = FileSystem::directoryName(downloadFilePrefixPath);
     2212    auto templatePrefix = FileSystem::pathGetFileName(downloadFilePrefixPath);
     2213    for (auto& fileName : FileSystem::listDirectory(templateDirectory)) {
     2214        if (!fileName.startsWith(templatePrefix))
     2215            continue;
     2216
     2217        auto filePath = FileSystem::pathByAppendingComponent(templateDirectory, fileName);
    22152218        if (UNLIKELY(!FileSystem::deleteFile(filePath))) {
    22162219            GST_WARNING("Couldn't unlink legacy media temporary file: %s", filePath.utf8().data());
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h

    r277031 r277357  
    438438    bool canSaveMediaData() const override;
    439439
    440     void purgeOldDownloadFiles(const char*);
     440    void purgeOldDownloadFiles(const String& downloadFilePrefixPath);
    441441    static void uriDecodeBinElementAddedCallback(GstBin*, GstElement*, MediaPlayerPrivateGStreamer*);
    442442    static void downloadBufferFileCreatedCallback(MediaPlayerPrivateGStreamer*);
  • trunk/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp

    r271533 r277357  
    5353};
    5454
    55 static String extractLocaleFromDictionaryFilePath(const String& filePath)
    56 {
     55static String extractLocaleFromDictionaryFileName(const String& fileName)
     56{
     57    if (!fileName.startsWith("hyph_") || !fileName.endsWith(".dic"))
     58        return { };
     59
    5760    // Dictionary files always have the form "hyph_<locale name>.dic"
    5861    // so we strip everything except the locale.
    59     String fileName = FileSystem::pathGetFileName(filePath);
    60     static const int prefixLength = 5;
    61     static const int suffixLength = 4;
    62     return fileName.substring(prefixLength, fileName.length() - prefixLength - suffixLength);
     62    constexpr int prefixLength = 5;
     63    constexpr int suffixLength = 4;
     64    return fileName.substring(prefixLength, fileName.length() - prefixLength - suffixLength).convertToASCIILowercase();
    6365}
    6466
    6567static void scanDirectoryForDictionaries(const char* directoryPath, HashMap<AtomString, Vector<String>>& availableLocales)
    6668{
    67     for (auto& filePath : FileSystem::listDirectory(directoryPath, "hyph_*.dic")) {
    68         String locale = extractLocaleFromDictionaryFilePath(filePath).convertToASCIILowercase();
    69 
     69    for (auto& fileName : FileSystem::listDirectory(directoryPath)) {
     70        String locale = extractLocaleFromDictionaryFileName(fileName);
     71        if (locale.isEmpty())
     72            continue;
     73
     74        auto filePath = FileSystem::pathByAppendingComponent(directoryPath, fileName);
    7075        char normalizedPath[PATH_MAX];
    7176        if (!realpath(FileSystem::fileSystemRepresentation(filePath).data(), normalizedPath))
  • trunk/Source/WebKit/ChangeLog

    r277356 r277357  
     12021-05-11  Chris Dumez  <cdumez@apple.com>
     2
     3        Port WTF::FileSystem::listDirectory to std::filesystem
     4        https://bugs.webkit.org/show_bug.cgi?id=225633
     5
     6        Reviewed by Darin Adler.
     7
     8        Update FileSystem::listDirectory() call sites to deal with the fact that:
     9        - The function now returns file names instead of full file paths
     10        - The callers now have to do filtering by themselves if they need it
     11
     12        * NetworkProcess/WebStorage/LocalStorageDatabaseTracker.cpp:
     13        (WebKit::LocalStorageDatabaseTracker::origins const):
     14        * NetworkProcess/cache/CacheStorageEngine.cpp:
     15        (WebKit::CacheStorage::getDirectorySize):
     16        (WebKit::CacheStorage::Engine::getDirectories):
     17        (WebKit::CacheStorage::Engine::clearAllCachesFromDisk):
     18        * NetworkProcess/cache/NetworkCacheFileSystem.cpp:
     19        (WebKit::NetworkCache::traverseDirectory):
     20        * UIProcess/API/APIContentRuleListStore.cpp:
     21        (API::ContentRuleListStore::getAvailableContentRuleListIdentifiers):
     22        (API::ContentRuleListStore::synchronousRemoveAllContentRuleLists):
     23        * UIProcess/DeviceIdHashSaltStorage.cpp:
     24        (WebKit::DeviceIdHashSaltStorage::loadStorageFromDisk):
     25        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     26        (WebKit::WebsiteDataStore::mediaKeyOrigins):
     27        (WebKit::WebsiteDataStore::removeMediaKeys):
     28        * WebProcess/InjectedBundle/API/glib/WebKitExtensionManager.cpp:
     29        (WebKit::WebKitExtensionManager::scanModules):
     30        * WebProcess/MediaCache/WebMediaKeyStorageManager.cpp:
     31        (WebKit::WebMediaKeyStorageManager::getMediaKeyOrigins):
     32        (WebKit::removeAllMediaKeyStorageForOriginPath):
     33        (WebKit::WebMediaKeyStorageManager::deleteMediaKeyEntriesModifiedBetweenDates):
     34        (WebKit::WebMediaKeyStorageManager::deleteAllMediaKeyEntries):
     35
    1362021-05-11  Chris Dumez  <cdumez@apple.com>
    237
  • trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabaseTracker.cpp

    r272754 r277357  
    105105{
    106106    Vector<SecurityOriginData> databaseOrigins;
    107     auto paths = FileSystem::listDirectory(localStorageDirectory(), "*.localstorage");
    108    
    109     for (const auto& path : paths) {
     107    for (auto& path : FileSystem::listDirectory(localStorageDirectory())) {
    110108        auto filename = FileSystem::pathGetFileName(path);
    111109        auto originIdentifier = filename.substring(0, filename.length() - strlen(".localstorage"));
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp

    r277239 r277357  
    209209        auto path = paths.takeFirst();
    210210        if (FileSystem::fileIsDirectory(path, FileSystem::ShouldFollowSymbolicLinks::No)) {
    211             auto newPaths = FileSystem::listDirectory(path, "*"_s);
    212             for (auto& newPath : newPaths) {
     211            auto fileNames = FileSystem::listDirectory(path);
     212            for (auto& fileName : fileNames) {
    213213                // Files in /Blobs directory are hard link.
    214                 auto fileName = FileSystem::lastComponentOfPathIgnoringTrailingSlash(newPath);
    215214                if (fileName == "Blobs")
    216215                    continue;
    217                 paths.append(newPath);
     216                paths.append(FileSystem::pathByAppendingComponent(path, fileName));
    218217            }
    219218            continue;
     
    616615    m_ioQueue->dispatch([path = m_rootPath.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
    617616        Vector<String> folderPaths;
    618         for (auto& filename : FileSystem::listDirectory(path, "*")) {
    619             if (FileSystem::fileIsDirectory(filename, FileSystem::ShouldFollowSymbolicLinks::No))
    620                 folderPaths.append(filename.isolatedCopy());
     617        for (auto& fileName : FileSystem::listDirectory(path)) {
     618            auto filePath = FileSystem::pathByAppendingComponent(path, fileName);
     619            if (FileSystem::fileIsDirectory(filePath, FileSystem::ShouldFollowSymbolicLinks::No))
     620                folderPaths.append(filePath.isolatedCopy());
    621621        }
    622622
     
    703703    m_ioQueue->dispatch([path = m_rootPath.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
    704704        LockHolder locker(globalSizeFileLock);
    705         for (auto& filename : FileSystem::listDirectory(path, "*")) {
    706             if (FileSystem::fileIsDirectory(filename, FileSystem::ShouldFollowSymbolicLinks::No))
    707                 FileSystem::deleteNonEmptyDirectory(filename);
     705        for (auto& fileName : FileSystem::listDirectory(path)) {
     706            auto filePath = FileSystem::pathByAppendingComponent(path, fileName);
     707            if (FileSystem::fileIsDirectory(filePath, FileSystem::ShouldFollowSymbolicLinks::No))
     708                FileSystem::deleteNonEmptyDirectory(filePath);
    708709        }
    709710        RunLoop::main().dispatch(WTFMove(completionHandler));
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp

    r275267 r277357  
    5656void traverseDirectory(const String& path, const Function<void (const String&, DirectoryEntryType)>& function)
    5757{
    58     auto entries = FileSystem::listDirectory(path, "*"_s);
     58    auto entries = FileSystem::listDirectory(path);
    5959    for (auto& entry : entries) {
    60         auto type = FileSystem::fileIsDirectory(entry, FileSystem::ShouldFollowSymbolicLinks::No) ? DirectoryEntryType::Directory : DirectoryEntryType::File;
    61         function(FileSystem::pathGetFileName(entry), type);
     60        auto entryPath = FileSystem::pathByAppendingComponent(path, entry);
     61        auto type = FileSystem::fileIsDirectory(entryPath, FileSystem::ShouldFollowSymbolicLinks::No) ? DirectoryEntryType::Directory : DirectoryEntryType::File;
     62        function(entry, type);
    6263    }
    6364}
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp

    r275166 r277357  
    9090}
    9191
    92 static const WTF::String constructedPathFilter(bool legacyFilename)
    93 {
    94     return makeString(constructedPathPrefix(legacyFilename), '*');
    95 }
    96 
    9792static WTF::String constructedPath(const WTF::String& base, const WTF::String& identifier, bool legacyFilename)
    9893{
     
    501496    ASSERT(RunLoop::isMain());
    502497    m_readQueue->dispatch([protectedThis = makeRef(*this), storePath = m_storePath.isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
    503 
    504         Vector<WTF::String> fullPaths = listDirectory(storePath, constructedPathFilter(false));
    505         Vector<WTF::String> legacyFullPaths = listDirectory(storePath, constructedPathFilter(true));
     498        auto prefix = constructedPathPrefix(false /*legacy*/);
     499        auto prefixLength = prefix.length();
     500        auto legacyPrefix = constructedPathPrefix(true /*legacy*/);
     501        auto legacyPrefixLength = legacyPrefix.length();
     502
    506503        Vector<WTF::String> identifiers;
    507         identifiers.reserveInitialCapacity(fullPaths.size() + legacyFullPaths.size());
    508         const auto prefixLength = constructedPathPrefix(false).length();
    509         const auto legacyPrefixLength = constructedPathPrefix(true).length();
    510         for (const auto& path : fullPaths)
    511             identifiers.uncheckedAppend(decodeFromFilename(path.substring(path.reverseFind('/') + 1 + prefixLength)));
    512         for (const auto& path : legacyFullPaths)
    513             identifiers.uncheckedAppend(decodeFromFilename(path.substring(path.reverseFind('/') + 1 + legacyPrefixLength)));
     504        for (auto& fileName : listDirectory(storePath)) {
     505            if (fileName.startsWith(prefix))
     506                identifiers.append(decodeFromFilename(fileName.substring(prefixLength)));
     507            else if (fileName.startsWith(legacyPrefix))
     508                identifiers.append(decodeFromFilename(fileName.substring(legacyPrefixLength)));
     509        }
    514510
    515511        RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler), identifiers = WTFMove(identifiers)]() mutable {
     
    569565void ContentRuleListStore::synchronousRemoveAllContentRuleLists()
    570566{
    571     for (const auto& path : listDirectory(m_storePath, "*"))
    572         deleteFile(path);
     567    for (const auto& fileName : listDirectory(m_storePath))
     568        deleteFile(FileSystem::pathByAppendingComponent(m_storePath, fileName));
    573569}
    574570
  • trunk/Source/WebKit/UIProcess/DeviceIdHashSaltStorage.cpp

    r260707 r277357  
    116116
    117117        HashMap<String, std::unique_ptr<HashSaltForOrigin>> deviceIdHashSaltForOrigins;
    118         for (auto& originPath : FileSystem::listDirectory(m_deviceIdHashSaltStorageDirectory, "*")) {
     118        for (auto& origin : FileSystem::listDirectory(m_deviceIdHashSaltStorageDirectory)) {
     119            auto originPath = FileSystem::pathByAppendingComponent(m_deviceIdHashSaltStorageDirectory, origin);
    119120            auto deviceIdHashSalt = URL::fileURLWithFileSystemPath(originPath).lastPathComponent().toString();
    120121
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r277114 r277357  
    16731673    Vector<WebCore::SecurityOriginData> origins;
    16741674
    1675     for (const auto& originPath : FileSystem::listDirectory(mediaKeysStorageDirectory, "*")) {
     1675    for (const auto& mediaKeyIdentifier : FileSystem::listDirectory(mediaKeysStorageDirectory)) {
     1676        auto originPath = FileSystem::pathByAppendingComponent(mediaKeysStorageDirectory, mediaKeyIdentifier);
    16761677        auto mediaKeyFile = computeMediaKeyFile(originPath);
    16771678        if (!FileSystem::fileExists(mediaKeyFile))
    16781679            continue;
    16791680
    1680         auto mediaKeyIdentifier = FileSystem::pathGetFileName(originPath);
    1681 
    16821681        if (auto securityOrigin = WebCore::SecurityOriginData::fromDatabaseIdentifier(mediaKeyIdentifier))
    16831682            origins.append(*securityOrigin);
     
    16911690    ASSERT(!mediaKeysStorageDirectory.isEmpty());
    16921691
    1693     for (const auto& mediaKeyDirectory : FileSystem::listDirectory(mediaKeysStorageDirectory, "*")) {
     1692    for (const auto& directoryName : FileSystem::listDirectory(mediaKeysStorageDirectory)) {
     1693        auto mediaKeyDirectory = FileSystem::pathByAppendingComponent(mediaKeysStorageDirectory, directoryName);
    16941694        auto mediaKeyFile = computeMediaKeyFile(mediaKeyDirectory);
    16951695
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitExtensionManager.cpp

    r248846 r277357  
    4242void WebKitExtensionManager::scanModules(const String& webExtensionsDirectory, Vector<String>& modules)
    4343{
    44     Vector<String> modulePaths = FileSystem::listDirectory(webExtensionsDirectory, String("*.so"));
    45     for (size_t i = 0; i < modulePaths.size(); ++i) {
    46         if (FileSystem::fileExists(modulePaths[i]))
    47             modules.append(modulePaths[i]);
     44    auto moduleNames = FileSystem::listDirectory(webExtensionsDirectory);
     45    for (auto& moduleName : moduleNames) {
     46        if (!moduleName.endsWith(".so"))
     47            continue;
     48
     49        auto modulePath = FileSystem::pathByAppendingComponent(webExtensionsDirectory, moduleName);
     50        if (FileSystem::fileExists(modulePath))
     51            modules.append(modulePath);
    4852    }
    4953}
  • trunk/Source/WebKit/WebProcess/MediaCache/WebMediaKeyStorageManager.cpp

    r260707 r277357  
    6161        return results;
    6262
    63     for (auto& originPath : FileSystem::listDirectory(m_mediaKeyStorageDirectory, "*")) {
    64         auto identifier = URL::fileURLWithFileSystemPath(originPath).lastPathComponent().toString();
     63    for (auto& identifier : FileSystem::listDirectory(m_mediaKeyStorageDirectory)) {
    6564        if (auto securityOrigin = SecurityOriginData::fromDatabaseIdentifier(identifier))
    6665            results.append(*securityOrigin);
     
    7271static void removeAllMediaKeyStorageForOriginPath(const String& originPath, WallTime startDate, WallTime endDate)
    7372{
    74     Vector<String> mediaKeyPaths = FileSystem::listDirectory(originPath, "*");
     73    Vector<String> mediaKeyNames = FileSystem::listDirectory(originPath);
    7574
    76     for (const auto& mediaKeyPath : mediaKeyPaths) {
     75    for (const auto& mediaKeyName : mediaKeyNames) {
     76        auto mediaKeyPath = FileSystem::pathByAppendingComponent(originPath, mediaKeyName);
    7777        String mediaKeyFile = FileSystem::pathByAppendingComponent(mediaKeyPath, "SecureStop.plist");
    7878
     
    107107        return;
    108108
    109     Vector<String> originPaths = FileSystem::listDirectory(m_mediaKeyStorageDirectory, "*");
    110     for (auto& originPath : originPaths)
    111         removeAllMediaKeyStorageForOriginPath(originPath, startDate, endDate);
     109    Vector<String> originNames = FileSystem::listDirectory(m_mediaKeyStorageDirectory);
     110    for (auto& originName : originNames)
     111        removeAllMediaKeyStorageForOriginPath(FileSystem::pathByAppendingComponent(m_mediaKeyStorageDirectory, originName), startDate, endDate);
    112112}
    113113
     
    117117        return;
    118118
    119     Vector<String> originPaths = FileSystem::listDirectory(m_mediaKeyStorageDirectory, "*");
    120     for (auto& originPath : originPaths)
    121         removeAllMediaKeyStorageForOriginPath(originPath, -WallTime::infinity(), WallTime::infinity());
     119    Vector<String> originNames = FileSystem::listDirectory(m_mediaKeyStorageDirectory);
     120    for (auto& originName : originNames)
     121        removeAllMediaKeyStorageForOriginPath(FileSystem::pathByAppendingComponent(m_mediaKeyStorageDirectory, originName), -WallTime::infinity(), WallTime::infinity());
    122122}
    123123
  • trunk/Source/WebKitLegacy/ChangeLog

    r276982 r277357  
     12021-05-11  Chris Dumez  <cdumez@apple.com>
     2
     3        Port WTF::FileSystem::listDirectory to std::filesystem
     4        https://bugs.webkit.org/show_bug.cgi?id=225633
     5
     6        Reviewed by Darin Adler.
     7
     8        Update FileSystem::listDirectory() call sites to deal with the fact that:
     9        - The function now returns file names instead of full file paths
     10        - The callers now have to do filtering by themselves if they need it
     11
     12        * Storage/StorageTracker.cpp:
     13        (WebKit::StorageTracker::syncFileSystemAndTrackerDatabase):
     14
    1152021-05-04  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Source/WebKitLegacy/Storage/StorageTracker.cpp

    r276982 r277357  
    237237    ASSERT(m_isActive);
    238238
    239     Vector<String> paths;
     239    Vector<String> fileNames;
    240240    {
    241241        LockHolder locker(m_databaseMutex);
    242         paths = FileSystem::listDirectory(m_storageDirectoryPath, "*.localstorage");
     242        fileNames = FileSystem::listDirectory(m_storageDirectoryPath);
    243243    }
    244244
     
    256256    String fileExtension = ".localstorage"_s;
    257257
    258     for (Vector<String>::const_iterator it = paths.begin(), end = paths.end(); it != end; ++it) {
    259         const String& path = *it;
    260 
    261         if (path.length() > fileExtension.length() && path.endsWith(fileExtension)) {
    262             String file = FileSystem::pathGetFileName(path);
    263             String originIdentifier = file.substring(0, file.length() - fileExtension.length());
    264             if (!originSetCopy.contains(originIdentifier))
    265                 syncSetOriginDetails(originIdentifier, path);
    266 
    267             foundOrigins.add(originIdentifier);
    268         }
     258    for (auto& fileName : fileNames) {
     259        if (fileName.length() <= fileExtension.length() || !fileName.endsWith(fileExtension))
     260            continue;
     261
     262        auto filePath = FileSystem::pathByAppendingComponent(m_storageDirectoryPath, fileName);
     263        String originIdentifier = fileName.substring(0, fileName.length() - fileExtension.length());
     264        if (!originSetCopy.contains(originIdentifier))
     265            syncSetOriginDetails(originIdentifier, filePath);
     266
     267        foundOrigins.add(originIdentifier);
    269268    }
    270269
  • trunk/Source/WebKitLegacy/win/ChangeLog

    r277295 r277357  
     12021-05-11  Chris Dumez  <cdumez@apple.com>
     2
     3        Port WTF::FileSystem::listDirectory to std::filesystem
     4        https://bugs.webkit.org/show_bug.cgi?id=225633
     5
     6        Reviewed by Darin Adler.
     7
     8        Update FileSystem::listDirectory() call sites to deal with the fact that:
     9        - The function now returns file names instead of full file paths
     10        - The callers now have to do filtering by themselves if they need it
     11
     12        * Plugins/PluginDatabase.cpp:
     13        (WebCore::PluginDatabase::getPluginPathsInDirectories const):
     14
    1152021-05-10  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/Source/WebKitLegacy/win/Plugins/PluginDatabase.cpp

    r260707 r277357  
    400400{
    401401    // FIXME: This should be a case insensitive set.
    402     HashSet<String> uniqueFilenames;
    403 
    404     String fileNameFilter("");
    405 
    406     auto dirsEnd = m_pluginDirectories.end();
    407     for (auto dIt = m_pluginDirectories.begin(); dIt != dirsEnd; ++dIt) {
    408         Vector<String> pluginPaths = FileSystem::listDirectory(*dIt, fileNameFilter);
    409         auto pluginsEnd = pluginPaths.end();
    410         for (auto pIt = pluginPaths.begin(); pIt != pluginsEnd; ++pIt) {
    411             if (!fileExistsAndIsNotDisabled(*pIt))
     402    for (auto& pluginDirectory : m_pluginDirectories) {
     403        for (auto& pluginName : FileSystem::listDirectory(pluginDirectory)) {
     404            auto pluginPath = FileSystem::pathByAppendingComponent(pluginDirectory, pluginName);
     405            if (!fileExistsAndIsNotDisabled(pluginPath))
    412406                continue;
    413407
    414             paths.add(*pIt);
     408            paths.add(pluginPath);
    415409        }
    416410    }
  • trunk/Tools/ChangeLog

    r277356 r277357  
     12021-05-11  Chris Dumez  <cdumez@apple.com>
     2
     3        Port WTF::FileSystem::listDirectory to std::filesystem
     4        https://bugs.webkit.org/show_bug.cgi?id=225633
     5
     6        Reviewed by Darin Adler.
     7
     8        Add API test coverage.
     9
     10        * TestWebKitAPI/Tests/WTF/FileSystem.cpp:
     11        (TestWebKitAPI::createTestFile):
     12        (TestWebKitAPI::TEST_F):
     13        * TestWebKitAPI/Tests/WebCore/cocoa/DatabaseTrackerTest.mm:
     14        (TestWebKitAPI::removeDirectoryAndAllContents):
     15
    1162021-05-11  Chris Dumez  <cdumez@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp

    r277231 r277357  
    3838const char* FileSystemTestData = "This is a test";
    3939
     40static void createTestFile(const String& path)
     41{
     42    auto fileHandle = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);
     43    EXPECT_TRUE(FileSystem::isHandleValid(fileHandle));
     44    FileSystem::writeToFile(fileHandle, FileSystemTestData, strlen(FileSystemTestData));
     45    FileSystem::closeFile(fileHandle);
     46};
     47
    4048// FIXME: Refactor FileSystemTest and SharedBufferTest as a single class.
    4149class FileSystemTest : public testing::Test {
     
    250258TEST_F(FileSystemTest, deleteNonEmptyDirectory)
    251259{
    252     auto createTestTile = [](const String& path) {
    253         auto fileHandle = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);
    254         EXPECT_TRUE(FileSystem::isHandleValid(fileHandle));
    255         FileSystem::writeToFile(fileHandle, FileSystemTestData, strlen(FileSystemTestData));
    256         FileSystem::closeFile(fileHandle);
    257     };
    258 
    259260    FileSystem::PlatformFileHandle temporaryFile;
    260261    auto temporaryTestFolder = FileSystem::openTemporaryFile("deleteNonEmptyDirectoryTest", temporaryFile);
     
    263264    EXPECT_TRUE(FileSystem::deleteFile(temporaryTestFolder));
    264265    EXPECT_TRUE(FileSystem::makeAllDirectories(FileSystem::pathByAppendingComponents(temporaryTestFolder, { "subfolder" })));
    265     createTestTile(FileSystem::pathByAppendingComponent(temporaryTestFolder, "file1.txt"));
    266     createTestTile(FileSystem::pathByAppendingComponent(temporaryTestFolder, "file2.txt"));
    267     createTestTile(FileSystem::pathByAppendingComponents(temporaryTestFolder, { "subfolder", "file3.txt" }));
    268     createTestTile(FileSystem::pathByAppendingComponents(temporaryTestFolder, { "subfolder", "file4.txt" }));
     266    createTestFile(FileSystem::pathByAppendingComponent(temporaryTestFolder, "file1.txt"));
     267    createTestFile(FileSystem::pathByAppendingComponent(temporaryTestFolder, "file2.txt"));
     268    createTestFile(FileSystem::pathByAppendingComponents(temporaryTestFolder, { "subfolder", "file3.txt" }));
     269    createTestFile(FileSystem::pathByAppendingComponents(temporaryTestFolder, { "subfolder", "file4.txt" }));
    269270    EXPECT_FALSE(FileSystem::deleteEmptyDirectory(temporaryTestFolder));
    270271    EXPECT_TRUE(FileSystem::fileExists(temporaryTestFolder));
     
    781782}
    782783
     784TEST_F(FileSystemTest, listDirectory)
     785{
     786    createTestFile(FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "a.txt"));
     787    createTestFile(FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "b.txt"));
     788    createTestFile(FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "bar.png"));
     789    createTestFile(FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "foo.png"));
     790    FileSystem::makeAllDirectories(FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "subfolder"));
     791    createTestFile(FileSystem::pathByAppendingComponents(tempEmptyFolderPath(), { "subfolder", "c.txt" }));
     792    createTestFile(FileSystem::pathByAppendingComponents(tempEmptyFolderPath(), { "subfolder", "d.txt" }));
     793
     794    auto matches = FileSystem::listDirectory(tempEmptyFolderPath());
     795    ASSERT_EQ(matches.size(), 5U);
     796    std::sort(matches.begin(), matches.end(), WTF::codePointCompareLessThan);
     797    EXPECT_STREQ(matches[0].utf8().data(), "a.txt");
     798    EXPECT_STREQ(matches[1].utf8().data(), "b.txt");
     799    EXPECT_STREQ(matches[2].utf8().data(), "bar.png");
     800    EXPECT_STREQ(matches[3].utf8().data(), "foo.png");
     801    EXPECT_STREQ(matches[4].utf8().data(), "subfolder");
     802
     803    matches = FileSystem::listDirectory(FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "subfolder"));
     804    ASSERT_EQ(matches.size(), 2U);
     805    std::sort(matches.begin(), matches.end(), WTF::codePointCompareLessThan);
     806    EXPECT_STREQ(matches[0].utf8().data(), "c.txt");
     807    EXPECT_STREQ(matches[1].utf8().data(), "d.txt");
     808
     809    matches = FileSystem::listDirectory(FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "does-not-exist"));
     810    ASSERT_EQ(matches.size(), 0U);
     811
     812    matches = FileSystem::listDirectory(FileSystem::pathByAppendingComponent(tempEmptyFolderPath(), "a.txt"));
     813    ASSERT_EQ(matches.size(), 0U);
     814
     815    EXPECT_TRUE(FileSystem::deleteNonEmptyDirectory(tempEmptyFolderPath()));
     816}
     817
    783818} // namespace TestWebKitAPI
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/DatabaseTrackerTest.mm

    r260366 r277357  
    7979static void removeDirectoryAndAllContents(const String& directoryPath)
    8080{
    81     for (const auto& file : FileSystem::listDirectory(directoryPath, "*"))
    82         EXPECT_TRUE(FileSystem::deleteFile(file));
     81    for (auto& fileName : FileSystem::listDirectory(directoryPath))
     82        EXPECT_TRUE(FileSystem::deleteFile(FileSystem::pathByAppendingComponent(directoryPath, fileName)));
    8383
    8484    if (FileSystem::fileExists(directoryPath))
Note: See TracChangeset for help on using the changeset viewer.