Bug 254813
Summary: | REGRESSION(259689@main): [GLib] openFile() fails to create files | ||
---|---|---|---|
Product: | WebKit | Reporter: | Alicia Boya García <aboya> |
Component: | WebKitGTK | Assignee: | Alicia Boya García <aboya> |
Status: | RESOLVED FIXED | ||
Severity: | Normal | CC: | bugs-noreply, mcatanzaro, sihui_liu, zdobersek |
Priority: | P2 | ||
Version: | WebKit Nightly Build | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
Alicia Boya García
How to reproduce:
$ run-webkit-httpd
$ TEST_RUNNER_TEST_PLUGIN_PATH=this_env_var_is_no_longer_used_and_shouldnt_be_required_but_that_is_work_for_another_patch \
webkit-flatpak --gtk --debug -c \
/app/webkit/WebKitBuild/Debug/bin/WebKitTestRunner --show-window http://localhost:8000/media-resources/media-source/media-source-seek-unbuffered.html
[...]
ERROR: writeOriginToFile: Failed to open origin file '/home/ntrrgc/.local/share/WebKitTestRunner/storage/4NoLZrGDXutAmUUf2IXlV4GkA_dI4PpgaXiB2xqjhow/4NoLZrGDXutAmUUf2IXlV4GkA_dI4PpgaXiB2xqjhow/origin'
/app/webkit/Source/WebKit/NetworkProcess/storage/StorageUtilities.h(73) : bool WebKit::writeOriginToFile(const WTF::String &, const WebCore::ClientOrigin &)
There is nothing wrong about the path above. This is the call that is being made:
auto originFileHandle = FileSystem::openFile(filePath, FileSystem::FileOpenMode::ReadWrite[, failIfFileExists = false]);
The problem is openFile() is using g_file_open_readwrite() in this code path, which fails if the file doesn't exist.
The following is a table of valid GIO functions for creating an stream with permissions requested by WebKit:
+-----------+-------------------------+----------------------------+
| Mode | failIfFileExists | Call |
+-----------+-------------------------+----------------------------+
| Read | (any, will always fail) | g_file_read() |
| Truncate | true | g_file_create() |
| Truncate | false | g_file_replace() |
| ReadWrite | true | g_file_create_readwrite() |
| ReadWrite | false | g_file_replace_readwrite() |
+-----------+-------------------------+----------------------------+
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Alicia Boya García
I'm working on a fix.
Alicia Boya García
This turned out to be a bigger rabbit hole than I expected. I'm not very happy with GIO's API.
The previous table I made is incorrect, as g_file_replace_readwrite() followed by a close() effectively truncates the file.
Alicia Boya García
Pull request: https://github.com/WebKit/WebKit/pull/12511
EWS
Committed 263367@main (78d2561b2bf7): <https://commits.webkit.org/263367@main>
Reviewed commits have been landed. Closing PR #12511 and removing active labels.