Changeset 245186 in webkit


Ignore:
Timestamp:
May 10, 2019 12:01:54 PM (5 years ago)
Author:
Fujii Hironori
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.

Location:
trunk/Source
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r245177 r245186  
     12019-05-10  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        [WinCairo] storage/indexeddb tests are timing out
     4        https://bugs.webkit.org/show_bug.cgi?id=196289
     5
     6        Reviewed by Alex Christensen.
     7
     8        * wtf/FileSystem.h: Added hardLink.
     9        * wtf/glib/FileSystemGlib.cpp:
     10        (WTF::FileSystemImpl::hardLink):
     11        (WTF::FileSystemImpl::hardLinkOrCopyFile):
     12        * wtf/posix/FileSystemPOSIX.cpp:
     13        (WTF::FileSystemImpl::hardLink):
     14        (WTF::FileSystemImpl::hardLinkOrCopyFile):
     15        * wtf/win/FileSystemWin.cpp:
     16        (WTF::FileSystemImpl::hardLink):
     17        (WTF::FileSystemImpl::hardLinkOrCopyFile):
     18        Added hardLink. Let hardLinkOrCopyFile use the hardLink.
     19
    1202019-05-10  Yusuke Suzuki  <ysuzuki@apple.com>
    221
  • trunk/Source/WTF/wtf/FileSystem.h

    r244921 r245186  
    152152WTF_EXPORT_PRIVATE bool appendFileContentsToFileHandle(const String& path, PlatformFileHandle&);
    153153
     154WTF_EXPORT_PRIVATE bool hardLink(const String& source, const String& destination);
    154155// Hard links a file if possible, copies it if not.
    155156WTF_EXPORT_PRIVATE bool hardLinkOrCopyFile(const String& source, const String& destination);
  • trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp

    r240969 r245186  
    430430}
    431431
    432 bool hardLinkOrCopyFile(const String& source, const String& destination)
     432bool hardLink(const String& source, const String& destination)
    433433{
    434434#if OS(WINDOWS)
    435     return !!::CopyFile(source.charactersWithNullTermination().data(), destination.charactersWithNullTermination().data(), TRUE);
     435    return CreateHardLink(destination.wideCharacters().data(), source.wideCharacters().data(), nullptr);
    436436#else
    437437    auto sourceFilename = fileSystemRepresentation(source);
     
    443443        return false;
    444444
    445     if (!link(sourceFilename.data(), destinationFilename.data()))
     445    return !link(sourceFilename.data(), destinationFilename.data());
     446#endif
     447}
     448
     449bool hardLinkOrCopyFile(const String& source, const String& destination)
     450{
     451    if (hardLink(source, destination))
    446452        return true;
    447453
    448454    // Hard link failed. Perform a copy instead.
     455#if OS(WINDOWS)
     456    return !!::CopyFile(source.wideCharacters().data(), destination.wideCharacters().data(), TRUE);
     457#else
     458    auto sourceFilename = fileSystemRepresentation(source);
     459    if (!validRepresentation(sourceFilename))
     460        return false;
     461
     462    auto destinationFilename = fileSystemRepresentation(destination);
     463    if (!validRepresentation(destinationFilename))
     464        return false;
     465
    449466    GRefPtr<GFile> sourceFile = adoptGRef(g_file_new_for_path(sourceFilename.data()));
    450467    GRefPtr<GFile> destinationFile = adoptGRef(g_file_new_for_path(destinationFilename.data()));
  • trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp

    r241654 r245186  
    445445#endif // !PLATFORM(COCOA)
    446446
     447bool hardLink(const String& source, const String& destination)
     448{
     449    if (source.isEmpty() || destination.isEmpty())
     450        return false;
     451
     452    auto fsSource = fileSystemRepresentation(source);
     453    if (!fsSource.data())
     454        return false;
     455
     456    auto fsDestination = fileSystemRepresentation(destination);
     457    if (!fsDestination.data())
     458        return false;
     459
     460    return !link(fsSource.data(), fsDestination.data());
     461}
     462
    447463bool hardLinkOrCopyFile(const String& source, const String& destination)
    448464{
     465    if (hardLink(source, destination))
     466        return true;
     467
     468    // Hard link failed. Perform a copy instead.
    449469    if (source.isEmpty() || destination.isEmpty())
    450470        return false;
    451471
    452     CString fsSource = fileSystemRepresentation(source);
     472    auto fsSource = fileSystemRepresentation(source);
    453473    if (!fsSource.data())
    454474        return false;
    455475
    456     CString fsDestination = fileSystemRepresentation(destination);
     476    auto fsDestination = fileSystemRepresentation(destination);
    457477    if (!fsDestination.data())
    458478        return false;
    459479
    460     if (!link(fsSource.data(), fsDestination.data()))
    461         return true;
    462 
    463     // Hard link failed. Perform a copy instead.
    464480    auto handle = open(fsDestination.data(), O_WRONLY | O_CREAT | O_EXCL, 0666);
    465481    if (handle == -1)
  • trunk/Source/WTF/wtf/win/FileSystemWin.cpp

    r242592 r245186  
    497497}
    498498
     499bool hardLink(const String& source, const String& destination)
     500{
     501    return CreateHardLink(destination.wideCharacters().data(), source.wideCharacters().data(), nullptr);
     502}
     503
    499504bool hardLinkOrCopyFile(const String& source, const String& destination)
    500505{
     506    if (hardLink(source, destination))
     507        return true;
     508
     509    // Hard link failed. Perform a copy instead.
    501510    return !!::CopyFile(source.wideCharacters().data(), destination.wideCharacters().data(), TRUE);
    502511}
  • trunk/Source/WebKit/ChangeLog

    r245185 r245186  
     12019-05-10  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        [WinCairo] storage/indexeddb tests are timing out
     4        https://bugs.webkit.org/show_bug.cgi?id=196289
     5
     6        Reviewed by Alex Christensen.
     7
     8        storage/indexeddb tests were timing out for WinCairo port because
     9        WebKit::NetworkCache classes were not implemented yet for Windows.
     10
     11        Implement WebKit::NetworkCache classes by using WTF::FileSystem
     12        functions.
     13
     14        * NetworkProcess/cache/CacheStorageEngine.cpp:
     15        (WebKit::CacheStorage::Engine::readFile): Use
     16        IOChannel::isOpened() to check the channel is opened instead of
     17        checking the file descriptor.
     18        * NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
     19        (WebKit::NetworkCache::BlobStorage::add):
     20        (WebKit::NetworkCache::BlobStorage::remove):
     21        * NetworkProcess/cache/NetworkCacheData.cpp:
     22        (WebKit::NetworkCache::Data::mapToFile const):
     23        (WebKit::NetworkCache::mapFile):
     24        (WebKit::NetworkCache::adoptAndMapFile):
     25        (WebKit::NetworkCache::makeSalt):
     26        (WebKit::NetworkCache::readOrMakeSalt):
     27        * NetworkProcess/cache/NetworkCacheData.h:
     28        (WebKit::NetworkCache::Data::isEmpty const):
     29        (WebKit::NetworkCache::Data::size const):
     30        * NetworkProcess/cache/NetworkCacheDataCurl.cpp:
     31        (WebKit::NetworkCache::Data::Data):
     32        (WebKit::NetworkCache::Data::empty):
     33        (WebKit::NetworkCache::Data::data const):
     34        (WebKit::NetworkCache::Data::isNull const):
     35        (WebKit::NetworkCache::Data::apply const):
     36        (WebKit::NetworkCache::Data::subrange const):
     37        (WebKit::NetworkCache::concatenate):
     38        (WebKit::NetworkCache::Data::adoptMap): Deleted.
     39        * NetworkProcess/cache/NetworkCacheFileSystem.cpp:
     40        (WebKit::NetworkCache::traverseDirectory):
     41        (WebKit::NetworkCache::fileTimes):
     42        (WebKit::NetworkCache::updateFileModificationTimeIfNeeded):
     43        (WebKit::NetworkCache::isSafeToUseMemoryMapForPath):
     44        * NetworkProcess/cache/NetworkCacheIOChannel.h:
     45        (WebKit::NetworkCache::IOChannel::isOpened const):
     46        (WebKit::NetworkCache::IOChannel::fileDescriptor const): Deleted.
     47        * NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp:
     48        (WebKit::NetworkCache::IOChannel::IOChannel):
     49        (WebKit::NetworkCache::IOChannel::~IOChannel):
     50        (WebKit::NetworkCache::runTaskInQueue):
     51        (WebKit::NetworkCache::IOChannel::read):
     52        (WebKit::NetworkCache::IOChannel::write):
     53
    1542019-05-10  Chris Dumez  <cdumez@apple.com>
    255
  • trunk/Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp

    r244364 r245186  
    424424    m_ioQueue->dispatch([this, weakThis = makeWeakPtr(this), identifier = m_pendingCallbacksCounter, filename = filename.isolatedCopy()]() mutable {
    425425        auto channel = IOChannel::open(filename, IOChannel::Type::Read);
    426         if (channel->fileDescriptor() < 0) {
     426        if (!channel->isOpened()) {
    427427            RunLoop::main().dispatch([this, weakThis = WTFMove(weakThis), identifier]() mutable {
    428428                if (!weakThis)
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp

    r244997 r245186  
    8787BlobStorage::Blob BlobStorage::add(const String& path, const Data& data)
    8888{
    89 #if !OS(WINDOWS)
    9089    ASSERT(!RunLoop::isMain());
    9190
     
    9493        return { data, hash };
    9594
    96     String blobPathString = blobPathForHash(hash);
     95    String blobPath = blobPathForHash(hash);
    9796   
    98     auto blobPath = FileSystem::fileSystemRepresentation(blobPathString);
    99     auto linkPath = FileSystem::fileSystemRepresentation(path);
    100     unlink(linkPath.data());
     97    FileSystem::deleteFile(path);
    10198
    102     bool blobExists = access(blobPath.data(), F_OK) != -1;
     99    bool blobExists = FileSystem::fileExists(blobPath);
    103100    if (blobExists) {
    104         FileSystem::makeSafeToUseMemoryMapForPath(blobPathString);
    105         auto existingData = mapFile(blobPath.data());
     101        FileSystem::makeSafeToUseMemoryMapForPath(blobPath);
     102        auto existingData = mapFile(blobPath);
    106103        if (bytesEqual(existingData, data)) {
    107             if (link(blobPath.data(), linkPath.data()) == -1)
    108                 WTFLogAlways("Failed to create hard link from %s to %s", blobPath.data(), linkPath.data());
     104            if (!FileSystem::hardLink(blobPath, path))
     105                WTFLogAlways("Failed to create hard link from %s to %s", blobPath.utf8().data(), path.utf8().data());
    109106            return { existingData, hash };
    110107        }
    111         unlink(blobPath.data());
     108        FileSystem::deleteFile(blobPath);
    112109    }
    113110
    114     auto mappedData = data.mapToFile(blobPath.data());
     111    auto mappedData = data.mapToFile(blobPath);
    115112    if (mappedData.isNull())
    116113        return { };
    117114
    118     FileSystem::makeSafeToUseMemoryMapForPath(blobPathString);
     115    FileSystem::makeSafeToUseMemoryMapForPath(blobPath);
    119116
    120     if (link(blobPath.data(), linkPath.data()) == -1)
    121         WTFLogAlways("Failed to create hard link from %s to %s", blobPath.data(), linkPath.data());
     117    if (!FileSystem::hardLink(blobPath, path))
     118        WTFLogAlways("Failed to create hard link from %s to %s", blobPath.utf8().data(), path.utf8().data());
    122119
    123120    m_approximateSize += mappedData.size();
    124121
    125122    return { mappedData, hash };
    126 #else
    127     return { Data(), computeSHA1(data, m_salt) };
    128 #endif
    129123}
    130124
     
    143137    ASSERT(!RunLoop::isMain());
    144138
    145     auto linkPath = FileSystem::fileSystemRepresentation(path);
    146     unlink(linkPath.data());
     139    FileSystem::deleteFile(path);
    147140}
    148141
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp

    r240437 r245186  
    4040namespace NetworkCache {
    4141
    42 Data Data::mapToFile(const char* path) const
    43 {
    44 #if !OS(WINDOWS)
    45     int fd = open(path, O_CREAT | O_EXCL | O_RDWR , S_IRUSR | S_IWUSR);
     42#if !OS(WINDOWS)
     43Data Data::mapToFile(const String& path) const
     44{
     45    int fd = open(FileSystem::fileSystemRepresentation(path).data(), O_CREAT | O_EXCL | O_RDWR , S_IRUSR | S_IWUSR);
    4646    if (fd < 0)
    4747        return { };
     
    7272
    7373    return Data::adoptMap(map, m_size, fd);
    74 #else
    75     return Data();
    76 #endif
    77 }
    78 
     74}
     75#else
     76Data Data::mapToFile(const String& path) const
     77{
     78    auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);
     79    if (!FileSystem::isHandleValid(file))
     80        return { };
     81    if (FileSystem::writeToFile(file, reinterpret_cast<const char*>(data()), size()) < 0)
     82        return { };
     83    return Data(Vector<uint8_t>(m_buffer));
     84}
     85#endif
     86
     87#if !OS(WINDOWS)
    7988Data mapFile(const char* path)
    8089{
    81 #if !OS(WINDOWS)
    8290    int fd = open(path, O_RDONLY, 0);
    8391    if (fd < 0)
     
    95103
    96104    return adoptAndMapFile(fd, 0, size);
    97 #else
    98     return Data();
    99 #endif
    100 }
    101 
     105}
     106#endif
     107
     108Data mapFile(const String& path)
     109{
     110#if !OS(WINDOWS)
     111    return mapFile(FileSystem::fileSystemRepresentation(path).data());
     112#else
     113    auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read);
     114    if (!FileSystem::isHandleValid(file))
     115        return { };
     116    long long size;
     117    if (!FileSystem::getFileSize(file, size))
     118        return { };
     119    return adoptAndMapFile(file, 0, size);
     120#endif
     121}
     122
     123#if !OS(WINDOWS)
    102124Data adoptAndMapFile(int fd, size_t offset, size_t size)
    103125{
    104 #if !OS(WINDOWS)
    105126    if (!size) {
    106127        close(fd);
     
    115136
    116137    return Data::adoptMap(map, size, fd);
    117 #else
    118     return Data();
    119 #endif
    120 }
     138}
     139#else
     140Data adoptAndMapFile(FileSystem::PlatformFileHandle file, size_t offset, size_t size)
     141{
     142    return Data(file, offset, size);
     143}
     144#endif
    121145
    122146SHA1::Digest computeSHA1(const Data& data, const Salt& salt)
     
    143167}
    144168
    145 #if !OS(WINDOWS)
    146169static Salt makeSalt()
    147170{
     
    152175    return salt;
    153176}
    154 #endif
    155177
    156178Optional<Salt> readOrMakeSalt(const String& path)
     
    174196    return salt;
    175197#else
    176     return Salt();
     198    auto file = FileSystem::openFile(path, FileSystem::FileOpenMode::Read);
     199    Salt salt;
     200    auto bytesRead = FileSystem::readFromFile(file, reinterpret_cast<char*>(salt.data()), salt.size());
     201    FileSystem::closeFile(file);
     202    if (bytesRead != salt.size()) {
     203        salt = makeSalt();
     204
     205        FileSystem::deleteFile(path);
     206        file = FileSystem::openFile(path, FileSystem::FileOpenMode::Write);
     207        bool success = FileSystem::writeToFile(file, reinterpret_cast<char*>(salt.data()), salt.size()) == salt.size();
     208        FileSystem::closeFile(file);
     209        if (!success)
     210            return { };
     211    }
     212    return salt;
    177213#endif
    178214}
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h

    r241283 r245186  
    2626#pragma once
    2727
     28#include <wtf/FileSystem.h>
    2829#include <wtf/FunctionDispatcher.h>
    2930#include <wtf/SHA1.h>
     
    5354
    5455    static Data empty();
     56#if !OS(WINDOWS)
    5557    static Data adoptMap(void* map, size_t, int fd);
     58#endif
    5659
    5760#if PLATFORM(COCOA)
     
    6164#if USE(SOUP)
    6265    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);
    6369#endif
    6470    bool isNull() const;
     
    7480    bool apply(const Function<bool (const uint8_t*, size_t)>&) const;
    7581
    76     Data mapToFile(const char* path) const;
     82    Data mapToFile(const String& path) const;
    7783
    7884#if PLATFORM(COCOA)
     
    9197    int m_fileDescriptor { -1 };
    9298#endif
     99#if OS(WINDOWS)
     100    Vector<uint8_t> m_buffer;
     101#endif
    93102    mutable const uint8_t* m_data { nullptr };
    94103    size_t m_size { 0 };
     
    98107Data concatenate(const Data&, const Data&);
    99108bool bytesEqual(const Data&, const Data&);
    100 Data adoptAndMapFile(int fd, size_t offset, size_t);
     109#if !OS(WINDOWS)
     110Data adoptAndMapFile(int, size_t offset, size_t);
     111#else
     112Data adoptAndMapFile(FileSystem::PlatformFileHandle, size_t offset, size_t);
     113#endif
    101114#if USE(GLIB) && !PLATFORM(WIN)
    102115Data adoptAndMapFile(GFileIOStream*, size_t offset, size_t);
    103116#endif
     117#if !OS(WINDOWS)
    104118Data mapFile(const char* path);
     119#endif
     120Data mapFile(const String& path);
    105121
    106122using Salt = std::array<uint8_t, 8>;
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheDataCurl.cpp

    r226465 r245186  
    2727#include "NetworkCacheData.h"
    2828
    29 #include <WebCore/NotImplemented.h>
    30 
    3129namespace WebKit {
    3230namespace NetworkCache {
     
    3432Data::Data(const uint8_t* data, size_t size)
    3533{
    36     notImplemented();
     34    m_buffer.resize(size);
     35    m_size = size;
     36    memcpy(m_buffer.data(), data, size);
     37}
     38
     39Data::Data(FileSystem::PlatformFileHandle file, size_t offset, size_t size)
     40{
     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
     48Data::Data(Vector<uint8_t>&& buffer)
     49    : m_buffer(WTFMove(buffer))
     50{
     51    m_size = m_buffer.size();
    3752}
    3853
    3954Data Data::empty()
    4055{
    41     notImplemented();
    4256    return { };
    4357}
     
    4559const uint8_t* Data::data() const
    4660{
    47     notImplemented();
    48     return nullptr;
     61    return m_buffer.data();
    4962}
    5063
    5164bool Data::isNull() const
    5265{
    53     notImplemented();
    54     return true;
     66    return m_buffer.isEmpty();
    5567}
    5668
    5769bool Data::apply(const Function<bool(const uint8_t*, size_t)>& applier) const
    5870{
    59     notImplemented();
    60     return false;
     71    if (isEmpty())
     72        return false;
     73
     74    return applier(reinterpret_cast<const uint8_t*>(m_buffer.data()), m_buffer.size());
    6175}
    6276
    6377Data Data::subrange(size_t offset, size_t size) const
    6478{
    65     return { };
     79    return { m_buffer.data() + offset, size };
    6680}
    6781
    6882Data concatenate(const Data& a, const Data& b)
    6983{
    70     notImplemented();
    71     return { };
    72 }
    73 
    74 Data Data::adoptMap(void* map, size_t size, int fd)
    75 {
    76     notImplemented();
    77     return { };
     84    Vector<uint8_t> buffer(a.size() + b.size());
     85    memcpy(buffer.data(), a.data(), a.size());
     86    memcpy(buffer.data() + a.size(), b.data(), b.size());
     87    return Data(WTFMove(buffer));
    7888}
    7989
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp

    r244921 r245186  
    8888    closedir(dir);
    8989#else
    90     function(String(), DirectoryEntryType::File);
     90    auto entries = FileSystem::listDirectory(path);
     91    for (auto& entry : entries) {
     92        auto type = FileSystem::fileIsDirectory(entry, FileSystem::ShouldFollowSymbolicLinks::No) ? DirectoryEntryType::Directory : DirectoryEntryType::File;
     93        function(entry, type);
     94    }
    9195#endif
    9296}
     
    128132        WallTime::fromRawSeconds(g_file_info_get_attribute_uint64(fileInfo.get(), "time::modified")) };
    129133#elif OS(WINDOWS)
    130     return FileTimes();
     134    auto createTime = FileSystem::getFileCreationTime(path);
     135    auto modifyTime = FileSystem::getFileModificationTime(path);
     136    return { createTime.valueOr(WallTime()), modifyTime.valueOr(WallTime()) };
    131137#endif
    132138}
     
    143149    // This really updates both the access time and the modification time.
    144150    utimes(FileSystem::fileSystemRepresentation(path).data(), nullptr);
     151#else
     152    FILETIME time;
     153    GetSystemTimeAsFileTime(&time);
     154    auto file = CreateFile(path.wideCharacters().data(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
     155    if (file == INVALID_HANDLE_VALUE)
     156        return;
     157    SetFileTime(file, &time, &time, &time);
     158    CloseHandle(file);
    145159#endif
    146160}
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannel.h

    r232528 r245186  
    5353    Type type() const { return m_type; }
    5454
    55     int fileDescriptor() const { return m_fileDescriptor; }
     55#if !USE(SOUP)
     56    bool isOpened() const { return FileSystem::isHandleValid(m_fileDescriptor); }
     57#else
     58    bool isOpened() const { return true; }
     59#endif
    5660
    5761    ~IOChannel();
     
    6771    Type m_type;
    6872
    69     int m_fileDescriptor { 0 };
     73#if !USE(SOUP)
     74    FileSystem::PlatformFileHandle m_fileDescriptor { FileSystem::invalidPlatformFileHandle };
     75#endif
    7076    std::atomic<bool> m_wasDeleted { false }; // Try to narrow down a crash, https://bugs.webkit.org/show_bug.cgi?id=165659
    7177#if PLATFORM(COCOA)
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelCurl.cpp

    r226465 r245186  
    2727#include "NetworkCacheIOChannel.h"
    2828
    29 #include <WebCore/NotImplemented.h>
     29#include <wtf/RunLoop.h>
    3030
    3131namespace WebKit {
     
    3333
    3434IOChannel::IOChannel(const String& filePath, Type type)
    35     : m_path{filePath}
    36     , m_type{type}
     35    : m_path(filePath)
     36    , m_type(type)
    3737{
    38     notImplemented();
     38    FileSystem::FileOpenMode mode;
     39    switch (type) {
     40    case Type::Read:
     41        mode = FileSystem::FileOpenMode::Read;
     42        break;
     43    case Type::Write:
     44        mode = FileSystem::FileOpenMode::Write;
     45        break;
     46    case Type::Create:
     47        mode = FileSystem::FileOpenMode::Write;
     48        break;
     49    }
     50    m_fileDescriptor = FileSystem::openFile(filePath, mode);
    3951}
    4052
    4153IOChannel::~IOChannel()
    4254{
     55    FileSystem::closeFile(m_fileDescriptor);
    4356}
    4457
     
    4861}
    4962
     63static inline void runTaskInQueue(Function<void()>&& task, WorkQueue* queue)
     64{
     65    if (queue) {
     66        queue->dispatch(WTFMove(task));
     67        return;
     68    }
     69
     70    // Using nullptr as queue submits the result to the main context.
     71    RunLoop::main().dispatch(WTFMove(task));
     72}
     73
    5074void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, Function<void(Data&, int error)>&& completionHandler)
    5175{
    52     notImplemented();
     76    runTaskInQueue([this, protectedThis = makeRef(*this), offset, size, completionHandler = WTFMove(completionHandler)] {
     77        Vector<uint8_t> buffer(size);
     78        FileSystem::seekFile(m_fileDescriptor, offset, FileSystem::FileSeekOrigin::Beginning);
     79        int err = FileSystem::readFromFile(m_fileDescriptor, reinterpret_cast<char*>(buffer.data()), size);
     80        err = err < 0 ? err : 0;
     81        auto data = Data(WTFMove(buffer));
     82        completionHandler(data, err);
     83    }, queue);
    5384}
    5485
    5586void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, Function<void(int error)>&& completionHandler)
    5687{
    57     notImplemented();
     88    runTaskInQueue([this, protectedThis = makeRef(*this), offset, data, completionHandler = WTFMove(completionHandler)] {
     89        FileSystem::seekFile(m_fileDescriptor, offset, FileSystem::FileSeekOrigin::Beginning);
     90        int err = FileSystem::writeToFile(m_fileDescriptor, reinterpret_cast<const char*>(data.data()), data.size());
     91        err = err < 0 ? err : 0;
     92        completionHandler(err);
     93    }, queue);
    5894}
    5995
Note: See TracChangeset for help on using the changeset viewer.