<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>254813</bug_id>
          
          <creation_ts>2023-03-31 07:52:06 -0700</creation_ts>
          <short_desc>REGRESSION(259689@main): [GLib] openFile() fails to create files</short_desc>
          <delta_ts>2023-04-25 06:49:33 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKitGTK</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alicia Boya García">aboya</reporter>
          <assigned_to name="Alicia Boya García">aboya</assigned_to>
          <cc>bugs-noreply</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>sihui_liu</cc>
    
    <cc>zdobersek</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1945679</commentid>
    <comment_count>0</comment_count>
    <who name="Alicia Boya García">aboya</who>
    <bug_when>2023-03-31 07:52:06 -0700</bug_when>
    <thetext>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 &apos;/home/ntrrgc/.local/share/WebKitTestRunner/storage/4NoLZrGDXutAmUUf2IXlV4GkA_dI4PpgaXiB2xqjhow/4NoLZrGDXutAmUUf2IXlV4GkA_dI4PpgaXiB2xqjhow/origin&apos;
/app/webkit/Source/WebKit/NetworkProcess/storage/StorageUtilities.h(73) : bool WebKit::writeOriginToFile(const WTF::String &amp;, const WebCore::ClientOrigin &amp;)

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&apos;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() |
+-----------+-------------------------+----------------------------+</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1946990</commentid>
    <comment_count>1</comment_count>
    <who name="Alicia Boya García">aboya</who>
    <bug_when>2023-04-06 07:04:47 -0700</bug_when>
    <thetext>I&apos;m working on a fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1947297</commentid>
    <comment_count>2</comment_count>
    <who name="Alicia Boya García">aboya</who>
    <bug_when>2023-04-07 09:32:14 -0700</bug_when>
    <thetext>This turned out to be a bigger rabbit hole than I expected. I&apos;m not very happy with GIO&apos;s API.

The previous table I made is incorrect, as g_file_replace_readwrite() followed by a close() effectively truncates the file.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1947302</commentid>
    <comment_count>3</comment_count>
    <who name="Alicia Boya García">aboya</who>
    <bug_when>2023-04-07 09:46:01 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/12511</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1951034</commentid>
    <comment_count>4</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-04-25 06:49:30 -0700</bug_when>
    <thetext>Committed 263367@main (78d2561b2bf7): &lt;https://commits.webkit.org/263367@main&gt;

Reviewed commits have been landed. Closing PR #12511 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>