Title: [245186] trunk/Source
Revision
245186
Author
[email protected]
Date
2019-05-10 12:01:54 -0700 (Fri, 10 May 2019)

Log Message

[WinCairo] storage/indexeddb tests are timing out
https://bugs.webkit.org/show_bug.cgi?id=196289

Reviewed by Alex Christensen.

Source/WebKit:

storage/indexeddb tests were timing out for WinCairo port because
WebKit::NetworkCache classes were not implemented yet for Windows.

Implement WebKit::NetworkCache classes by using WTF::FileSystem
functions.

* NetworkProcess/cache/CacheStorageEngine.cpp:
(WebKit::CacheStorage::Engine::readFile): Use
IOChannel::isOpened() to check the channel is opened instead of
checking the file descriptor.
* NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
(WebKit::NetworkCache::BlobStorage::add):
(WebKit::NetworkCache::BlobStorage::remove):
* NetworkProcess/cache/NetworkCacheData.cpp:
(WebKit::NetworkCache::Data::mapToFile const):
(WebKit::NetworkCache::mapFile):
(WebKit::NetworkCache::adoptAndMapFile):
(WebKit::NetworkCache::makeSalt):
(WebKit::NetworkCache::readOrMakeSalt):
* NetworkProcess/cache/NetworkCacheData.h:
(WebKit::NetworkCache::Data::isEmpty const):
(WebKit::NetworkCache::Data::size const):
* NetworkProcess/cache/NetworkCacheDataCurl.cpp:
(WebKit::NetworkCache::Data::Data):
(WebKit::NetworkCache::Data::empty):
(WebKit::NetworkCache::Data::data const):
(WebKit::NetworkCache::Data::isNull const):
(WebKit::NetworkCache::Data::apply const):
(WebKit::NetworkCache::Data::subrange const):
(WebKit::NetworkCache::concatenate):
(WebKit::NetworkCache::Data::adoptMap): Deleted.
* NetworkProcess/cache/NetworkCacheFileSystem.cpp:
(WebKit::NetworkCache::traverseDirectory):
(WebKit::NetworkCache::fileTimes):
(WebKit::NetworkCache::updateFileModificationTimeIfNeeded):
(WebKit::NetworkCache::isSafeToUseMemoryMapForPath):
* NetworkProcess/cache/NetworkCacheIOChannel.h:
(WebKit::NetworkCache::IOChannel::isOpened const):
(WebKit::NetworkCache::IOChannel::fileDescriptor const): Deleted.
* NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp:
(WebKit::NetworkCache::IOChannel::IOChannel):
(WebKit::NetworkCache::IOChannel::~IOChannel):
(WebKit::NetworkCache::runTaskInQueue):
(WebKit::NetworkCache::IOChannel::read):
(WebKit::NetworkCache::IOChannel::write):

Source/WTF:

* wtf/FileSystem.h: Added hardLink.
* wtf/glib/FileSystemGlib.cpp:
(WTF::FileSystemImpl::hardLink):
(WTF::FileSystemImpl::hardLinkOrCopyFile):
* wtf/posix/FileSystemPOSIX.cpp:
(WTF::FileSystemImpl::hardLink):
(WTF::FileSystemImpl::hardLinkOrCopyFile):
* wtf/win/FileSystemWin.cpp:
(WTF::FileSystemImpl::hardLink):
(WTF::FileSystemImpl::hardLinkOrCopyFile):
Added hardLink. Let hardLinkOrCopyFile use the hardLink.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (245185 => 245186)


--- trunk/Source/WTF/ChangeLog	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WTF/ChangeLog	2019-05-10 19:01:54 UTC (rev 245186)
@@ -1,3 +1,22 @@
+2019-05-10  Fujii Hironori  <[email protected]>
+
+        [WinCairo] storage/indexeddb tests are timing out
+        https://bugs.webkit.org/show_bug.cgi?id=196289
+
+        Reviewed by Alex Christensen.
+
+        * wtf/FileSystem.h: Added hardLink.
+        * wtf/glib/FileSystemGlib.cpp:
+        (WTF::FileSystemImpl::hardLink):
+        (WTF::FileSystemImpl::hardLinkOrCopyFile):
+        * wtf/posix/FileSystemPOSIX.cpp:
+        (WTF::FileSystemImpl::hardLink):
+        (WTF::FileSystemImpl::hardLinkOrCopyFile):
+        * wtf/win/FileSystemWin.cpp:
+        (WTF::FileSystemImpl::hardLink):
+        (WTF::FileSystemImpl::hardLinkOrCopyFile):
+        Added hardLink. Let hardLinkOrCopyFile use the hardLink.
+
 2019-05-10  Yusuke Suzuki  <[email protected]>
 
         [WTF] Remove "private:" from Noncopyable and Nonmovable macros

Modified: trunk/Source/WTF/wtf/FileSystem.h (245185 => 245186)


--- trunk/Source/WTF/wtf/FileSystem.h	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WTF/wtf/FileSystem.h	2019-05-10 19:01:54 UTC (rev 245186)
@@ -151,6 +151,7 @@
 // Returns true if the write was successful, false if it was not.
 WTF_EXPORT_PRIVATE bool appendFileContentsToFileHandle(const String& path, PlatformFileHandle&);
 
+WTF_EXPORT_PRIVATE bool hardLink(const String& source, const String& destination);
 // Hard links a file if possible, copies it if not.
 WTF_EXPORT_PRIVATE bool hardLinkOrCopyFile(const String& source, const String& destination);
 

Modified: trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp (245185 => 245186)


--- trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp	2019-05-10 19:01:54 UTC (rev 245186)
@@ -429,10 +429,10 @@
     return g_file_move(oldFile.get(), newFile.get(), G_FILE_COPY_OVERWRITE, nullptr, nullptr, nullptr, nullptr);
 }
 
-bool hardLinkOrCopyFile(const String& source, const String& destination)
+bool hardLink(const String& source, const String& destination)
 {
 #if OS(WINDOWS)
-    return !!::CopyFile(source.charactersWithNullTermination().data(), destination.charactersWithNullTermination().data(), TRUE);
+    return CreateHardLink(destination.wideCharacters().data(), source.wideCharacters().data(), nullptr);
 #else
     auto sourceFilename = fileSystemRepresentation(source);
     if (!validRepresentation(sourceFilename))
@@ -442,10 +442,27 @@
     if (!validRepresentation(destinationFilename))
         return false;
 
-    if (!link(sourceFilename.data(), destinationFilename.data()))
+    return !link(sourceFilename.data(), destinationFilename.data());
+#endif
+}
+
+bool hardLinkOrCopyFile(const String& source, const String& destination)
+{
+    if (hardLink(source, destination))
         return true;
 
     // Hard link failed. Perform a copy instead.
+#if OS(WINDOWS)
+    return !!::CopyFile(source.wideCharacters().data(), destination.wideCharacters().data(), TRUE);
+#else
+    auto sourceFilename = fileSystemRepresentation(source);
+    if (!validRepresentation(sourceFilename))
+        return false;
+
+    auto destinationFilename = fileSystemRepresentation(destination);
+    if (!validRepresentation(destinationFilename))
+        return false;
+
     GRefPtr<GFile> sourceFile = adoptGRef(g_file_new_for_path(sourceFilename.data()));
     GRefPtr<GFile> destinationFile = adoptGRef(g_file_new_for_path(destinationFilename.data()));
     return g_file_copy(sourceFile.get(), destinationFile.get(), G_FILE_COPY_NONE, nullptr, nullptr, nullptr, nullptr);

Modified: trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp (245185 => 245186)


--- trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp	2019-05-10 19:01:54 UTC (rev 245186)
@@ -444,23 +444,39 @@
 }
 #endif // !PLATFORM(COCOA)
 
-bool hardLinkOrCopyFile(const String& source, const String& destination)
+bool hardLink(const String& source, const String& destination)
 {
     if (source.isEmpty() || destination.isEmpty())
         return false;
 
-    CString fsSource = fileSystemRepresentation(source);
+    auto fsSource = fileSystemRepresentation(source);
     if (!fsSource.data())
         return false;
 
-    CString fsDestination = fileSystemRepresentation(destination);
+    auto fsDestination = fileSystemRepresentation(destination);
     if (!fsDestination.data())
         return false;
 
-    if (!link(fsSource.data(), fsDestination.data()))
+    return !link(fsSource.data(), fsDestination.data());
+}
+
+bool hardLinkOrCopyFile(const String& source, const String& destination)
+{
+    if (hardLink(source, destination))
         return true;
 
     // Hard link failed. Perform a copy instead.
+    if (source.isEmpty() || destination.isEmpty())
+        return false;
+
+    auto fsSource = fileSystemRepresentation(source);
+    if (!fsSource.data())
+        return false;
+
+    auto fsDestination = fileSystemRepresentation(destination);
+    if (!fsDestination.data())
+        return false;
+
     auto handle = open(fsDestination.data(), O_WRONLY | O_CREAT | O_EXCL, 0666);
     if (handle == -1)
         return false;

Modified: trunk/Source/WTF/wtf/win/FileSystemWin.cpp (245185 => 245186)


--- trunk/Source/WTF/wtf/win/FileSystemWin.cpp	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WTF/wtf/win/FileSystemWin.cpp	2019-05-10 19:01:54 UTC (rev 245186)
@@ -496,8 +496,17 @@
     return static_cast<int>(bytesRead);
 }
 
+bool hardLink(const String& source, const String& destination)
+{
+    return CreateHardLink(destination.wideCharacters().data(), source.wideCharacters().data(), nullptr);
+}
+
 bool hardLinkOrCopyFile(const String& source, const String& destination)
 {
+    if (hardLink(source, destination))
+        return true;
+
+    // Hard link failed. Perform a copy instead.
     return !!::CopyFile(source.wideCharacters().data(), destination.wideCharacters().data(), TRUE);
 }
 

Modified: trunk/Source/WebKit/ChangeLog (245185 => 245186)


--- trunk/Source/WebKit/ChangeLog	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WebKit/ChangeLog	2019-05-10 19:01:54 UTC (rev 245186)
@@ -1,3 +1,56 @@
+2019-05-10  Fujii Hironori  <[email protected]>
+
+        [WinCairo] storage/indexeddb tests are timing out
+        https://bugs.webkit.org/show_bug.cgi?id=196289
+
+        Reviewed by Alex Christensen.
+
+        storage/indexeddb tests were timing out for WinCairo port because
+        WebKit::NetworkCache classes were not implemented yet for Windows.
+
+        Implement WebKit::NetworkCache classes by using WTF::FileSystem
+        functions.
+
+        * NetworkProcess/cache/CacheStorageEngine.cpp:
+        (WebKit::CacheStorage::Engine::readFile): Use
+        IOChannel::isOpened() to check the channel is opened instead of
+        checking the file descriptor.
+        * NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
+        (WebKit::NetworkCache::BlobStorage::add):
+        (WebKit::NetworkCache::BlobStorage::remove):
+        * NetworkProcess/cache/NetworkCacheData.cpp:
+        (WebKit::NetworkCache::Data::mapToFile const):
+        (WebKit::NetworkCache::mapFile):
+        (WebKit::NetworkCache::adoptAndMapFile):
+        (WebKit::NetworkCache::makeSalt):
+        (WebKit::NetworkCache::readOrMakeSalt):
+        * NetworkProcess/cache/NetworkCacheData.h:
+        (WebKit::NetworkCache::Data::isEmpty const):
+        (WebKit::NetworkCache::Data::size const):
+        * NetworkProcess/cache/NetworkCacheDataCurl.cpp:
+        (WebKit::NetworkCache::Data::Data):
+        (WebKit::NetworkCache::Data::empty):
+        (WebKit::NetworkCache::Data::data const):
+        (WebKit::NetworkCache::Data::isNull const):
+        (WebKit::NetworkCache::Data::apply const):
+        (WebKit::NetworkCache::Data::subrange const):
+        (WebKit::NetworkCache::concatenate):
+        (WebKit::NetworkCache::Data::adoptMap): Deleted.
+        * NetworkProcess/cache/NetworkCacheFileSystem.cpp:
+        (WebKit::NetworkCache::traverseDirectory):
+        (WebKit::NetworkCache::fileTimes):
+        (WebKit::NetworkCache::updateFileModificationTimeIfNeeded):
+        (WebKit::NetworkCache::isSafeToUseMemoryMapForPath):
+        * NetworkProcess/cache/NetworkCacheIOChannel.h:
+        (WebKit::NetworkCache::IOChannel::isOpened const):
+        (WebKit::NetworkCache::IOChannel::fileDescriptor const): Deleted.
+        * NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp:
+        (WebKit::NetworkCache::IOChannel::IOChannel):
+        (WebKit::NetworkCache::IOChannel::~IOChannel):
+        (WebKit::NetworkCache::runTaskInQueue):
+        (WebKit::NetworkCache::IOChannel::read):
+        (WebKit::NetworkCache::IOChannel::write):
+
 2019-05-10  Chris Dumez  <[email protected]>
 
         Do not wait until requestPermission() is called to fire deviceorientation events if permission was already granted

Modified: trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp (245185 => 245186)


--- trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp	2019-05-10 19:01:54 UTC (rev 245186)
@@ -423,7 +423,7 @@
     m_pendingReadCallbacks.add(++m_pendingCallbacksCounter, WTFMove(callback));
     m_ioQueue->dispatch([this, weakThis = makeWeakPtr(this), identifier = m_pendingCallbacksCounter, filename = filename.isolatedCopy()]() mutable {
         auto channel = IOChannel::open(filename, IOChannel::Type::Read);
-        if (channel->fileDescriptor() < 0) {
+        if (!channel->isOpened()) {
             RunLoop::main().dispatch([this, weakThis = WTFMove(weakThis), identifier]() mutable {
                 if (!weakThis)
                     return;

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp (245185 => 245186)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp	2019-05-10 19:01:54 UTC (rev 245186)
@@ -86,7 +86,6 @@
 
 BlobStorage::Blob BlobStorage::add(const String& path, const Data& data)
 {
-#if !OS(WINDOWS)
     ASSERT(!RunLoop::isMain());
 
     auto hash = computeSHA1(data, m_salt);
@@ -93,39 +92,34 @@
     if (data.isEmpty())
         return { data, hash };
 
-    String blobPathString = blobPathForHash(hash);
+    String blobPath = blobPathForHash(hash);
     
-    auto blobPath = FileSystem::fileSystemRepresentation(blobPathString);
-    auto linkPath = FileSystem::fileSystemRepresentation(path);
-    unlink(linkPath.data());
+    FileSystem::deleteFile(path);
 
-    bool blobExists = access(blobPath.data(), F_OK) != -1;
+    bool blobExists = FileSystem::fileExists(blobPath);
     if (blobExists) {
-        FileSystem::makeSafeToUseMemoryMapForPath(blobPathString);
-        auto existingData = mapFile(blobPath.data());
+        FileSystem::makeSafeToUseMemoryMapForPath(blobPath);
+        auto existingData = mapFile(blobPath);
         if (bytesEqual(existingData, data)) {
-            if (link(blobPath.data(), linkPath.data()) == -1)
-                WTFLogAlways("Failed to create hard link from %s to %s", blobPath.data(), linkPath.data());
+            if (!FileSystem::hardLink(blobPath, path))
+                WTFLogAlways("Failed to create hard link from %s to %s", blobPath.utf8().data(), path.utf8().data());
             return { existingData, hash };
         }
-        unlink(blobPath.data());
+        FileSystem::deleteFile(blobPath);
     }
 
-    auto mappedData = data.mapToFile(blobPath.data());
+    auto mappedData = data.mapToFile(blobPath);
     if (mappedData.isNull())
         return { };
 
-    FileSystem::makeSafeToUseMemoryMapForPath(blobPathString);
+    FileSystem::makeSafeToUseMemoryMapForPath(blobPath);
 
-    if (link(blobPath.data(), linkPath.data()) == -1)
-        WTFLogAlways("Failed to create hard link from %s to %s", blobPath.data(), linkPath.data());
+    if (!FileSystem::hardLink(blobPath, path))
+        WTFLogAlways("Failed to create hard link from %s to %s", blobPath.utf8().data(), path.utf8().data());
 
     m_approximateSize += mappedData.size();
 
     return { mappedData, hash };
-#else
-    return { Data(), computeSHA1(data, m_salt) };
-#endif
 }
 
 BlobStorage::Blob BlobStorage::get(const String& path)
@@ -142,8 +136,7 @@
 {
     ASSERT(!RunLoop::isMain());
 
-    auto linkPath = FileSystem::fileSystemRepresentation(path);
-    unlink(linkPath.data());
+    FileSystem::deleteFile(path);
 }
 
 unsigned BlobStorage::shareCount(const String& path)

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp (245185 => 245186)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp	2019-05-10 19:01:54 UTC (rev 245186)
@@ -39,10 +39,10 @@
 namespace WebKit {
 namespace NetworkCache {
 
-Data Data::mapToFile(const char* path) const
+#if !OS(WINDOWS)
+Data Data::mapToFile(const String& path) const
 {
-#if !OS(WINDOWS)
-    int fd = open(path, O_CREAT | O_EXCL | O_RDWR , S_IRUSR | S_IWUSR);
+    int fd = open(FileSystem::fileSystemRepresentation(path).data(), O_CREAT | O_EXCL | O_RDWR , S_IRUSR | S_IWUSR);
     if (fd < 0)
         return { };
 
@@ -71,14 +71,22 @@
     msync(map, m_size, MS_ASYNC);
 
     return Data::adoptMap(map, m_size, fd);
+}
 #else
-    return Data();
+Data Data::mapToFile(const String& path) const
+{
+    auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);
+    if (!FileSystem::isHandleValid(file))
+        return { };
+    if (FileSystem::writeToFile(file, reinterpret_cast<const char*>(data()), size()) < 0)
+        return { };
+    return Data(Vector<uint8_t>(m_buffer));
+}
 #endif
-}
 
+#if !OS(WINDOWS)
 Data mapFile(const char* path)
 {
-#if !OS(WINDOWS)
     int fd = open(path, O_RDONLY, 0);
     if (fd < 0)
         return { };
@@ -94,14 +102,27 @@
     }
 
     return adoptAndMapFile(fd, 0, size);
+}
+#endif
+
+Data mapFile(const String& path)
+{
+#if !OS(WINDOWS)
+    return mapFile(FileSystem::fileSystemRepresentation(path).data());
 #else
-    return Data();
+    auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read);
+    if (!FileSystem::isHandleValid(file))
+        return { };
+    long long size;
+    if (!FileSystem::getFileSize(file, size))
+        return { };
+    return adoptAndMapFile(file, 0, size);
 #endif
 }
 
+#if !OS(WINDOWS)
 Data adoptAndMapFile(int fd, size_t offset, size_t size)
 {
-#if !OS(WINDOWS)
     if (!size) {
         close(fd);
         return Data::empty();
@@ -114,10 +135,13 @@
     }
 
     return Data::adoptMap(map, size, fd);
+}
 #else
-    return Data();
+Data adoptAndMapFile(FileSystem::PlatformFileHandle file, size_t offset, size_t size)
+{
+    return Data(file, offset, size);
+}
 #endif
-}
 
 SHA1::Digest computeSHA1(const Data& data, const Salt& salt)
 {
@@ -142,7 +166,6 @@
     return !memcmp(a.data(), b.data(), a.size());
 }
 
-#if !OS(WINDOWS)
 static Salt makeSalt()
 {
     Salt salt;
@@ -151,7 +174,6 @@
     *reinterpret_cast<uint32_t*>(&salt[4]) = cryptographicallyRandomNumber();
     return salt;
 }
-#endif
 
 Optional<Salt> readOrMakeSalt(const String& path)
 {
@@ -173,7 +195,21 @@
     }
     return salt;
 #else
-    return Salt();
+    auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read);
+    Salt salt;
+    auto bytesRead = FileSystem::readFromFile(file, reinterpret_cast<char*>(salt.data()), salt.size());
+    FileSystem::closeFile(file);
+    if (bytesRead != salt.size()) {
+        salt = makeSalt();
+
+        FileSystem::deleteFile(path);
+        file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);
+        bool success = FileSystem::writeToFile(file, reinterpret_cast<char*>(salt.data()), salt.size()) == salt.size();
+        FileSystem::closeFile(file);
+        if (!success)
+            return { };
+    }
+    return salt;
 #endif
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h (245185 => 245186)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h	2019-05-10 19:01:54 UTC (rev 245186)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#include <wtf/FileSystem.h>
 #include <wtf/FunctionDispatcher.h>
 #include <wtf/SHA1.h>
 #include <wtf/ThreadSafeRefCounted.h>
@@ -52,7 +53,9 @@
     ~Data() { }
 
     static Data empty();
+#if !OS(WINDOWS)
     static Data adoptMap(void* map, size_t, int fd);
+#endif
 
 #if PLATFORM(COCOA)
     enum class Backing { Buffer, Map };
@@ -60,6 +63,9 @@
 #endif
 #if USE(SOUP)
     Data(GRefPtr<SoupBuffer>&&, int fd = -1);
+#elif OS(WINDOWS)
+    explicit Data(Vector<uint8_t>&&);
+    Data(FileSystem::PlatformFileHandle, size_t offset, size_t);
 #endif
     bool isNull() const;
     bool isEmpty() const { return !m_size; }
@@ -73,7 +79,7 @@
 
     bool apply(const Function<bool (const uint8_t*, size_t)>&) const;
 
-    Data mapToFile(const char* path) const;
+    Data mapToFile(const String& path) const;
 
 #if PLATFORM(COCOA)
     dispatch_data_t dispatchData() const { return m_dispatchData.get(); }
@@ -90,6 +96,9 @@
     mutable GRefPtr<SoupBuffer> m_buffer;
     int m_fileDescriptor { -1 };
 #endif
+#if OS(WINDOWS)
+    Vector<uint8_t> m_buffer;
+#endif
     mutable const uint8_t* m_data { nullptr };
     size_t m_size { 0 };
     bool m_isMap { false };
@@ -97,11 +106,18 @@
 
 Data concatenate(const Data&, const Data&);
 bool bytesEqual(const Data&, const Data&);
-Data adoptAndMapFile(int fd, size_t offset, size_t);
+#if !OS(WINDOWS)
+Data adoptAndMapFile(int, size_t offset, size_t);
+#else
+Data adoptAndMapFile(FileSystem::PlatformFileHandle, size_t offset, size_t);
+#endif
 #if USE(GLIB) && !PLATFORM(WIN)
 Data adoptAndMapFile(GFileIOStream*, size_t offset, size_t);
 #endif
+#if !OS(WINDOWS)
 Data mapFile(const char* path);
+#endif
+Data mapFile(const String& path);
 
 using Salt = std::array<uint8_t, 8>;
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCurl.cpp (245185 => 245186)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCurl.cpp	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCurl.cpp	2019-05-10 19:01:54 UTC (rev 245186)
@@ -26,56 +26,66 @@
 #include "config.h"
 #include "NetworkCacheData.h"
 
-#include <WebCore/NotImplemented.h>
-
 namespace WebKit {
 namespace NetworkCache {
 
 Data::Data(const uint8_t* data, size_t size)
 {
-    notImplemented();
+    m_buffer.resize(size);
+    m_size = size;
+    memcpy(m_buffer.data(), data, size);
 }
 
+Data::Data(FileSystem::PlatformFileHandle file, size_t offset, size_t size)
+{
+    m_buffer.resize(size);
+    m_size = size;
+    FileSystem::seekFile(file, offset, FileSystem::FileSeekOrigin::Beginning);
+    FileSystem::readFromFile(file, reinterpret_cast<char*>(m_buffer.data()), size);
+    FileSystem::closeFile(file);
+}
+
+Data::Data(Vector<uint8_t>&& buffer)
+    : m_buffer(WTFMove(buffer))
+{
+    m_size = m_buffer.size();
+}
+
 Data Data::empty()
 {
-    notImplemented();
     return { };
 }
 
 const uint8_t* Data::data() const
 {
-    notImplemented();
-    return nullptr;
+    return m_buffer.data();
 }
 
 bool Data::isNull() const
 {
-    notImplemented();
-    return true;
+    return m_buffer.isEmpty();
 }
 
 bool Data::apply(const Function<bool(const uint8_t*, size_t)>& applier) const
 {
-    notImplemented();
-    return false;
+    if (isEmpty())
+        return false;
+
+    return applier(reinterpret_cast<const uint8_t*>(m_buffer.data()), m_buffer.size());
 }
 
 Data Data::subrange(size_t offset, size_t size) const
 {
-    return { };
+    return { m_buffer.data() + offset, size };
 }
 
 Data concatenate(const Data& a, const Data& b)
 {
-    notImplemented();
-    return { };
+    Vector<uint8_t> buffer(a.size() + b.size());
+    memcpy(buffer.data(), a.data(), a.size());
+    memcpy(buffer.data() + a.size(), b.data(), b.size());
+    return Data(WTFMove(buffer));
 }
 
-Data Data::adoptMap(void* map, size_t size, int fd)
-{
-    notImplemented();
-    return { };
-}
-
 } // namespace NetworkCache
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp (245185 => 245186)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp	2019-05-10 19:01:54 UTC (rev 245186)
@@ -87,7 +87,11 @@
     }
     closedir(dir);
 #else
-    function(String(), DirectoryEntryType::File);
+    auto entries = FileSystem::listDirectory(path);
+    for (auto& entry : entries) {
+        auto type = FileSystem::fileIsDirectory(entry, FileSystem::ShouldFollowSymbolicLinks::No) ? DirectoryEntryType::Directory : DirectoryEntryType::File;
+        function(entry, type);
+    }
 #endif
 }
 
@@ -127,7 +131,9 @@
     return { WallTime::fromRawSeconds(g_ascii_strtoull(birthtimeString, nullptr, 10)),
         WallTime::fromRawSeconds(g_file_info_get_attribute_uint64(fileInfo.get(), "time::modified")) };
 #elif OS(WINDOWS)
-    return FileTimes();
+    auto createTime = FileSystem::getFileCreationTime(path);
+    auto modifyTime = FileSystem::getFileModificationTime(path);
+    return { createTime.valueOr(WallTime()), modifyTime.valueOr(WallTime()) };
 #endif
 }
 
@@ -142,6 +148,14 @@
 #if !OS(WINDOWS)
     // This really updates both the access time and the modification time.
     utimes(FileSystem::fileSystemRepresentation(path).data(), nullptr);
+#else
+    FILETIME time;
+    GetSystemTimeAsFileTime(&time);
+    auto file = CreateFile(path.wideCharacters().data(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
+    if (file == INVALID_HANDLE_VALUE)
+        return;
+    SetFileTime(file, &time, &time, &time);
+    CloseHandle(file);
 #endif
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h (245185 => 245186)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h	2019-05-10 19:01:54 UTC (rev 245186)
@@ -52,7 +52,11 @@
     const String& path() const { return m_path; }
     Type type() const { return m_type; }
 
-    int fileDescriptor() const { return m_fileDescriptor; }
+#if !USE(SOUP)
+    bool isOpened() const { return FileSystem::isHandleValid(m_fileDescriptor); }
+#else
+    bool isOpened() const { return true; }
+#endif
 
     ~IOChannel();
 
@@ -66,7 +70,9 @@
     String m_path;
     Type m_type;
 
-    int m_fileDescriptor { 0 };
+#if !USE(SOUP)
+    FileSystem::PlatformFileHandle m_fileDescriptor { FileSystem::invalidPlatformFileHandle };
+#endif
     std::atomic<bool> m_wasDeleted { false }; // Try to narrow down a crash, https://bugs.webkit.org/show_bug.cgi?id=165659
 #if PLATFORM(COCOA)
     OSObjectPtr<dispatch_io_t> m_dispatchIO;

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp (245185 => 245186)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp	2019-05-10 19:01:12 UTC (rev 245185)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp	2019-05-10 19:01:54 UTC (rev 245186)
@@ -26,20 +26,33 @@
 #include "config.h"
 #include "NetworkCacheIOChannel.h"
 
-#include <WebCore/NotImplemented.h>
+#include <wtf/RunLoop.h>
 
 namespace WebKit {
 namespace NetworkCache {
 
 IOChannel::IOChannel(const String& filePath, Type type)
-    : m_path{filePath}
-    , m_type{type}
+    : m_path(filePath)
+    , m_type(type)
 {
-    notImplemented();
+    FileSystem::FileOpenMode mode;
+    switch (type) {
+    case Type::Read:
+        mode = FileSystem::FileOpenMode::Read;
+        break;
+    case Type::Write:
+        mode = FileSystem::FileOpenMode::Write;
+        break;
+    case Type::Create:
+        mode = FileSystem::FileOpenMode::Write;
+        break;
+    }
+    m_fileDescriptor = FileSystem::openFile(filePath, mode);
 }
 
 IOChannel::~IOChannel()
 {
+    FileSystem::closeFile(m_fileDescriptor);
 }
 
 Ref<IOChannel> IOChannel::open(const String& filePath, IOChannel::Type type)
@@ -47,14 +60,37 @@
     return adoptRef(*new IOChannel(filePath, type));
 }
 
+static inline void runTaskInQueue(Function<void()>&& task, WorkQueue* queue)
+{
+    if (queue) {
+        queue->dispatch(WTFMove(task));
+        return;
+    }
+
+    // Using nullptr as queue submits the result to the main context.
+    RunLoop::main().dispatch(WTFMove(task));
+}
+
 void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, Function<void(Data&, int error)>&& completionHandler)
 {
-    notImplemented();
+    runTaskInQueue([this, protectedThis = makeRef(*this), offset, size, completionHandler = WTFMove(completionHandler)] {
+        Vector<uint8_t> buffer(size);
+        FileSystem::seekFile(m_fileDescriptor, offset, FileSystem::FileSeekOrigin::Beginning);
+        int err = FileSystem::readFromFile(m_fileDescriptor, reinterpret_cast<char*>(buffer.data()), size);
+        err = err < 0 ? err : 0;
+        auto data = ""
+        completionHandler(data, err);
+    }, queue);
 }
 
 void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, Function<void(int error)>&& completionHandler)
 {
-    notImplemented();
+    runTaskInQueue([this, protectedThis = makeRef(*this), offset, data, completionHandler = WTFMove(completionHandler)] {
+        FileSystem::seekFile(m_fileDescriptor, offset, FileSystem::FileSeekOrigin::Beginning);
+        int err = FileSystem::writeToFile(m_fileDescriptor, reinterpret_cast<const char*>(data.data()), data.size());
+        err = err < 0 ? err : 0;
+        completionHandler(err);
+    }, queue);
 }
 
 } // namespace NetworkCache
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to