Skip to content

Commit 72d1917

Browse files
committed
Drop FileSystem::fileMetadata() / fileMetadataFollowingSymlinks()
https://bugs.webkit.org/show_bug.cgi?id=225820 Reviewed by Darin Adler. Source/JavaScriptCore: Update our code base because of the FileSystem API changes. * API/JSScript.mm: (validateBytecodeCachePath): Source/WebCore: Update our code base because of the FileSystem API changes. * Modules/entriesapi/DOMFileSystem.cpp: (WebCore::listDirectoryWithMetadata): (WebCore::toFileSystemEntries): (WebCore::fileTypeIgnoringHiddenFiles): (WebCore::validatePathIsExpectedType): (WebCore::DOMFileSystem::getParent): (WebCore::DOMFileSystem::getEntry): (WebCore::DOMFileSystem::getFile): * editing/cocoa/WebContentReaderCocoa.mm: (WebCore::attachmentForFilePath): * fileapi/File.cpp: (WebCore::File::isDirectory const): * html/DirectoryFileListCreator.cpp: (WebCore::appendDirectoryFiles): (WebCore::gatherFileInformation): * platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm: (WebCore::CDMInstanceFairPlayStreamingAVFObjC::setStorageDirectory): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::ensureAssetCacheExistsForPath): * platform/network/BlobDataFileReference.cpp: (WebCore::BlobDataFileReference::startTrackingModifications): * platform/network/BlobRegistryImpl.cpp: * platform/network/FormData.cpp: (WebCore::FormData::prepareForUpload): * platform/network/mac/BlobDataFileReferenceMac.mm: (WebCore::BlobDataFileReference::generateReplacementFile): Source/WebKit: Update our code base because of the FileSystem API changes. * NetworkProcess/cache/CacheStorageEngine.cpp: (WebKit::CacheStorage::getDirectorySize): (WebKit::CacheStorage::Engine::getDirectories): (WebKit::CacheStorage::Engine::clearAllCachesFromDisk): * NetworkProcess/cache/NetworkCacheFileSystem.cpp: (WebKit::NetworkCache::traverseDirectory): * Shared/mac/AuxiliaryProcessMac.mm: (WebKit::ensureSandboxCacheDirectory): * UIProcess/Cocoa/WebProcessPoolCocoa.mm: (WebKit::isInternalInstall): Source/WTF: Drop FileSystem::fileMetadata() / fileMetadataFollowingSymlinks(). Those don't match very closely the std::filesystem API we use internally and they are not very efficient because we gather several attributes of a file but the callers are usually only interested in one thing (e.g. file type or file size). Callers interested in the file size, can call the pre-existing FileSystem::fileSize(). For call sites wanting to check if it is a hidden file, I introduced a new FileSystem::isHiddenFile() API. For call sites interested in the file type, I replaced FileSystem::isDirectory() / FileSystem::isDirectoryFollowingSymlinks() with more generic FileSystem::fileType() / FileSystem::fileTypeFollowingSymlinks(). * WTF.xcodeproj/project.pbxproj: * wtf/CMakeLists.txt: * wtf/FileMetadata.h: Removed. * wtf/FileSystem.cpp: (WTF::FileSystemImpl::isHiddenFile): (WTF::FileSystemImpl::fileTypePotentiallyFollowingSymLinks): (WTF::FileSystemImpl::fileType): (WTF::FileSystemImpl::fileTypeFollowingSymlinks): * wtf/FileSystem.h: * wtf/glib/FileSystemGlib.cpp: * wtf/posix/FileSystemPOSIX.cpp: * wtf/win/FileSystemWin.cpp: Tools: Update the FileSystem API tests accordingly. * TestWebKitAPI/Tests/WTF/FileSystem.cpp: (TestWebKitAPI::TEST_F): Canonical link: https://commits.webkit.org/237763@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@277535 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 1a957c6 commit 72d1917

29 files changed

Lines changed: 276 additions & 354 deletions

‎Source/JavaScriptCore/API/JSScript.mm‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#import "JSVirtualMachineInternal.h"
3939
#import "Symbol.h"
4040
#import <sys/stat.h>
41-
#import <wtf/FileMetadata.h>
4241
#import <wtf/FileSystem.h>
4342
#import <wtf/SHA1.h>
4443
#import <wtf/Scope.h>
@@ -77,8 +76,8 @@ static bool validateBytecodeCachePath(NSURL* cachePath, NSError** error)
7776

7877
String systemPath = cachePathURL.fileSystemPath();
7978

80-
if (auto metadata = FileSystem::fileMetadata(systemPath)) {
81-
if (metadata->type != FileMetadata::Type::File) {
79+
if (auto fileType = FileSystem::fileType(systemPath)) {
80+
if (*fileType != FileSystem::FileType::Regular) {
8281
createError([NSString stringWithFormat:@"Cache path `%@` already exists and is not a file", static_cast<NSString *>(systemPath)], error);
8382
return false;
8483
}
@@ -90,7 +89,7 @@ static bool validateBytecodeCachePath(NSURL* cachePath, NSError** error)
9089
return false;
9190
}
9291

93-
if (!FileSystem::isDirectory(directory)) {
92+
if (FileSystem::fileType(directory) != FileSystem::FileType::Directory) {
9493
createError([NSString stringWithFormat:@"Cache directory `%@` is not a directory or does not exist", static_cast<NSString *>(directory)], error);
9594
return false;
9695
}

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2021-05-14 Chris Dumez <cdumez@apple.com>
2+
3+
Drop FileSystem::fileMetadata() / fileMetadataFollowingSymlinks()
4+
https://bugs.webkit.org/show_bug.cgi?id=225820
5+
6+
Reviewed by Darin Adler.
7+
8+
Update our code base because of the FileSystem API changes.
9+
10+
* API/JSScript.mm:
11+
(validateBytecodeCachePath):
12+
113
2021-05-14 Ross Kirsling <ross.kirsling@sony.com>
214

315
REGRESSION (r277221): 2 test262 tests failing

‎Source/WTF/ChangeLog‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
2021-05-14 Chris Dumez <cdumez@apple.com>
2+
3+
Drop FileSystem::fileMetadata() / fileMetadataFollowingSymlinks()
4+
https://bugs.webkit.org/show_bug.cgi?id=225820
5+
6+
Reviewed by Darin Adler.
7+
8+
Drop FileSystem::fileMetadata() / fileMetadataFollowingSymlinks(). Those don't match very closely the
9+
std::filesystem API we use internally and they are not very efficient because we gather several attributes
10+
of a file but the callers are usually only interested in one thing (e.g. file type or file size).
11+
12+
Callers interested in the file size, can call the pre-existing FileSystem::fileSize(). For call sites
13+
wanting to check if it is a hidden file, I introduced a new FileSystem::isHiddenFile() API. For call sites
14+
interested in the file type, I replaced FileSystem::isDirectory() / FileSystem::isDirectoryFollowingSymlinks()
15+
with more generic FileSystem::fileType() / FileSystem::fileTypeFollowingSymlinks().
16+
17+
* WTF.xcodeproj/project.pbxproj:
18+
* wtf/CMakeLists.txt:
19+
* wtf/FileMetadata.h: Removed.
20+
* wtf/FileSystem.cpp:
21+
(WTF::FileSystemImpl::isHiddenFile):
22+
(WTF::FileSystemImpl::fileTypePotentiallyFollowingSymLinks):
23+
(WTF::FileSystemImpl::fileType):
24+
(WTF::FileSystemImpl::fileTypeFollowingSymlinks):
25+
* wtf/FileSystem.h:
26+
* wtf/glib/FileSystemGlib.cpp:
27+
* wtf/posix/FileSystemPOSIX.cpp:
28+
* wtf/win/FileSystemWin.cpp:
29+
130
2021-05-14 Chris Dumez <cdumez@apple.com>
231

332
Drop legacy / prefixed WebAudio implementation

‎Source/WTF/WTF.xcodeproj/project.pbxproj‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@
512512
A30D412C1F0DE0BA00B71954 /* SoftLinking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SoftLinking.h; sourceTree = "<group>"; };
513513
A30D412D1F0DE13F00B71954 /* SoftLinking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SoftLinking.h; sourceTree = "<group>"; };
514514
A32D8FA421FFFAB400780662 /* ThreadingPOSIX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadingPOSIX.cpp; sourceTree = "<group>"; };
515-
A331D95821F24978009F02AA /* FileMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileMetadata.h; sourceTree = "<group>"; };
516515
A331D95921F24992009F02AA /* FileSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystem.h; sourceTree = "<group>"; };
517516
A331D95A21F24992009F02AA /* FileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystem.cpp; sourceTree = "<group>"; };
518517
A331D95C21F249E4009F02AA /* FileSystemCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystemCF.cpp; sourceTree = "<group>"; };
@@ -1039,7 +1038,6 @@
10391038
A8A472A1151A825A004123FF /* FastMalloc.cpp */,
10401039
A8A472A2151A825A004123FF /* FastMalloc.h */,
10411040
0F79C7C31E73511800EB34D1 /* FastTLS.h */,
1042-
A331D95821F24978009F02AA /* FileMetadata.h */,
10431041
0F9D335B165DBA73005AD387 /* FilePrintStream.cpp */,
10441042
0F9D335C165DBA73005AD387 /* FilePrintStream.h */,
10451043
A331D95A21F24992009F02AA /* FileSystem.cpp */,

‎Source/WTF/wtf/CMakeLists.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ set(WTF_PUBLIC_HEADERS
6868
FastBitVector.h
6969
FastMalloc.h
7070
FastTLS.h
71-
FileMetadata.h
7271
FilePrintStream.h
7372
FileSystem.h
7473
FixedVector.h

‎Source/WTF/wtf/FileMetadata.h‎

Lines changed: 0 additions & 54 deletions
This file was deleted.

‎Source/WTF/wtf/FileSystem.cpp‎

Lines changed: 26 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <wtf/FileSystem.h>
2929

3030
#include <wtf/CryptographicallyRandomNumber.h>
31-
#include <wtf/FileMetadata.h>
3231
#include <wtf/HexNumber.h>
3332
#include <wtf/Scope.h>
3433
#include <wtf/StdFilesystem.h>
@@ -139,20 +138,6 @@ static WallTime toWallTime(std::filesystem::file_time_type fileTime)
139138
return WallTime::fromRawSeconds(toTimeT(fileTime));
140139
}
141140

142-
static std::filesystem::path resolveSymlinks(std::filesystem::path path, std::error_code& ec)
143-
{
144-
#ifdef MAXSYMLINKS
145-
static constexpr unsigned maxSymlinkDepth = MAXSYMLINKS;
146-
#else
147-
static constexpr unsigned maxSymlinkDepth = 40;
148-
#endif
149-
150-
unsigned currentDepth = 0;
151-
while (++currentDepth <= maxSymlinkDepth && !ec && std::filesystem::is_symlink(path, ec))
152-
path = std::filesystem::read_symlink(path, ec);
153-
return path;
154-
}
155-
156141
String encodeForFileName(const String& inputString)
157142
{
158143
unsigned length = inputString.length();
@@ -606,18 +591,6 @@ Optional<uint64_t> fileSize(const String& path)
606591
return size;
607592
}
608593

609-
bool isDirectory(const String& path)
610-
{
611-
std::error_code ec;
612-
return std::filesystem::symlink_status(toStdFileSystemPath(path), ec).type() == std::filesystem::file_type::directory;
613-
}
614-
615-
bool isDirectoryFollowingSymlinks(const String& path)
616-
{
617-
std::error_code ec;
618-
return std::filesystem::status(toStdFileSystemPath(path), ec).type() == std::filesystem::file_type::directory;
619-
}
620-
621594
bool makeAllDirectories(const String& path)
622595
{
623596
std::error_code ec;
@@ -692,56 +665,44 @@ bool updateFileModificationTime(const String& path)
692665
return !ec;
693666
}
694667

695-
enum class ShouldFollowSymbolicLinks { No, Yes };
696-
static Optional<FileMetadata> fileMetadataPotentiallyFollowingSymlinks(const String& path, ShouldFollowSymbolicLinks shouldFollowSymbolicLinks)
668+
bool isHiddenFile(const String& path)
697669
{
698-
if (path.isEmpty())
699-
return WTF::nullopt;
700-
701-
auto fsPath = toStdFileSystemPath(path);
702-
703-
std::error_code ec;
704-
if (shouldFollowSymbolicLinks == ShouldFollowSymbolicLinks::Yes && std::filesystem::is_symlink(fsPath, ec)) {
705-
fsPath = resolveSymlinks(fsPath, ec);
706-
if (ec)
707-
return WTF::nullopt;
708-
}
709-
710-
ec = { };
711-
std::filesystem::directory_entry entry(fsPath, ec);
712-
if (ec)
713-
return WTF::nullopt;
714-
715-
auto modificationTime = toWallTime(entry.last_write_time(ec));
716-
717-
// Note that the result of attempting to determine the size of a directory is implementation-defined.
718-
auto fileSize = entry.file_size(ec);
719-
if (ec)
720-
fileSize = 0;
721-
722670
#if OS(UNIX)
671+
auto fsPath = toStdFileSystemPath(path);
723672
std::filesystem::path::string_type filename = fsPath.filename();
724-
bool isHidden = !filename.empty() && filename[0] == '.';
673+
return !filename.empty() && filename[0] == '.';
725674
#else
726-
bool isHidden = false;
675+
UNUSED_PARAM(path);
676+
return false;
727677
#endif
728-
FileMetadata::Type type = FileMetadata::Type::File;
729-
if (entry.is_symlink(ec))
730-
type = FileMetadata::Type::SymbolicLink;
731-
else if (entry.is_directory(ec))
732-
type = FileMetadata::Type::Directory;
678+
}
733679

734-
return FileMetadata { modificationTime, static_cast<long long>(fileSize), isHidden, type };
680+
enum class ShouldFollowSymbolicLinks { No, Yes };
681+
static Optional<FileType> fileTypePotentiallyFollowingSymLinks(const String& path, ShouldFollowSymbolicLinks shouldFollowSymbolicLinks)
682+
{
683+
std::error_code ec;
684+
auto status = shouldFollowSymbolicLinks == ShouldFollowSymbolicLinks::Yes ? std::filesystem::status(toStdFileSystemPath(path), ec) : std::filesystem::symlink_status(toStdFileSystemPath(path), ec);
685+
if (ec)
686+
return WTF::nullopt;
687+
switch (status.type()) {
688+
case std::filesystem::file_type::directory:
689+
return FileType::Directory;
690+
case std::filesystem::file_type::symlink:
691+
return FileType::SymbolicLink;
692+
default:
693+
break;
694+
}
695+
return FileType::Regular;
735696
}
736697

737-
Optional<FileMetadata> fileMetadata(const String& path)
698+
Optional<FileType> fileType(const String& path)
738699
{
739-
return fileMetadataPotentiallyFollowingSymlinks(path, ShouldFollowSymbolicLinks::No);
700+
return fileTypePotentiallyFollowingSymLinks(path, ShouldFollowSymbolicLinks::No);
740701
}
741702

742-
Optional<FileMetadata> fileMetadataFollowingSymlinks(const String& path)
703+
Optional<FileType> fileTypeFollowingSymlinks(const String& path)
743704
{
744-
return fileMetadataPotentiallyFollowingSymlinks(path, ShouldFollowSymbolicLinks::Yes);
705+
return fileTypePotentiallyFollowingSymLinks(path, ShouldFollowSymbolicLinks::Yes);
745706
}
746707

747708
String pathFileName(const String& path)

‎Source/WTF/wtf/FileSystem.h‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ typedef struct _GFileIOStream GFileIOStream;
5858

5959
namespace WTF {
6060

61-
struct FileMetadata;
62-
6361
namespace FileSystemImpl {
6462

6563
// PlatformFileHandle
@@ -111,15 +109,12 @@ WTF_EXPORT_PRIVATE bool fileExists(const String&);
111109
WTF_EXPORT_PRIVATE bool deleteFile(const String&);
112110
WTF_EXPORT_PRIVATE bool deleteEmptyDirectory(const String&);
113111
WTF_EXPORT_PRIVATE bool moveFile(const String& oldPath, const String& newPath);
114-
WTF_EXPORT_PRIVATE Optional<uint64_t> fileSize(const String&);
112+
WTF_EXPORT_PRIVATE Optional<uint64_t> fileSize(const String&); // Follows symlinks.
115113
WTF_EXPORT_PRIVATE Optional<uint64_t> fileSize(PlatformFileHandle);
116114
WTF_EXPORT_PRIVATE Optional<WallTime> fileModificationTime(const String&);
117115
WTF_EXPORT_PRIVATE bool updateFileModificationTime(const String& path); // Sets modification time to now.
118116
WTF_EXPORT_PRIVATE Optional<WallTime> fileCreationTime(const String&); // Not all platforms store file creation time.
119-
WTF_EXPORT_PRIVATE Optional<FileMetadata> fileMetadata(const String& path);
120-
WTF_EXPORT_PRIVATE Optional<FileMetadata> fileMetadataFollowingSymlinks(const String& path);
121-
WTF_EXPORT_PRIVATE bool isDirectory(const String&);
122-
WTF_EXPORT_PRIVATE bool isDirectoryFollowingSymlinks(const String&);
117+
WTF_EXPORT_PRIVATE bool isHiddenFile(const String&);
123118
WTF_EXPORT_PRIVATE String pathByAppendingComponent(const String& path, const String& component);
124119
WTF_EXPORT_PRIVATE String pathByAppendingComponents(StringView path, const Vector<StringView>& components);
125120
WTF_EXPORT_PRIVATE String lastComponentOfPathIgnoringTrailingSlash(const String& path);
@@ -131,6 +126,10 @@ WTF_EXPORT_PRIVATE Optional<int32_t> getFileDeviceId(const CString&);
131126
WTF_EXPORT_PRIVATE bool createSymbolicLink(const String& targetPath, const String& symbolicLinkPath);
132127
WTF_EXPORT_PRIVATE String createTemporaryZipArchive(const String& directory);
133128

129+
enum class FileType { Regular, Directory, SymbolicLink };
130+
WTF_EXPORT_PRIVATE Optional<FileType> fileType(const String&);
131+
WTF_EXPORT_PRIVATE Optional<FileType> fileTypeFollowingSymlinks(const String&);
132+
134133
WTF_EXPORT_PRIVATE void setMetadataURL(const String& path, const String& urlString, const String& referrer = { });
135134

136135
bool canExcludeFromBackup(); // Returns true if any file can ever be excluded from backup.

‎Source/WTF/wtf/glib/FileSystemGlib.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <glib/gstdio.h>
3030
#include <sys/file.h>
3131
#include <wtf/EnumTraits.h>
32-
#include <wtf/FileMetadata.h>
3332
#include <wtf/UUID.h>
3433
#include <wtf/glib/GLibUtilities.h>
3534
#include <wtf/glib/GRefPtr.h>

‎Source/WTF/wtf/posix/FileSystemPOSIX.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <sys/types.h>
4141
#include <unistd.h>
4242
#include <wtf/EnumTraits.h>
43-
#include <wtf/FileMetadata.h>
4443
#include <wtf/text/CString.h>
4544
#include <wtf/text/StringBuilder.h>
4645
#include <wtf/text/WTFString.h>

0 commit comments

Comments
 (0)