<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jun 6, 2014 at 3:32 PM, David T. Lewis <span dir="ltr">&lt;<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
On Fri, Jun 06, 2014 at 11:25:23AM -0700, Eliot Miranda wrote:<br>
&gt;<br>
&gt; On Fri, Jun 6, 2014 at 9:33 AM, Douglas McPherson &lt;<a href="mailto:djm1329@san.rr.com">djm1329@san.rr.com</a>&gt;<br>
&gt; wrote:<br>
&gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; On Jun 5, 2014, at 21:03 , David T. Lewis wrote:<br>
&gt; &gt;<br>
&gt; &gt; &gt; On Thu, Jun 05, 2014 at 06:50:31PM +0200, Bert Freudenberg wrote:<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; On 04.06.2014, at 18:19, Douglas McPherson &lt;<a href="mailto:djm1329@san.rr.com">djm1329@san.rr.com</a>&gt; wrote:<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt; Hi All,<br>
&gt; &gt; &gt;&gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt; I&#39;ve tested a fix for this on OS X and Linux. The fix simply adds an<br>
&gt; &gt; extra attempt to open the file after the &quot;w+b&quot; attempt using this code:<br>
&gt; &gt; &gt;&gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt;         if (getFile(f) == NULL) {<br>
&gt; &gt; &gt;&gt;&gt;            setFile(f, fopen(cFileName, &quot;wb&quot;));<br>
&gt; &gt; &gt;&gt;&gt;         }<br>
&gt; &gt; &gt;&gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt; If the previous attempts to open the file failed (because the file<br>
&gt; &gt; exists with write-only permission, no read permission) then the above will<br>
&gt; &gt; actually open the file write-only. Adding the extra attempt preserves<br>
&gt; &gt; existing behaviour for the success paths, so the change should be<br>
&gt; &gt; transparent to existing code.<br>
&gt; &gt; &gt;&gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt; BTW, AFAICT the same issue exists in Pharo.<br>
&gt; &gt; &gt;&gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt; Thoughts?<br>
&gt; &gt; &gt;&gt;&gt;<br>
&gt; &gt; &gt;&gt;&gt; Doug<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; Sounds reasonable to me.<br>
&gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt;&gt; - Bert -<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; I have not tested it yet, but I think that this would truncate an<br>
&gt; &gt; existing file,<br>
&gt; &gt; &gt; so that if the write-only file exists and contains data, the data would<br>
&gt; &gt; be lost.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Doug, could you check this with your patched VM?<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Thanks,<br>
&gt; &gt; &gt; Dave<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Hi Dave,<br>
&gt; &gt;<br>
&gt; &gt; Yes you are right, I didn&#39;t think of that. That is indeed what happens.<br>
&gt; &gt;<br>
&gt; &gt; We could use &quot;ab&quot; instead of &quot;wb&quot; to get append behaviour if the file<br>
&gt; &gt; already exists. I think &quot;a&quot; is still a write-only mode. This is probably<br>
&gt; &gt; safer.<br>
&gt; &gt;<br>
&gt;<br>
&gt; OK.  Then I propose to commit the following:<br>
&gt;<br>
&gt; --- platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c (revision<br>
&gt; 2888)<br>
&gt; +++ platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c (working<br>
&gt; copy)<br>
&gt; @@ -245,6 +245,9 @@<br>
&gt;                            try opening it in write mode to create a new,<br>
&gt; empty file.<br>
&gt;                         */<br>
&gt;                         setFile(f, fopen(cFileName, &quot;w+b&quot;));<br>
&gt; +                       /* and if w+b fails, try ab (not wb which deletes<br>
&gt; read-only files) */<br>
&gt; +                       if (getFile(f) == NULL)<br>
&gt; +                               setFile(f, fopen(cFileName, &quot;ab&quot;));<br>
&gt;                         if (getFile(f) != NULL) {<br>
&gt;                             char type[4],creator[4];<br>
&gt;                                 dir_GetMacFileTypeAndCreator(sqFileName,<br>
&gt; sqFileNameSize, type, creator);<br>
&gt;<br>
<br>
</div></div>This fixes the problem but does not preserve existing behaviour WRT updating<br>
Mac file characteristics, whatever that might happen to mean. Please no rants<br>
about keeping Mac stuff in Cross, but given what we have now I think that a<br>
more compatible fix is:<br>
<div class=""><br>
                /* First try to open an existing file read/write: */<br>
                setFile(f, fopen(cFileName, &quot;r+b&quot;));<br>
                if (getFile(f) == NULL) {<br>
                        /* Previous call fails if file does not exist. In that case,<br>
                           try opening it in write mode to create a new, empty file.<br>
                        */<br>
                        setFile(f, fopen(cFileName, &quot;w+b&quot;));<br>
                        if (getFile(f) != NULL) {<br>
</div>                            /* New file created, set Mac file characteristics */<br>
<div class="">                            char type[4],creator[4];<br>
                                dir_GetMacFileTypeAndCreator(sqFileName, sqFileNameSize, type, creator);<br>
                                if (strncmp(type,&quot;BINA&quot;,4) == 0 || strncmp(type,&quot;????&quot;,4) == 0 || *(int *)type == 0 )<br>
                                    dir_SetMacFileTypeAndCreator(sqFileName, sqFileNameSize,&quot;TEXT&quot;,&quot;R*ch&quot;);<br>
</div>                        } else { /* if (getFile(f) == NULL) */<br>
                                /* If the file could not be opened read/write and if a new file<br>
                                   could not be created, then it may be that the file exists but<br>
                                   does not permit read access. Try opening as a write only file,<br>
                                   opened for append to preserve existing file contents.<br>
                                */<br>
                                setFile(f, fopen(cFileName, &quot;ab&quot;));<br>
                                if (getFile(f) == NULL) {<br>
                                        return interpreterProxy-&gt;success(false);<br>
                                }<br>
                        }<br>
                }<br>
<br>
If no objections, I&#39;ll update Eliot&#39;s update tomorrow.<br></blockquote><div><br></div><div>Oops.  Good catch.  Fine with me.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
Dave<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div></div>