Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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.


Canonical link: https://commits.webkit.org/211925@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245186 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
fujii committed May 10, 2019
1 parent 2af76a3 commit 2ad27c2
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 72 deletions.
19 changes: 19 additions & 0 deletions Source/WTF/ChangeLog
@@ -1,3 +1,22 @@
2019-05-10 Fujii Hironori <Hironori.Fujii@sony.com>

[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 <ysuzuki@apple.com>

[WTF] Remove "private:" from Noncopyable and Nonmovable macros
Expand Down
1 change: 1 addition & 0 deletions Source/WTF/wtf/FileSystem.h
Expand Up @@ -151,6 +151,7 @@ WTF_EXPORT_PRIVATE void unlockAndCloseFile(PlatformFileHandle);
// 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);

Expand Down
23 changes: 20 additions & 3 deletions Source/WTF/wtf/glib/FileSystemGlib.cpp
Expand Up @@ -429,10 +429,10 @@ bool moveFile(const String& oldPath, const String& newPath)
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))
Expand All @@ -442,10 +442,27 @@ bool hardLinkOrCopyFile(const String& source, const String& destination)
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);
Expand Down
24 changes: 20 additions & 4 deletions Source/WTF/wtf/posix/FileSystemPOSIX.cpp
Expand Up @@ -444,23 +444,39 @@ String openTemporaryFile(const String& prefix, PlatformFileHandle& handle)
}
#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;
Expand Down
9 changes: 9 additions & 0 deletions Source/WTF/wtf/win/FileSystemWin.cpp
Expand Up @@ -496,8 +496,17 @@ int readFromFile(PlatformFileHandle handle, char* data, int length)
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);
}

Expand Down
53 changes: 53 additions & 0 deletions Source/WebKit/ChangeLog
@@ -1,3 +1,56 @@
2019-05-10 Fujii Hironori <Hironori.Fujii@sony.com>

[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 <cdumez@apple.com>

Do not wait until requestPermission() is called to fire deviceorientation events if permission was already granted
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/NetworkProcess/cache/CacheStorageEngine.cpp
Expand Up @@ -423,7 +423,7 @@ void Engine::readFile(const String& filename, CompletionHandler<void(const Netwo
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;
Expand Down
33 changes: 13 additions & 20 deletions Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp
Expand Up @@ -86,46 +86,40 @@ String BlobStorage::blobPathForHash(const SHA1::Digest& hash) const

BlobStorage::Blob BlobStorage::add(const String& path, const Data& data)
{
#if !OS(WINDOWS)
ASSERT(!RunLoop::isMain());

auto hash = computeSHA1(data, m_salt);
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)
Expand All @@ -142,8 +136,7 @@ void BlobStorage::remove(const String& path)
{
ASSERT(!RunLoop::isMain());

auto linkPath = FileSystem::fileSystemRepresentation(path);
unlink(linkPath.data());
FileSystem::deleteFile(path);
}

unsigned BlobStorage::shareCount(const String& path)
Expand Down
62 changes: 49 additions & 13 deletions Source/WebKit/NetworkProcess/cache/NetworkCacheData.cpp
Expand Up @@ -39,10 +39,10 @@
namespace WebKit {
namespace NetworkCache {

Data Data::mapToFile(const char* path) const
{
#if !OS(WINDOWS)
int fd = open(path, O_CREAT | O_EXCL | O_RDWR , S_IRUSR | S_IWUSR);
Data Data::mapToFile(const String& path) const
{
int fd = open(FileSystem::fileSystemRepresentation(path).data(), O_CREAT | O_EXCL | O_RDWR , S_IRUSR | S_IWUSR);
if (fd < 0)
return { };

Expand Down Expand Up @@ -71,14 +71,22 @@ Data Data::mapToFile(const char* path) const
msync(map, m_size, MS_ASYNC);

return Data::adoptMap(map, m_size, fd);
}
#else
return Data();
#endif
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 { };
Expand All @@ -94,14 +102,27 @@ Data mapFile(const char* path)
}

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();
Expand All @@ -114,10 +135,13 @@ Data adoptAndMapFile(int fd, size_t offset, size_t size)
}

return Data::adoptMap(map, size, fd);
}
#else
return Data();
#endif
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)
{
Expand All @@ -142,7 +166,6 @@ bool bytesEqual(const Data& a, const Data& b)
return !memcmp(a.data(), b.data(), a.size());
}

#if !OS(WINDOWS)
static Salt makeSalt()
{
Salt salt;
Expand All @@ -151,7 +174,6 @@ static Salt makeSalt()
*reinterpret_cast<uint32_t*>(&salt[4]) = cryptographicallyRandomNumber();
return salt;
}
#endif

Optional<Salt> readOrMakeSalt(const String& path)
{
Expand All @@ -173,7 +195,21 @@ Optional<Salt> readOrMakeSalt(const String& path)
}
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
}

Expand Down

0 comments on commit 2ad27c2

Please sign in to comment.