<table><tr><td style="">dfaure requested changes to this revision.<br />dfaure added a comment.<br />This revision now requires changes to proceed.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D8254" rel="noreferrer">View Revision</a></tr></table><br /><div><div><p>I suppose <tt style="background: #ebebeb; font-size: 13px;">put()</tt> should do the same, then?</p></div></div><br /><div><strong>INLINE COMMENTS</strong><div><div style="margin: 6px 0 12px 0;"><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D8254#inline-41019" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">file_unix.cpp:72</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span style="color: #74777d"> */</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span style="color: #aa4000">static</span> <span class="n">QString</span> <span style="color: #004012">blockDeviceByPath</span><span class="p">(</span><span style="color: #aa4000">const</span> <span class="n">QString</span> <span style="color: #aa2211">&</span><span class="n">filename</span><span class="p">)</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span class="p">{</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Doesn't KMountPoint::currentMountPoints + findByPath already do this?</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D8254#inline-41020" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">file_unix.cpp:107</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span style="color: #74777d"> */</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span style="color: #74777d">// TODO move it to KMountPoint?</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span style="color: #aa4000">static</span> <span style="color: #aa4000">int</span> <span style="color: #004012">statsDeviceByFile</span><span class="p">(</span><span style="color: #aa4000">const</span> <span class="n">QString</span> <span style="color: #aa2211">&</span><span class="n">filename</span><span class="p">,</span> <span style="color: #aa4000">int</span> <span style="color: #aa2211">&</span><span class="n">max_hw_single_transfer_chunk</span><span class="p">,</span> <span style="color: #aa4000">bool</span> <span style="color: #aa2211">&</span><span class="n">is_removeable</span><span class="p">)</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Probably not, I don't see another user than kio_file for such detailed information.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D8254#inline-41021" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">file_unix.cpp:226</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span class="bright"> </span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #74777d">// set default is non removable and chunk size 512k</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">int</span> <span class="n">block_size</span> <span style="color: #aa2211">=</span> <span style="color: #601200">1024</span> <span style="color: #aa2211">*</span> <span style="color: #601200">1024</span> <span style="color: #aa2211">*</span> <span style="color: #601200">1</span><span class="p">;</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">... and then the code says 1024*1024 ;)</p>
<p style="padding: 0; margin: 8px;">A comment shouldn't say "what" (the code does that), but "why".<br />
If there's no need to document "why", remove the comment.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D8254#inline-41022" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">file_unix.cpp:229</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">bool</span> <span class="n">is_removeable</span> <span style="color: #aa2211">=</span> <span style="color: #304a96">false</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">statsDeviceByFile</span><span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="n">block_size</span><span class="p">,</span> <span class="n">is_removeable</span><span class="p">);</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">make that &block_size and &is_removeable so that when reading this line it's clear that those are in+out vars.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D8254#inline-41023" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">file_unix.cpp:232</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #74777d">// minimum block size 1M</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">if</span><span class="p">(</span> <span class="n">block_size</span> <span style="color: #aa2211"><</span> <span class="p">(</span><span style="color: #601200">1024</span> <span style="color: #aa2211">*</span> <span style="color: #601200">1024</span> <span style="color: #aa2211">*</span> <span style="color: #601200">1</span><span class="p">)</span> <span class="p">)</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">block_size</span> <span style="color: #aa2211">=</span> <span class="p">(</span><span style="color: #601200">1024</span> <span style="color: #aa2211">*</span> <span style="color: #601200">1024</span> <span style="color: #aa2211">*</span> <span style="color: #601200">1</span><span class="p">);</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">use std::clamp, this way you won't even have to repeat the min and max values.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D8254#inline-41024" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">file_unix.cpp:241</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; "> <span class="n">QFile</span> <span style="color: #004012">dest_file</span><span class="p">(</span><span class="n">dest</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span style="color: #aa4000">i<span class="bright">f</span></span><span class="bright"> </span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span style="color: #aa2211"><span class="bright">!</span></span><span class="bright"></span><span class="n"><span class="bright">dest_file</span></span><span class="bright"></span><span class="p"><span class="bright">.</span></span><span class="bright"></span><span class="n"><span class="bright">open</span></span><span class="bright"></span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span class="n"><span class="bright">QIODevice</span></span><span class="bright"></span><span style="color: #aa2211"><span class="bright">::</span></span><span class="bright"></span><span class="n"><span class="bright">Truncate</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">|</span></span><span class="bright"> </span><span class="n"><span class="bright">QIODevice</span></span><span class="bright"></span><span style="color: #aa2211"><span class="bright">::</span></span><span class="bright"></span><span class="n"><span class="bright">WriteOnly</span></span><span class="bright"></span><span class="p"><span class="bright">))</span></span><span class="bright"> </span><span class="p"><span class="bright">{</span></span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">i<span class="bright">nt</span></span><span class="bright"> </span><span class="n"><span class="bright">dest_fd</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">=</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">::</span></span><span class="bright"></span><span class="n"><span class="bright">open</span></span><span class="bright"></span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span class="n"><span class="bright">dest</span></span><span class="bright"></span><span class="p"><span class="bright">.</span></span><span class="bright"></span><span class="n"><span class="bright">toStdString</span></span><span class="bright"></span><span class="p"><span class="bright">().</span></span><span class="bright"></span><span class="n"><span class="bright">c_str</span></span><span class="bright"></span><span class="p"><span class="bright">(),</span></span><span class="bright"> </span><span class="n"><span class="bright">O_CREAT</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">|</span></span><span class="bright"> </span><span class="n"><span class="bright">O_TRUNC</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">|</span></span><span class="bright"> </span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span class="n"><span class="bright">is_removeable</span></span><span class="bright"></span><span style="color: #aa2211"><span class="bright">?</span></span><span class="bright"> </span><span style="color: #a0a000"><span class="bright">O_SYNC</span></span><span class="bright"> </span><span class="p"><span class="bright">:</span></span><span class="bright"> </span><span style="color: #601200"><span class="bright">0</span></span><span class="bright"></span><span class="p"><span class="bright">)</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">|</span></span><span class="bright"> </span><span class="n"><span class="bright">O_WRONLY</span></span><span class="bright"></span><span class="p"><span class="bright">);</span></span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">if</span> <span class="p">(</span><span style="color: #aa2211">!</span><span class="n">dest_file</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="n">dest_fd</span><span class="p">,</span> <span class="n">QIODevice</span><span style="color: #aa2211">::</span><span class="n">Truncate</span> <span style="color: #aa2211">|</span> <span class="n">QIODevice</span><span style="color: #aa2211">::</span><span class="n">WriteOnly</span><span class="p">,</span> <span class="n">QFile</span><span style="color: #aa2211">::</span><span class="n">AutoCloseHandle</span><span class="p">))</span> <span class="p">{</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">The conversion via std::string is incorrect, encoding wise.</p>
<p style="padding: 0; margin: 8px;">The way to pass a QString (for a filename) to a system call is QFile::encodeName().</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D8254#inline-41025" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">file_unix.cpp:289</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; "><span style="color: #304a96">#endif</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">n</span> <span style="color: #aa2211">=</span> <span style="color: #aa2211">::</span><span class="n">read</span><span class="p">(</span><span class="n">src_file</span><span class="p">.</span><span class="n">handle</span><span class="p">(),</span> <span class="n">buffer<span class="bright"></span></span><span class="bright"></span><span class="p"><span class="bright">,</span></span><span class="bright"> </span><span class="n"><span class="bright">MAX_IPC_SIZE</span></span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">n</span> <span style="color: #aa2211">=</span> <span style="color: #aa2211">::</span><span class="n">read</span><span class="p">(</span><span class="n">src_file</span><span class="p">.</span><span class="n">handle</span><span class="p">(),</span> <span class="bright"></span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span style="color: #aa4000"><span class="bright">void</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">*</span></span><span class="bright"></span><span class="p"><span class="bright">)</span></span><span class="bright"></span><span style="color: #aa2211"><span class="bright">&</span></span><span class="bright"></span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span style="color: #aa2211"><span class="bright">*</span></span><span class="n">buffer<span class="bright"></span></span><span class="bright"></span><span class="p"><span class="bright">),</span></span><span class="bright"> </span><span class="n"><span class="bright">block_size</span></span><span class="p">);</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">C casts make me puke ;)<br />
The C++ way would be reinterpret_cast, but I don't think you even need that. It compiled with a char* before, so just use <tt style="background: #ebebeb; font-size: 13px;">buffer.data()</tt></p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D8254#inline-41026" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">file_unix.cpp:324</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; "><span style="color: #304a96">#endif</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span style="color: #aa4000">if</span> <span class="p">(</span><span class="n">dest_file</span><span class="p">.</span><span class="n">write</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span> <span style="color: #aa2211">!=</span> <span class="n">n</span><span class="p">)</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">if</span> <span class="p">(</span><span class="n">dest_file</span><span class="p">.</span><span class="n">write</span><span class="p">(<span class="bright"></span></span><span class="bright"></span><span style="color: #aa2211"><span class="bright">&</span></span><span class="bright"></span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span style="color: #aa2211"><span class="bright">*</span></span><span class="n">buffer<span class="bright"></span></span><span class="bright"></span><span class="p"><span class="bright">)</span>,</span> <span class="n">n</span><span class="p">)</span> <span style="color: #aa2211">!=</span> <span class="n">n</span><span class="p">)</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; "> <span style="color: #aa4000">if</span> <span class="p">(</span><span class="n">dest_file</span><span class="p">.</span><span class="n">error</span><span class="p">()</span> <span style="color: #aa2211">==</span> <span class="n">QFileDevice</span><span style="color: #aa2211">::</span><span class="n">ResourceError</span><span class="p">)</span> <span class="p">{</span> <span style="color: #74777d">// disk full</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">.data() is more readable</p></div></div></div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R241 KIO</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D8254" rel="noreferrer">https://phabricator.kde.org/D8254</a></div></div><br /><div><strong>To: </strong>vova7890, Frameworks, dfaure<br /><strong>Cc: </strong>dfaure, ngraham, alexeymin, Frameworks<br /></div>