Skip to content
Permalink
Browse files
Rename FileSystem::directoryName() to FileSystem::parentPath()
https://bugs.webkit.org/show_bug.cgi?id=225768

Reviewed by Darin Adler.

Rename FileSystem::directoryName() to FileSystem::parentPath() for clarity and
consistency with std::filesystem::parent_path() which is used internally.

Source/JavaScriptCore:

* API/JSScript.mm:
(validateBytecodeCachePath):

Source/WebCore:

* Modules/entriesapi/DOMFileSystem.cpp:
(WebCore::DOMFileSystem::DOMFileSystem):
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::writeDataToUniqueFileInDirectory):
(WebCore::ApplicationCacheStorage::checkForDeletedResources):
* platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.mm:
(WebCore::CDMSessionAVContentKeySession::contentKeySession):
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::purgeOldDownloadFiles):
* platform/network/curl/CookieJarDB.cpp:
(WebCore::CookieJarDB::openDatabase):
* platform/sql/SQLiteFileSystem.cpp:
(WebCore::SQLiteFileSystem::ensureDatabaseFileExists):
* platform/win/SearchPopupMenuDB.cpp:
(WebCore::SearchPopupMenuDB::openDatabase):
* workers/service/server/SWScriptStorage.cpp:
(WebCore::SWScriptStorage::store):

Source/WebKit:

* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
(WebKit::ResourceLoadStatisticsDatabaseStore::openITPDatabase):
* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::writeFile):
* Shared/glib/ProcessExecutablePathGLib.cpp:
(WebKit::getExecutablePath):
* UIProcess/API/glib/IconDatabase.cpp:
(WebKit::IconDatabase::IconDatabase):
* UIProcess/API/glib/WebKitWebsiteDataManager.cpp:
(webkit_website_data_manager_get_disk_cache_directory):
* UIProcess/Launcher/glib/BubblewrapLauncher.cpp:
(WebKit::bubblewrapSpawn):
* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::platformSetNetworkParameters):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::resolveDirectoriesIfNecessary):

Source/WebKitLegacy:

* Storage/StorageTracker.cpp:
(WebKit::ensureDatabaseFileExists):

Source/WebKitLegacy/win:

* Plugins/PluginDatabase.cpp:
(WebCore::PluginDatabase::loadPersistentMetadataCache):

Source/WTF:

* wtf/FileSystem.cpp:
(WTF::FileSystemImpl::readOrMakeSalt):
(WTF::FileSystemImpl::parentPath):
(WTF::FileSystemImpl::directoryName): Deleted.
* wtf/FileSystem.h:

Tools:

* DumpRenderTree/win/DumpRenderTree.cpp:
(findFontFallback):
* TestWebKitAPI/Tests/WTF/FileSystem.cpp:
(TestWebKitAPI::TEST_F):
* TestWebKitAPI/win/PlatformUtilitiesWin.cpp:
(TestWebKitAPI::Util::moduleDirectory):


Canonical link: https://commits.webkit.org/237697@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277449 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed May 13, 2021
1 parent b737296 commit 503659938fbc736507c3bc3a14db7d588d9bdd1e
Showing 31 changed files with 162 additions and 35 deletions.
@@ -84,7 +84,7 @@ static bool validateBytecodeCachePath(NSURL* cachePath, NSError** error)
}
}

String directory = FileSystem::directoryName(systemPath);
String directory = FileSystem::parentPath(systemPath);
if (directory.isNull()) {
createError([NSString stringWithFormat:@"Cache path `%@` does not contain in a valid directory", static_cast<NSString *>(systemPath)], error);
return false;
@@ -1,3 +1,16 @@
2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::directoryName() to FileSystem::parentPath()
https://bugs.webkit.org/show_bug.cgi?id=225768

Reviewed by Darin Adler.

Rename FileSystem::directoryName() to FileSystem::parentPath() for clarity and
consistency with std::filesystem::parent_path() which is used internally.

* API/JSScript.mm:
(validateBytecodeCachePath):

2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::fileIsDirectory(path, followSymlinks) to isDirectory(path) / isDirectoryFollowingSymlinks(path)
@@ -1,3 +1,19 @@
2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::directoryName() to FileSystem::parentPath()
https://bugs.webkit.org/show_bug.cgi?id=225768

Reviewed by Darin Adler.

Rename FileSystem::directoryName() to FileSystem::parentPath() for clarity and
consistency with std::filesystem::parent_path() which is used internally.

* wtf/FileSystem.cpp:
(WTF::FileSystemImpl::readOrMakeSalt):
(WTF::FileSystemImpl::parentPath):
(WTF::FileSystemImpl::directoryName): Deleted.
* wtf/FileSystem.h:

2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::fileIsDirectory(path, followSymlinks) to isDirectory(path) / isDirectoryFollowingSymlinks(path)
@@ -518,7 +518,7 @@ Optional<Salt> readOrMakeSalt(const String& path)
}

Salt salt = makeSalt();
FileSystem::makeAllDirectories(FileSystem::directoryName(path));
FileSystem::makeAllDirectories(FileSystem::parentPath(path));
auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write, FileSystem::FileAccessPermission::User);
if (!FileSystem::isHandleValid(file))
return { };
@@ -744,7 +744,7 @@ String pathGetFileName(const String& path)
return fromStdFileSystemPath(toStdFileSystemPath(path).filename());
}

String directoryName(const String& path)
String parentPath(const String& path)
{
return fromStdFileSystemPath(toStdFileSystemPath(path).parent_path());
}
@@ -125,7 +125,7 @@ WTF_EXPORT_PRIVATE String lastComponentOfPathIgnoringTrailingSlash(const String&
WTF_EXPORT_PRIVATE bool makeAllDirectories(const String& path);
WTF_EXPORT_PRIVATE String homeDirectoryPath();
WTF_EXPORT_PRIVATE String pathGetFileName(const String&);
WTF_EXPORT_PRIVATE String directoryName(const String&);
WTF_EXPORT_PRIVATE String parentPath(const String&);
WTF_EXPORT_PRIVATE bool getVolumeFreeSpace(const String&, uint64_t&);
WTF_EXPORT_PRIVATE Optional<int32_t> getFileDeviceId(const CString&);
WTF_EXPORT_PRIVATE bool createSymbolicLink(const String& targetPath, const String& symbolicLinkPath);
@@ -1,3 +1,31 @@
2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::directoryName() to FileSystem::parentPath()
https://bugs.webkit.org/show_bug.cgi?id=225768

Reviewed by Darin Adler.

Rename FileSystem::directoryName() to FileSystem::parentPath() for clarity and
consistency with std::filesystem::parent_path() which is used internally.

* Modules/entriesapi/DOMFileSystem.cpp:
(WebCore::DOMFileSystem::DOMFileSystem):
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::writeDataToUniqueFileInDirectory):
(WebCore::ApplicationCacheStorage::checkForDeletedResources):
* platform/graphics/avfoundation/objc/CDMSessionAVContentKeySession.mm:
(WebCore::CDMSessionAVContentKeySession::contentKeySession):
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::purgeOldDownloadFiles):
* platform/network/curl/CookieJarDB.cpp:
(WebCore::CookieJarDB::openDatabase):
* platform/sql/SQLiteFileSystem.cpp:
(WebCore::SQLiteFileSystem::ensureDatabaseFileExists):
* platform/win/SearchPopupMenuDB.cpp:
(WebCore::SearchPopupMenuDB::openDatabase):
* workers/service/server/SWScriptStorage.cpp:
(WebCore::SWScriptStorage::store):

2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::fileIsDirectory(path, followSymlinks) to isDirectory(path) / isDirectoryFollowingSymlinks(path)
@@ -146,7 +146,7 @@ static bool isValidVirtualPath(StringView virtualPath)
DOMFileSystem::DOMFileSystem(Ref<File>&& file)
: m_name(createCanonicalUUIDString())
, m_file(WTFMove(file))
, m_rootPath(FileSystem::directoryName(m_file->path()))
, m_rootPath(FileSystem::parentPath(m_file->path()))
, m_workQueue(WorkQueue::create("DOMFileSystem work queue"))
{
ASSERT(!m_rootPath.endsWith('/'));
@@ -1291,7 +1291,7 @@ bool ApplicationCacheStorage::writeDataToUniqueFileInDirectory(SharedBuffer& dat
return false;

fullPath = FileSystem::pathByAppendingComponent(directory, path);
} while (FileSystem::directoryName(fullPath) != directory || FileSystem::fileExists(fullPath));
} while (FileSystem::parentPath(fullPath) != directory || FileSystem::fileExists(fullPath));

FileSystem::PlatformFileHandle handle = FileSystem::openFile(fullPath, FileSystem::FileOpenMode::Write);
if (!handle)
@@ -1431,7 +1431,7 @@ void ApplicationCacheStorage::checkForDeletedResources()

// Don't exit the flatFileDirectory! This should only happen if the "path" entry contains a directory
// component, but protect against it regardless.
if (FileSystem::directoryName(fullPath) != flatFileDirectory)
if (FileSystem::parentPath(fullPath) != flatFileDirectory)
continue;

FileSystem::deleteFile(fullPath);
@@ -379,7 +379,7 @@ static bool isEqual(Uint8Array* data, const char* literal)

m_contentKeySession = [PAL::getAVContentKeySessionClass() contentKeySessionWithKeySystem:AVContentKeySystemFairPlayStreaming];
} else {
String storageDirectory = FileSystem::directoryName(storagePath);
String storageDirectory = FileSystem::parentPath(storagePath);

if (!FileSystem::fileExists(storageDirectory)) {
if (!FileSystem::makeAllDirectories(storageDirectory))
@@ -2208,7 +2208,7 @@ void MediaPlayerPrivateGStreamer::purgeOldDownloadFiles(const String& downloadFi
if (downloadFilePrefixPath.isEmpty())
return;

auto templateDirectory = FileSystem::directoryName(downloadFilePrefixPath);
auto templateDirectory = FileSystem::parentPath(downloadFilePrefixPath);
auto templatePrefix = FileSystem::pathGetFileName(downloadFilePrefixPath);
for (auto& fileName : FileSystem::listDirectory(templateDirectory)) {
if (!fileName.startsWith(templatePrefix))
@@ -139,7 +139,7 @@ bool CookieJarDB::openDatabase()
}

if (!existsDatabaseFile) {
if (!FileSystem::makeAllDirectories(FileSystem::directoryName(m_databasePath)))
if (!FileSystem::makeAllDirectories(FileSystem::parentPath(m_databasePath)))
LOG_ERROR("Unable to create the Cookie Database path %s", m_databasePath.utf8().data());

m_database.open(m_databasePath);
@@ -65,7 +65,7 @@ bool SQLiteFileSystem::ensureDatabaseFileExists(const String& fileName, bool che
return false;

if (checkPathOnly) {
String dir = FileSystem::directoryName(fileName);
String dir = FileSystem::parentPath(fileName);
return ensureDatabaseDirectoryExists(dir);
}

@@ -188,7 +188,7 @@ bool SearchPopupMenuDB::openDatabase()
}

if (!existsDatabaseFile) {
if (!FileSystem::makeAllDirectories(FileSystem::directoryName(m_databaseFilename)))
if (!FileSystem::makeAllDirectories(FileSystem::parentPath(m_databaseFilename)))
LOG_ERROR("Failed to create the search autosave database path %s", m_databaseFilename.utf8().data());

m_database.open(m_databaseFilename);
@@ -84,7 +84,7 @@ ScriptBuffer SWScriptStorage::store(const ServiceWorkerRegistrationKey& registra
ASSERT(!isMainThread());

auto scriptPath = this->scriptPath(registrationKey, scriptURL);
FileSystem::makeAllDirectories(FileSystem::directoryName(scriptPath));
FileSystem::makeAllDirectories(FileSystem::parentPath(scriptPath));

auto iterateOverBufferAndWriteData = [&](const Function<bool(const uint8_t*, size_t)>& writeData) {
for (auto it = script.buffer()->begin(); it != script.buffer()->end(); ++it)
@@ -1,3 +1,30 @@
2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::directoryName() to FileSystem::parentPath()
https://bugs.webkit.org/show_bug.cgi?id=225768

Reviewed by Darin Adler.

Rename FileSystem::directoryName() to FileSystem::parentPath() for clarity and
consistency with std::filesystem::parent_path() which is used internally.

* NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp:
(WebKit::ResourceLoadStatisticsDatabaseStore::openITPDatabase):
* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::writeFile):
* Shared/glib/ProcessExecutablePathGLib.cpp:
(WebKit::getExecutablePath):
* UIProcess/API/glib/IconDatabase.cpp:
(WebKit::IconDatabase::IconDatabase):
* UIProcess/API/glib/WebKitWebsiteDataManager.cpp:
(webkit_website_data_manager_get_disk_cache_directory):
* UIProcess/Launcher/glib/BubblewrapLauncher.cpp:
(WebKit::bubblewrapSpawn):
* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::platformSetNetworkParameters):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::resolveDirectoriesIfNecessary):

2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::fileIsDirectory(path, followSymlinks) to isDirectory(path) / isDirectoryFollowingSymlinks(path)
@@ -369,7 +369,7 @@ void ResourceLoadStatisticsDatabaseStore::close()
void ResourceLoadStatisticsDatabaseStore::openITPDatabase()
{
if (!FileSystem::fileExists(m_storageDirectoryPath)) {
if (!FileSystem::makeAllDirectories(FileSystem::directoryName(m_storageDirectoryPath))) {
if (!FileSystem::makeAllDirectories(FileSystem::parentPath(m_storageDirectoryPath))) {
RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::open failed, error message: Failed to create directory database path: %" PUBLIC_LOG_STRING, this, m_storageDirectoryPath.utf8().data());
return;
}
@@ -463,7 +463,7 @@ void Engine::writeFile(const String& filename, NetworkCache::Data&& data, WebCor
m_pendingWriteCallbacks.add(++m_pendingCallbacksCounter, WTFMove(callback));
m_ioQueue->dispatch([this, weakThis = makeWeakPtr(this), identifier = m_pendingCallbacksCounter, data = WTFMove(data), filename = filename.isolatedCopy()]() mutable {

String directoryPath = FileSystem::directoryName(filename);
String directoryPath = FileSystem::parentPath(filename);
if (!FileSystem::fileExists(directoryPath))
FileSystem::makeAllDirectories(directoryPath);

@@ -38,7 +38,7 @@ static String getExecutablePath()
{
CString executablePath = getCurrentExecutablePath();
if (!executablePath.isNull())
return FileSystem::directoryName(FileSystem::stringFromFileSystemRepresentation(executablePath.data()));
return FileSystem::parentPath(FileSystem::stringFromFileSystemRepresentation(executablePath.data()));
return { };
}
#endif
@@ -59,7 +59,7 @@ IconDatabase::IconDatabase(const String& path, AllowDatabaseWrite allowDatabaseW
if (allowDatabaseWrite == AllowDatabaseWrite::No && !FileSystem::fileExists(path))
return;

auto databaseDirectory = FileSystem::directoryName(path);
auto databaseDirectory = FileSystem::parentPath(path);
FileSystem::makeAllDirectories(databaseDirectory);
if (!m_db.open(path)) {
LOG_ERROR("Unable to open favicon database at path %s - %s", path.utf8().data(), m_db.lastErrorMsg());
@@ -633,7 +633,7 @@ const gchar* webkit_website_data_manager_get_disk_cache_directory(WebKitWebsiteD

if (!priv->diskCacheDirectory) {
// The default directory already has the subdirectory.
priv->diskCacheDirectory.reset(g_strdup(FileSystem::directoryName(WebKit::WebsiteDataStore::defaultNetworkCacheDirectory()).utf8().data()));
priv->diskCacheDirectory.reset(g_strdup(FileSystem::parentPath(WebKit::WebsiteDataStore::defaultNetworkCacheDirectory()).utf8().data()));
}
return priv->diskCacheDirectory.get();
}
@@ -900,14 +900,14 @@ GRefPtr<GSubprocess> bubblewrapSpawn(GSubprocessLauncher* launcher, const Proces
#if ENABLE(DEVELOPER_MODE)
const char* execDirectory = g_getenv("WEBKIT_EXEC_PATH");
if (execDirectory) {
String parentDir = FileSystem::directoryName(FileSystem::stringFromFileSystemRepresentation(execDirectory));
String parentDir = FileSystem::parentPath(FileSystem::stringFromFileSystemRepresentation(execDirectory));
bindIfExists(sandboxArgs, parentDir.utf8().data());
}

CString executablePath = getCurrentExecutablePath();
if (!executablePath.isNull()) {
// Our executable is `/foo/bar/bin/Process`, we want `/foo/bar` as a usable prefix
String parentDir = FileSystem::directoryName(FileSystem::directoryName(FileSystem::stringFromFileSystemRepresentation(executablePath.data())));
String parentDir = FileSystem::parentPath(FileSystem::parentPath(FileSystem::stringFromFileSystemRepresentation(executablePath.data())));
bindIfExists(sandboxArgs, parentDir.utf8().data());
}
#endif
@@ -192,7 +192,7 @@
parameters.uiProcessCookieStorageIdentifier = m_uiProcessCookieStorageIdentifier;

if (!cookieFile.isEmpty())
SandboxExtension::createHandleForReadWriteDirectory(FileSystem::directoryName(cookieFile), parameters.cookieStoragePathExtensionHandle);
SandboxExtension::createHandleForReadWriteDirectory(FileSystem::parentPath(cookieFile), parameters.cookieStoragePathExtensionHandle);
}

#if HAVE(CFNETWORK_ALTERNATIVE_SERVICE) || HAVE(NETWORK_LOADER)
@@ -268,7 +268,7 @@ void WebsiteDataStore::resolveDirectoriesIfNecessary()

// Resolve directories for file paths.
if (!m_configuration->cookieStorageFile().isEmpty()) {
m_resolvedConfiguration->setCookieStorageFile(resolveAndCreateReadWriteDirectoryForSandboxExtension(FileSystem::directoryName(m_configuration->cookieStorageFile())));
m_resolvedConfiguration->setCookieStorageFile(resolveAndCreateReadWriteDirectoryForSandboxExtension(FileSystem::parentPath(m_configuration->cookieStorageFile())));
m_resolvedConfiguration->setCookieStorageFile(FileSystem::pathByAppendingComponent(m_resolvedConfiguration->cookieStorageFile(), FileSystem::pathGetFileName(m_configuration->cookieStorageFile())));
}
}
@@ -1,3 +1,16 @@
2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::directoryName() to FileSystem::parentPath()
https://bugs.webkit.org/show_bug.cgi?id=225768

Reviewed by Darin Adler.

Rename FileSystem::directoryName() to FileSystem::parentPath() for clarity and
consistency with std::filesystem::parent_path() which is used internally.

* Storage/StorageTracker.cpp:
(WebKit::ensureDatabaseFileExists):

2021-05-11 Chris Dumez <cdumez@apple.com>

Port WTF::FileSystem::listDirectory to std::filesystem
@@ -113,7 +113,7 @@ String StorageTracker::trackerDatabasePath()
static bool ensureDatabaseFileExists(const String& fileName, bool createIfDoesNotExist)
{
if (createIfDoesNotExist)
return FileSystem::makeAllDirectories(FileSystem::directoryName(fileName));
return FileSystem::makeAllDirectories(FileSystem::parentPath(fileName));

return FileSystem::fileExists(fileName);
}
@@ -1,3 +1,16 @@
2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::directoryName() to FileSystem::parentPath()
https://bugs.webkit.org/show_bug.cgi?id=225768

Reviewed by Darin Adler.

Rename FileSystem::directoryName() to FileSystem::parentPath() for clarity and
consistency with std::filesystem::parent_path() which is used internally.

* Plugins/PluginDatabase.cpp:
(WebCore::PluginDatabase::loadPersistentMetadataCache):

2021-05-13 Darin Adler <darin@apple.com>

Remove StringBuilder::appendNumber
@@ -515,7 +515,7 @@ void PluginDatabase::loadPersistentMetadataCache()

// Skip metadata that points to plugins from directories that
// are not part of plugin directory list anymore.
String pluginDirectoryName = FileSystem::directoryName(path);
String pluginDirectoryName = FileSystem::parentPath(path);
if (m_pluginDirectories.find(pluginDirectoryName) == WTF::notFound)
continue;

@@ -1,3 +1,20 @@
2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::directoryName() to FileSystem::parentPath()
https://bugs.webkit.org/show_bug.cgi?id=225768

Reviewed by Darin Adler.

Rename FileSystem::directoryName() to FileSystem::parentPath() for clarity and
consistency with std::filesystem::parent_path() which is used internally.

* DumpRenderTree/win/DumpRenderTree.cpp:
(findFontFallback):
* TestWebKitAPI/Tests/WTF/FileSystem.cpp:
(TestWebKitAPI::TEST_F):
* TestWebKitAPI/win/PlatformUtilitiesWin.cpp:
(TestWebKitAPI::Util::moduleDirectory):

2021-05-13 Chris Dumez <cdumez@apple.com>

Rename FileSystem::fileIsDirectory(path, followSymlinks) to isDirectory(path) / isDirectoryFollowingSymlinks(path)
@@ -1106,7 +1106,7 @@ static void sizeWebViewForCurrentTest()

static String findFontFallback(const char* pathOrUrl)
{
String pathToFontFallback = FileSystem::directoryName(pathOrUrl);
String pathToFontFallback = FileSystem::parentPath(pathOrUrl);

wchar_t fullPath[_MAX_PATH];
if (!_wfullpath(fullPath, pathToFontFallback.wideCharacters().data(), _MAX_PATH))

0 comments on commit 5036599

Please sign in to comment.