<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Dec 22, 2016 at 5:52 AM, Rafael Avila de Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> writes:<br>
<br>
> On Wed, Dec 21, 2016 at 9:06 AM, Rafael Avila de Espindola <<br>
> <a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br>
><br>
>> > +// Represents a non-memory-mapped file. We need this class<br>
>> > +// because not all files are mmap'able. For example, /dev/null<br>
>> > +// is not mmap'able.<br>
>><br>
>> The comment is a bit confusing. The issue is that with the old code if<br>
>> you tried to "-o /dev/null", we would not try to mmap /dev/null. We<br>
>> would try to mmap a temp file and move it to /dev/null.<br>
>><br>
>> Maybe the best way to do this is<br>
>> * Check the file type as you did.<br>
>> * Remember the result in a member variable.<br>
>> * If it is regular, use fs::createUniqueFile.<br>
>> * If it is not, use fs::createTemporaryFile, which can also be mmaped.<br>
>> * In commit, do a move if the target is regular or write the contents if<br>
>>   it is not.<br>
>><br>
><br>
> If you want do the same thing until the final rename(2) or file copy, you<br>
> need to create a temporary file in the same directory as the final<br>
> destination file (because the temporary file needs to be in the same file<br>
> system as the final output.) But that's not always doable. For example, if<br>
> the final output is /dev/null, /dev/ is not writable. So I guess this patch<br>
> is reasonable, no?<br>
<br>
</span>That is why I suggested using fs::createTemporaryFile for non regular<br>
files. It will create a file in /tmp.<br></blockquote><div><br></div><div>I don't think using fs::createTemporaryFile is an improvement. Currently, I'm using malloc'ed memory region as a buffer, so it is probably faster than file-system-backed file and will leave nothing if a program crashes unexpectedly. I don't see a benefit of using createTemporaryFile.</div></div></div></div>