Changeset 257518 in webkit
- Timestamp:
- Feb 26, 2020 2:41:40 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r257517 r257518 1 2020-02-26 Christopher Reid <chris.reid@sony.com> 2 3 [Win] Implement NetworkCache::Data by using FileSystem::MappedFileData 4 https://bugs.webkit.org/show_bug.cgi?id=197684 5 <rdar://problem/59467397> 6 7 Reviewed by Yusuke Suzuki. 8 9 * platform/wincairo/TestExpectations: 10 1 11 2020-02-26 Jason Lawrence <lawrence.j@apple.com> 2 12 -
trunk/LayoutTests/platform/wincairo/TestExpectations
r256700 r257518 1162 1162 http/tests/appcache [ Skip ] 1163 1163 http/tests/blink/sendbeacon [ Skip ] 1164 http/tests/cache [ Skip ] 1164 1165 # needs more investigation 1166 http/tests/cache/cancel-multiple-post-xhrs.html [ Failure ] 1167 1168 # fails because of conversion to epoch behavior specific to Mac 1169 http/tests/cache/disk-cache/disk-cache-last-modified.html [ Failure ] 1170 1171 # needs more investigation 1172 http/tests/cache/iframe-304-crash.html [ Failure ] 1173 http/tests/cache/network-error-during-revalidation.html [ Failure ] 1174 http/tests/cache/partitioned-cache-iframe.html [ Failure ] 1175 http/tests/cache/partitioned-cache.html [ Failure ] 1176 http/tests/cache/willsendrequest-returns-null-for-memory-cache-load.html [ Failure ] 1177 1165 1178 http/tests/cache-storage [ Skip ] 1166 1179 http/tests/canvas [ Skip ] -
trunk/Source/WTF/ChangeLog
r257410 r257518 1 2020-02-26 Christopher Reid <chris.reid@sony.com> 2 3 [Win] Implement NetworkCache::Data by using FileSystem::MappedFileData 4 https://bugs.webkit.org/show_bug.cgi?id=197684 5 <rdar://problem/59467397> 6 7 Reviewed by Yusuke Suzuki. 8 9 * wtf/FileSystem.cpp: 10 * wtf/FileSystem.h: 11 Added FileAccessPermission flag when opening files. 12 Remove default argument for the listDirectory filter since the defaut 13 String() filter doesn't match all files on Mac and Windows. 14 15 Added FileOpenMode::ReadWrite to be used with ReadWrite MappedFileData. 16 Added failIfFileExists flag to openFile. 17 18 * wtf/glib/FileSystemGlib.cpp: 19 * wtf/posix/FileSystemPOSIX.cpp: 20 Added (S_IRUSR | S_IWUSR) file open modes. 21 22 * wtf/win/FileSystemWin.cpp: 23 Implement getVolumeFreeSpace since some of the tests use it when toggling cache. 24 25 * wtf/win/PathWalker.cpp: 26 1 27 2020-02-25 Devin Rousso <drousso@apple.com> 2 28 -
trunk/Source/WTF/wtf/FileSystem.cpp
r256700 r257518 288 288 } 289 289 290 MappedFileData::MappedFileData(const String& filePath, MappedFileMode mapMode, bool& success) 291 { 292 auto fd = openFile(filePath, FileSystem::FileOpenMode::Read); 293 294 success = mapFileHandle(fd, FileSystem::FileOpenMode::Read, mapMode); 295 closeFile(fd); 296 } 297 290 298 #if HAVE(MMAP) 291 299 292 MappedFileData::MappedFileData(const String& filePath, MappedFileMode mode, bool& success) 293 { 294 auto fd = openFile(filePath, FileOpenMode::Read); 295 296 success = mapFileHandle(fd, mode); 297 closeFile(fd); 298 } 299 300 bool MappedFileData::mapFileHandle(PlatformFileHandle handle, MappedFileMode mode) 300 bool MappedFileData::mapFileHandle(PlatformFileHandle handle, FileOpenMode openMode, MappedFileMode mapMode) 301 301 { 302 302 if (!isHandleValid(handle)) … … 325 325 } 326 326 327 void* data = mmap(0, size, PROT_READ, MAP_FILE | (mode == MappedFileMode::Shared ? MAP_SHARED : MAP_PRIVATE), fd, 0); 327 int pageProtection = PROT_READ; 328 switch (openMode) { 329 case FileOpenMode::Read: 330 pageProtection = PROT_READ; 331 break; 332 case FileOpenMode::Write: 333 pageProtection = PROT_WRITE; 334 break; 335 case FileOpenMode::ReadWrite: 336 pageProtection = PROT_READ | PROT_WRITE; 337 break; 338 #if OS(DARWIN) 339 case FileOpenMode::EventsOnly: 340 ASSERT_NOT_REACHED(); 341 #endif 342 } 343 344 void* data = mmap(0, size, pageProtection, MAP_FILE | (mapMode == MappedFileMode::Shared ? MAP_SHARED : MAP_PRIVATE), fd, 0); 328 345 329 346 if (data == MAP_FAILED) { -
trunk/Source/WTF/wtf/FileSystem.h
r256700 r257518 80 80 Read, 81 81 Write, 82 ReadWrite, 82 83 #if OS(DARWIN) 83 84 EventsOnly, 84 85 #endif 86 }; 87 88 enum class FileAccessPermission : bool { 89 User, 90 All 85 91 }; 86 92 … … 132 138 bool excludeFromBackup(const String&); // Returns true if successful. 133 139 134 WTF_EXPORT_PRIVATE Vector<String> listDirectory(const String& path, const String& filter = String());140 WTF_EXPORT_PRIVATE Vector<String> listDirectory(const String& path, const String& filter); 135 141 136 142 WTF_EXPORT_PRIVATE CString fileSystemRepresentation(const String&); … … 141 147 // Prefix is what the filename should be prefixed with, not the full path. 142 148 WTF_EXPORT_PRIVATE String openTemporaryFile(const String& prefix, PlatformFileHandle&); 143 WTF_EXPORT_PRIVATE PlatformFileHandle openFile(const String& path, FileOpenMode );149 WTF_EXPORT_PRIVATE PlatformFileHandle openFile(const String& path, FileOpenMode, FileAccessPermission = FileAccessPermission::All, bool failIfFileExists = false); 144 150 WTF_EXPORT_PRIVATE void closeFile(PlatformFileHandle&); 145 151 // Returns the resulting offset from the beginning of the file if successful, -1 otherwise. … … 207 213 WTF_EXPORT_PRIVATE MappedFileData(const String& filePath, MappedFileMode, bool& success); 208 214 WTF_EXPORT_PRIVATE MappedFileData(PlatformFileHandle, MappedFileMode, bool& success); 215 WTF_EXPORT_PRIVATE MappedFileData(PlatformFileHandle, FileOpenMode, MappedFileMode, bool& success); 209 216 WTF_EXPORT_PRIVATE ~MappedFileData(); 210 217 MappedFileData& operator=(MappedFileData&&); … … 217 224 218 225 private: 219 WTF_EXPORT_PRIVATE bool mapFileHandle(PlatformFileHandle, MappedFileMode);226 WTF_EXPORT_PRIVATE bool mapFileHandle(PlatformFileHandle, FileOpenMode, MappedFileMode); 220 227 221 228 void* m_fileData { nullptr }; … … 223 230 }; 224 231 225 inline MappedFileData::MappedFileData(PlatformFileHandle handle, MappedFileMode mode, bool& success) 226 { 227 success = mapFileHandle(handle, mode); 232 inline MappedFileData::MappedFileData(PlatformFileHandle handle, MappedFileMode mapMode, bool& success) 233 { 234 success = mapFileHandle(handle, FileOpenMode::Read, mapMode); 235 } 236 237 inline MappedFileData::MappedFileData(PlatformFileHandle handle, FileOpenMode openMode, MappedFileMode mapMode, bool& success) 238 { 239 success = mapFileHandle(handle, openMode, mapMode); 228 240 } 229 241 -
trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp
r256700 r257518 339 339 } 340 340 341 PlatformFileHandle openFile(const String& path, FileOpenMode mode )341 PlatformFileHandle openFile(const String& path, FileOpenMode mode, FileAccessPermission permission, bool failIfFileExists) 342 342 { 343 343 auto filename = fileSystemRepresentation(path); … … 347 347 GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(filename.data())); 348 348 GRefPtr<GFileIOStream> ioStream; 349 GFileCreateFlags permissionFlag = (permission == FileAccessPermission::All) ? G_FILE_CREATE_NONE : G_FILE_CREATE_PRIVATE; 350 351 if (failIfFileExists) { 352 ioStream = adoptGRef(g_file_create_readwrite(file.get(), permissionFlag, nullptr, nullptr)); 353 return ioStream.leakRef(); 354 } 355 349 356 if (mode == FileOpenMode::Read) 350 357 ioStream = adoptGRef(g_file_open_readwrite(file.get(), nullptr, nullptr)); 351 else if (mode == FileOpenMode::Write ) {358 else if (mode == FileOpenMode::Write || mode == FileOpenMode::ReadWrite) { 352 359 if (g_file_test(filename.data(), static_cast<GFileTest>(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) 353 360 ioStream = adoptGRef(g_file_open_readwrite(file.get(), nullptr, nullptr)); 354 361 else 355 ioStream = adoptGRef(g_file_create_readwrite(file.get(), G_FILE_CREATE_NONE, nullptr, nullptr));362 ioStream = adoptGRef(g_file_create_readwrite(file.get(), permissionFlag, nullptr, nullptr)); 356 363 } 357 364 -
trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp
r256700 r257518 80 80 } 81 81 82 PlatformFileHandle openFile(const String& path, FileOpenMode mode )82 PlatformFileHandle openFile(const String& path, FileOpenMode mode, FileAccessPermission permission, bool failIfFileExists) 83 83 { 84 84 CString fsRep = fileSystemRepresentation(path); … … 88 88 89 89 int platformFlag = 0; 90 if (mode == FileOpenMode::Read) 90 switch (mode) { 91 case FileOpenMode::Read: 91 92 platformFlag |= O_RDONLY; 92 else if (mode == FileOpenMode::Write) 93 break; 94 case FileOpenMode::Write: 93 95 platformFlag |= (O_WRONLY | O_CREAT | O_TRUNC); 96 break; 97 case FileOpenMode::ReadWrite: 98 platformFlag |= (O_RDWR | O_CREAT); 99 break; 94 100 #if OS(DARWIN) 95 else if (mode == FileOpenMode::EventsOnly)101 case FileOpenMode::EventsOnly: 96 102 platformFlag |= O_EVTONLY; 103 break; 97 104 #endif 98 99 return open(fsRep.data(), platformFlag, 0666); 105 } 106 107 if (failIfFileExists) 108 platformFlag |= (O_CREAT | O_EXCL); 109 110 int permissionFlag = 0; 111 if (permission == FileAccessPermission::User) 112 permissionFlag |= (S_IRUSR | S_IWUSR); 113 else if (permission == FileAccessPermission::All) 114 permissionFlag |= (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); 115 116 return open(fsRep.data(), platformFlag, permissionFlag); 100 117 } 101 118 -
trunk/Source/WTF/wtf/win/FileSystemWin.cpp
r256700 r257518 422 422 } 423 423 424 PlatformFileHandle openFile(const String& path, FileOpenMode mode )424 PlatformFileHandle openFile(const String& path, FileOpenMode mode, FileAccessPermission, bool failIfFileExists) 425 425 { 426 426 DWORD desiredAccess = 0; … … 437 437 creationDisposition = CREATE_ALWAYS; 438 438 break; 439 default: 440 ASSERT_NOT_REACHED(); 441 } 439 case FileOpenMode::ReadWrite: 440 desiredAccess = GENERIC_READ | GENERIC_WRITE; 441 creationDisposition = OPEN_ALWAYS; 442 break; 443 } 444 445 if (failIfFileExists) 446 creationDisposition = CREATE_NEW; 442 447 443 448 String destination = path; … … 550 555 } 551 556 552 bool getVolumeFreeSpace(const String&, uint64_t&) 553 { 554 return false; 557 bool getVolumeFreeSpace(const String& path, uint64_t& freeSpace) 558 { 559 ULARGE_INTEGER freeBytesAvailableToCaller; 560 if (!GetDiskFreeSpaceExW(path.wideCharacters().data(), &freeBytesAvailableToCaller, nullptr, nullptr)) 561 return false; 562 563 freeSpace = freeBytesAvailableToCaller.QuadPart; 564 return true; 555 565 } 556 566 … … 604 614 } 605 615 606 MappedFileData::MappedFileData(const String& filePath, MappedFileMode mode, bool& success) 607 { 608 auto file = CreateFile(filePath.wideCharacters().data(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); 609 610 success = mapFileHandle(file, mode); 611 closeFile(file); 612 } 613 614 bool MappedFileData::mapFileHandle(PlatformFileHandle handle, MappedFileMode) 616 bool MappedFileData::mapFileHandle(PlatformFileHandle handle, FileOpenMode openMode, MappedFileMode) 615 617 { 616 618 if (!isHandleValid(handle)) … … 626 628 } 627 629 628 auto mapping = CreateFileMapping(handle, nullptr, PAGE_READONLY, 0, 0, nullptr); 630 DWORD pageProtection = PAGE_READONLY; 631 DWORD desiredAccess = FILE_MAP_READ; 632 switch (openMode) { 633 case FileOpenMode::Read: 634 pageProtection = PAGE_READONLY; 635 desiredAccess = FILE_MAP_READ; 636 break; 637 case FileOpenMode::Write: 638 pageProtection = PAGE_READWRITE; 639 desiredAccess = FILE_MAP_WRITE; 640 break; 641 case FileOpenMode::ReadWrite: 642 pageProtection = PAGE_READWRITE; 643 desiredAccess = FILE_MAP_WRITE | FILE_MAP_READ; 644 break; 645 } 646 647 auto mapping = CreateFileMapping(handle, nullptr, pageProtection, 0, 0, nullptr); 629 648 if (!mapping) 630 649 return false; 631 650 632 m_fileData = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, size);651 m_fileData = MapViewOfFile(mapping, desiredAccess, 0, 0, size); 633 652 CloseHandle(mapping); 634 653 if (!m_fileData) -
trunk/Source/WTF/wtf/win/PathWalker.cpp
r256700 r257518 33 33 PathWalker::PathWalker(const String& directory, const String& pattern) 34 34 { 35 String path = directory + "\\" + pattern;35 String path = makeString(directory, '\\', pattern); 36 36 m_handle = ::FindFirstFileW(path.wideCharacters().data(), &m_data); 37 37 } -
trunk/Source/WebKit/ChangeLog
r257508 r257518 1 2020-02-26 Christopher Reid <chris.reid@sony.com> 2 3 [Win] Implement NetworkCache::Data by using FileSystem::MappedFileData 4 https://bugs.webkit.org/show_bug.cgi?id=197684 5 <rdar://problem/59467397> 6 7 Reviewed by Yusuke Suzuki. 8 9 * NetworkProcess/NetworkProcess.cpp: 10 Ensure that the CacheStorage directory is actually being created. 11 12 * NetworkProcess/cache/NetworkCacheData.cpp: 13 * NetworkProcess/cache/NetworkCacheData.h: 14 * NetworkProcess/cache/NetworkCacheDataCocoa.mm: 15 * NetworkProcess/cache/NetworkCacheDataSoup.cpp: 16 * NetworkProcess/cache/NetworkCacheFileSystem.cpp: 17 Use more FileSystem functionality to share code across platforms. 18 19 * NetworkProcess/cache/NetworkCacheDataCurl.cpp: 20 Use Optional<Vector> for m_buffer since we need to differentiate isEmpty and isNull. 21 1 22 2020-02-26 Per Arne Vollan <pvollan@apple.com> 2 23 -
trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp
r257206 r257518 455 455 return makeUnique<SessionStorageQuotaManager>(cacheRootPath, defaultQuota, defaultThirdPartyQuota); 456 456 }).isNewEntry; 457 if (isNewEntry) 457 if (isNewEntry) { 458 458 SandboxExtension::consumePermanently(cacheRootPathHandle); 459 if (!cacheRootPath.isEmpty()) 460 postStorageTask(createCrossThreadTask(*this, &NetworkProcess::ensurePathExists, cacheRootPath)); 461 } 459 462 } 460 463 -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp
r256700 r257518 29 29 #include <fcntl.h> 30 30 #include <wtf/CryptographicallyRandomNumber.h> 31 #include <wtf/FileSystem.h>32 31 33 32 #if !OS(WINDOWS) … … 40 39 namespace NetworkCache { 41 40 42 #if !OS(WINDOWS)43 41 Data Data::mapToFile(const String& path) const 44 42 { 45 int fd = open(FileSystem::fileSystemRepresentation(path).data(), O_CREAT | O_EXCL | O_RDWR , S_IRUSR | S_IWUSR); 46 if (fd < 0) 47 return { }; 48 49 if (ftruncate(fd, m_size) < 0) { 50 close(fd); 43 constexpr bool failIfFileExists = true; 44 auto handle = FileSystem::openFile(path, FileSystem::FileOpenMode::ReadWrite, FileSystem::FileAccessPermission::User, failIfFileExists); 45 if (!FileSystem::isHandleValid(handle) || !FileSystem::truncateFile(handle, m_size)) { 46 FileSystem::closeFile(handle); 51 47 return { }; 52 48 } 53 49 54 50 FileSystem::makeSafeToUseMemoryMapForPath(path); 55 56 void* map = mmap(nullptr, m_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);57 if ( map == MAP_FAILED) {58 close(fd);51 bool success; 52 FileSystem::MappedFileData mappedFile(handle, FileSystem::FileOpenMode::ReadWrite, FileSystem::MappedFileMode::Shared, success); 53 if (!success) { 54 FileSystem::closeFile(handle); 59 55 return { }; 60 56 } 61 57 58 void* map = const_cast<void*>(mappedFile.data()); 62 59 uint8_t* mapData = static_cast<uint8_t*>(map); 63 60 apply([&mapData](const uint8_t* bytes, size_t bytesSize) { … … 67 64 }); 68 65 66 #if OS(WINDOWS) 67 DWORD oldProtection; 68 VirtualProtect(map, m_size, FILE_MAP_READ, &oldProtection); 69 FlushViewOfFile(map, m_size); 70 #else 69 71 // Drop the write permission. 70 72 mprotect(map, m_size, PROT_READ); … … 72 74 // Flush (asynchronously) to file, turning this into clean memory. 73 75 msync(map, m_size, MS_ASYNC); 74 75 return Data::adoptMap(map, m_size, fd);76 }77 #else78 Data Data::mapToFile(const String& path) const79 {80 auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);81 if (!FileSystem::isHandleValid(file))82 return { };83 if (FileSystem::writeToFile(file, reinterpret_cast<const char*>(data()), size()) < 0)84 return { };85 return Data(Vector<uint8_t>(m_buffer));86 }87 76 #endif 88 77 89 #if !OS(WINDOWS) 78 return Data::adoptMap(WTFMove(mappedFile), handle); 79 } 80 90 81 Data mapFile(const char* path) 91 82 { 92 int fd = open(path, O_RDONLY, 0);93 if (fd < 0)94 return { };95 struct stat stat;96 if (fstat(fd, &stat) < 0) {97 close(fd);98 return { };99 }100 size_t size = stat.st_size;101 if (!size) {102 close(fd);103 return Data::empty();104 }105 106 return adoptAndMapFile(fd, 0, size);107 }108 #endif109 110 Data mapFile(const String& path)111 {112 #if !OS(WINDOWS)113 return mapFile(FileSystem::fileSystemRepresentation(path).data());114 #else115 83 auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read); 116 84 if (!FileSystem::isHandleValid(file)) … … 120 88 return { }; 121 89 return adoptAndMapFile(file, 0, size); 122 #endif123 90 } 124 91 125 #if !OS(WINDOWS) 126 Data adoptAndMapFile(int fd, size_t offset, size_t size) 92 Data mapFile(const String& path) 93 { 94 return mapFile(FileSystem::fileSystemRepresentation(path).data()); 95 } 96 97 Data adoptAndMapFile(FileSystem::PlatformFileHandle handle, size_t offset, size_t size) 127 98 { 128 99 if (!size) { 129 close(fd);100 FileSystem::closeFile(handle); 130 101 return Data::empty(); 131 102 } 132 133 void* map = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, offset);134 if ( map == MAP_FAILED) {135 close(fd);103 bool success; 104 FileSystem::MappedFileData mappedFile(handle, FileSystem::FileOpenMode::Read, FileSystem::MappedFileMode::Private, success); 105 if (!success) { 106 FileSystem::closeFile(handle); 136 107 return { }; 137 108 } 138 109 139 return Data::adoptMap( map, size, fd);110 return Data::adoptMap(WTFMove(mappedFile), handle); 140 111 } 141 #else142 Data adoptAndMapFile(FileSystem::PlatformFileHandle file, size_t offset, size_t size)143 {144 return Data(file, offset, size);145 }146 #endif147 112 148 113 SHA1::Digest computeSHA1(const Data& data, const Salt& salt) … … 180 145 Optional<Salt> readOrMakeSalt(const String& path) 181 146 { 182 #if !OS(WINDOWS) 183 auto cpath = FileSystem::fileSystemRepresentation(path); 184 auto fd = open(cpath.data(), O_RDONLY, 0); 185 Salt salt; 186 auto bytesRead = read(fd, salt.data(), salt.size()); 187 close(fd); 188 if (bytesRead != static_cast<ssize_t>(salt.size())) { 189 salt = makeSalt(); 190 191 unlink(cpath.data()); 192 fd = open(cpath.data(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); 193 bool success = write(fd, salt.data(), salt.size()) == static_cast<ssize_t>(salt.size()); 194 close(fd); 195 if (!success) 196 return { }; 197 } 198 return salt; 199 #else 200 auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read); 201 Salt salt; 202 auto bytesRead = FileSystem::readFromFile(file, reinterpret_cast<char*>(salt.data()), salt.size()); 203 FileSystem::closeFile(file); 204 if (bytesRead != salt.size()) { 205 salt = makeSalt(); 147 if (fileExists(path)) { 148 auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read); 149 Salt salt; 150 auto bytesRead = FileSystem::readFromFile(file, reinterpret_cast<char*>(salt.data()), salt.size()); 151 FileSystem::closeFile(file); 152 if (bytesRead == salt.size()) 153 return salt; 206 154 207 155 FileSystem::deleteFile(path); 208 file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);209 bool success = FileSystem::writeToFile(file, reinterpret_cast<char*>(salt.data()), salt.size()) == salt.size();210 FileSystem::closeFile(file);211 if (!success)212 return { };213 156 } 157 158 Salt salt = makeSalt(); 159 auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write, FileSystem::FileAccessPermission::User); 160 bool success = FileSystem::writeToFile(file, reinterpret_cast<char*>(salt.data()), salt.size()) == salt.size(); 161 FileSystem::closeFile(file); 162 if (!success) 163 return { }; 164 214 165 return salt; 215 #endif216 166 } 217 167 -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h
r256700 r257518 40 40 #endif 41 41 42 #if USE(CURL) 43 #include <wtf/Box.h> 44 #include <wtf/Variant.h> 45 #endif 46 42 47 namespace WebKit { 43 48 … … 54 59 55 60 static Data empty(); 56 #if !OS(WINDOWS) 57 static Data adoptMap(void* map, size_t, int fd); 58 #endif 61 static Data adoptMap(FileSystem::MappedFileData&&, FileSystem::PlatformFileHandle); 59 62 60 63 #if PLATFORM(COCOA) … … 63 66 #endif 64 67 #if USE(SOUP) 65 Data(GRefPtr<SoupBuffer>&&, int fd = -1); 66 #elif OS(WINDOWS) 67 explicit Data(Vector<uint8_t>&&); 68 Data(FileSystem::PlatformFileHandle, size_t offset, size_t); 68 Data(GRefPtr<SoupBuffer>&&, FileSystem::PlatformFileHandle fd = FileSystem::invalidPlatformFileHandle); 69 #elif USE(CURL) 70 Data(Variant<Vector<uint8_t>, FileSystem::MappedFileData>&&); 69 71 #endif 70 72 bool isNull() const; … … 95 97 #if USE(SOUP) 96 98 mutable GRefPtr<SoupBuffer> m_buffer; 97 int m_fileDescriptor { -1};99 FileSystem::PlatformFileHandle m_fileDescriptor { FileSystem::invalidPlatformFileHandle }; 98 100 #endif 99 #if OS(WINDOWS)100 Vector<uint8_t> m_buffer;101 #if USE(CURL) 102 Box<Variant<Vector<uint8_t>, FileSystem::MappedFileData>> m_buffer; 101 103 #endif 102 104 mutable const uint8_t* m_data { nullptr }; … … 107 109 Data concatenate(const Data&, const Data&); 108 110 bool bytesEqual(const Data&, const Data&); 109 #if !OS(WINDOWS)110 Data adoptAndMapFile(int, size_t offset, size_t);111 #else112 111 Data adoptAndMapFile(FileSystem::PlatformFileHandle, size_t offset, size_t); 113 #endif114 #if USE(GLIB) && !PLATFORM(WIN)115 Data adoptAndMapFile(GFileIOStream*, size_t offset, size_t);116 #endif117 #if !OS(WINDOWS)118 112 Data mapFile(const char* path); 119 #endif120 113 Data mapFile(const String& path); 121 114 -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCocoa.mm
r256700 r257518 93 93 } 94 94 95 Data Data::adoptMap( void* map, size_t size, intfd)95 Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd) 96 96 { 97 size_t size = mappedFile.size(); 98 void* map = mappedFile.leakHandle(); 97 99 ASSERT(map); 98 100 ASSERT(map != MAP_FAILED); 99 close(fd);101 FileSystem::closeFile(fd); 100 102 auto bodyMap = adoptOSObject(dispatch_data_create(map, size, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), [map, size] { 101 103 munmap(map, size); -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCurl.cpp
r256700 r257518 31 31 32 32 Data::Data(const uint8_t* data, size_t size) 33 : m_buffer(Box<Variant<Vector<uint8_t>, FileSystem::MappedFileData>>::create(Vector<uint8_t>(size))) 34 , m_size(size) 33 35 { 34 m_buffer.resize(size); 35 m_size = size; 36 memcpy(m_buffer.data(), data, size); 36 memcpy(WTF::get<Vector<uint8_t>>(*m_buffer).data(), data, size); 37 37 } 38 38 39 Data::Data(FileSystem::PlatformFileHandle file, size_t offset, size_t size) 39 Data::Data(Variant<Vector<uint8_t>, FileSystem::MappedFileData>&& data) 40 : m_buffer(Box<Variant<Vector<uint8_t>, FileSystem::MappedFileData>>::create(WTFMove(data))) 41 , m_isMap(WTF::holds_alternative<FileSystem::MappedFileData>(*m_buffer)) 40 42 { 41 m_buffer.resize(size); 42 m_size = size; 43 FileSystem::seekFile(file, offset, FileSystem::FileSeekOrigin::Beginning); 44 FileSystem::readFromFile(file, reinterpret_cast<char*>(m_buffer.data()), size); 45 FileSystem::closeFile(file); 46 } 47 48 Data::Data(Vector<uint8_t>&& buffer) 49 : m_buffer(WTFMove(buffer)) 50 { 51 m_size = m_buffer.size(); 43 m_size = WTF::switchOn(*m_buffer, 44 [](const Vector<uint8_t>& buffer) -> size_t { return buffer.size(); }, 45 [](const FileSystem::MappedFileData& mappedFile) -> size_t { return mappedFile.size(); } 46 ); 52 47 } 53 48 54 49 Data Data::empty() 55 50 { 56 return { }; 51 Vector<uint8_t> buffer; 52 return { WTFMove(buffer) }; 57 53 } 58 54 59 55 const uint8_t* Data::data() const 60 56 { 61 return m_buffer.data(); 57 if (!m_buffer) 58 return nullptr; 59 60 return WTF::switchOn(*m_buffer, 61 [](const Vector<uint8_t>& buffer) -> const uint8_t* { return buffer.data(); }, 62 [](const FileSystem::MappedFileData& mappedFile) -> const uint8_t* { return static_cast<const uint8_t*>(mappedFile.data()); } 63 ); 62 64 } 63 65 64 66 bool Data::isNull() const 65 67 { 66 return m_buffer.isEmpty();68 return !m_buffer; 67 69 } 68 70 … … 72 74 return false; 73 75 74 return applier(reinterpret_cast<const uint8_t*>( m_buffer.data()), m_buffer.size());76 return applier(reinterpret_cast<const uint8_t*>(data()), size()); 75 77 } 76 78 77 79 Data Data::subrange(size_t offset, size_t size) const 78 80 { 79 return { m_buffer.data() + offset, size }; 81 if (!m_buffer) 82 return { }; 83 84 return { data() + offset, size }; 80 85 } 81 86 82 87 Data concatenate(const Data& a, const Data& b) 83 88 { 89 if (a.isNull()) 90 return b; 91 if (b.isNull()) 92 return a; 93 84 94 Vector<uint8_t> buffer(a.size() + b.size()); 85 95 memcpy(buffer.data(), a.data(), a.size()); … … 88 98 } 89 99 100 Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd) 101 { 102 ASSERT(mappedFile.data()); 103 FileSystem::closeFile(fd); 104 105 return { WTFMove(mappedFile) }; 106 } 107 90 108 } // namespace NetworkCache 91 109 } // namespace WebKit -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp
r256700 r257518 49 49 } 50 50 51 Data::Data(GRefPtr<SoupBuffer>&& buffer, intfd)51 Data::Data(GRefPtr<SoupBuffer>&& buffer, FileSystem::PlatformFileHandle fd) 52 52 : m_buffer(buffer) 53 53 , m_fileDescriptor(fd) 54 54 , m_size(buffer ? buffer->length : 0) 55 , m_isMap(m_size && fd != -1)55 , m_isMap(m_size && FileSystem::isHandleValid(fd)) 56 56 { 57 57 } … … 109 109 { 110 110 munmap(map, size); 111 close(fileDescriptor);111 FileSystem::closeFile(fileDescriptor); 112 112 } 113 113 114 114 void* map; 115 115 size_t size; 116 intfileDescriptor;116 FileSystem::PlatformFileHandle fileDescriptor; 117 117 }; 118 118 … … 122 122 } 123 123 124 Data Data::adoptMap( void* map, size_t size, intfd)124 Data Data::adoptMap(FileSystem::MappedFileData&& mappedFile, FileSystem::PlatformFileHandle fd) 125 125 { 126 size_t size = mappedFile.size(); 127 void* map = mappedFile.leakHandle(); 126 128 ASSERT(map); 127 129 ASSERT(map != MAP_FAILED); … … 131 133 } 132 134 133 #if USE(GLIB) && !PLATFORM(WIN)134 Data adoptAndMapFile(GFileIOStream* stream, size_t offset, size_t size)135 {136 GInputStream* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(stream));137 int fd = g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream));138 return adoptAndMapFile(fd, offset, size);139 }140 #endif141 142 135 RefPtr<SharedMemory> Data::tryCreateSharedMemory() const 143 136 { … … 145 138 return nullptr; 146 139 147 return SharedMemory::wrapMap(const_cast<char*>(m_buffer->data), m_buffer->length, m_fileDescriptor); 140 GInputStream* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(m_fileDescriptor)); 141 int fd = g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream)); 142 return SharedMemory::wrapMap(const_cast<char*>(m_buffer->data), m_buffer->length, fd); 148 143 } 149 144 -
trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp
r256700 r257518 54 54 namespace NetworkCache { 55 55 56 #if !OS(WINDOWS)57 static DirectoryEntryType directoryEntryType(uint8_t dtype)58 {59 switch (dtype) {60 case DT_DIR:61 return DirectoryEntryType::Directory;62 case DT_REG:63 return DirectoryEntryType::File;64 default:65 ASSERT_NOT_REACHED();66 return DirectoryEntryType::File;67 }68 return DirectoryEntryType::File;69 }70 #endif71 72 56 void traverseDirectory(const String& path, const Function<void (const String&, DirectoryEntryType)>& function) 73 57 { 74 #if !OS(WINDOWS) 75 DIR* dir = opendir(FileSystem::fileSystemRepresentation(path).data()); 76 if (!dir) 77 return; 78 dirent* dp; 79 while ((dp = readdir(dir))) { 80 if (dp->d_type != DT_DIR && dp->d_type != DT_REG) 81 continue; 82 const char* name = dp->d_name; 83 if (!strcmp(name, ".") || !strcmp(name, "..")) 84 continue; 85 auto nameString = String::fromUTF8(name); 86 if (nameString.isNull()) 87 continue; 88 function(nameString, directoryEntryType(dp->d_type)); 89 } 90 closedir(dir); 91 #else 92 auto entries = FileSystem::listDirectory(path); 58 auto entries = FileSystem::listDirectory(path, "*"_s); 93 59 for (auto& entry : entries) { 94 60 auto type = FileSystem::fileIsDirectory(entry, FileSystem::ShouldFollowSymbolicLinks::No) ? DirectoryEntryType::Directory : DirectoryEntryType::File; 95 function( entry, type);61 function(FileSystem::pathGetFileName(entry), type); 96 62 } 97 #endif98 63 } 99 64 -
trunk/Tools/ChangeLog
r257498 r257518 1 2020-02-26 Christopher Reid <chris.reid@sony.com> 2 3 [Win] Implement NetworkCache::Data by using FileSystem::MappedFileData 4 https://bugs.webkit.org/show_bug.cgi?id=197684 5 <rdar://problem/59467397> 6 7 Reviewed by Yusuke Suzuki. 8 9 Add test for FileSystem::createFile 10 11 * TestWebKitAPI/Tests/WTF/FileSystem.cpp: 12 1 13 2020-02-26 Aakash Jain <aakash_jain@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp
r247542 r257518 146 146 } 147 147 148 TEST_F(FileSystemTest, openExistingFileAndFailIfFileExists) 149 { 150 auto handle = FileSystem::openFile(tempFilePath(), FileSystem::FileOpenMode::ReadWrite, FileSystem::FileAccessPermission::All, true); 151 EXPECT_FALSE(FileSystem::isHandleValid(handle)); 148 152 } 153 154 }
Note: See TracChangeset
for help on using the changeset viewer.