[RFC] Support optional suffix parameter in tempnam

php.internals

Athos Ribeiro

3 years ago
Hi internals, As a follow-up on my previous message here (https://marc.info/?l=php-internals&m=168912164828942&w=2), I would like to start the discussion on the "Support optional suffix parameter in tempnam" RFC. https://wiki.php.net/rfc/tempnam-suffix-v2 The goal is, as suggested by its title, to allow an optional parameter to the tempnam function, which would set a suffix to the created temporary file. This is a take-over on a previous attempt by Stefan Neufeind (https://wiki.php.net/rfc/tempnam-suffix), who I am Ccing for visibility. I left some of my concerns regarding the proposed implementation in the open issues section along with arguments for leaving them as is. Provided no suggestions/discussions arrise from them, I will move them to the future scope section before starting the voting phase for this change. Thanks in advance for any feedback here. regards,
-- Athos Ribeiro

Côme Chilliet

3 years ago
Le mardi 8 août 2023, 21:11:01 CEST Athos Ribeiro a écrit :
> Hi internals, > > As a follow-up on my previous message here > (https://marc.info/?l=php-internals&m=168912164828942&w=2), > I would like to start the discussion on the "Support optional suffix > parameter in tempnam" RFC. > https://wiki.php.net/rfc/tempnam-suffix-v2
Hello, The RFC does not explain what benefits brings using tempnam($directory, $prefix, $suffix) over using tempnam($directory, $prefix).$suffix , which you can already use? Côme

Tim Düsterhus

3 years ago
Hi On 8/14/23 17:57, Côme Chilliet wrote:
> The RFC does not explain what benefits brings using tempnam($directory, $prefix, $suffix) over using tempnam($directory, $prefix).$suffix , which you can already use?
As per the documentation of tempnam:
> Creates a file with a unique filename, with access permission set to 0600, in the specified directory.
The function does not just generate a filename, but also creates the file itself (with strict permissions) to "reserve" it and thus *guarantees* that there won't be a conflict. Manually appending a suffix does not have that property [1]. Best regards Tim Düsterhus [1] Though I'd like to note that using `$prefix . bin2hex(random_bytes(16)) . $suffix` as the filename will almost certainly [2] give you a conflict-free filename and doesn't have OS-specific behavior. That's why I personally don't bother with tempnam(). [2] Collision chance is less than 10^(-7) for 2^52 files.

Athos Ribeiro

3 years ago
On Mon, Aug 14, 2023 at 05:57:53PM +0200, Côme Chilliet wrote:
>Le mardi 8 août 2023, 21:11:01 CEST Athos Ribeiro a écrit : >> Hi internals, >> >> As a follow-up on my previous message here >> (https://marc.info/?l=php-internals&m=168912164828942&w=2), >> I would like to start the discussion on the "Support optional suffix >> parameter in tempnam" RFC. >> https://wiki.php.net/rfc/tempnam-suffix-v2 > >Hello, > >The RFC does not explain what benefits brings using tempnam($directory, $prefix, $suffix) over using tempnam($directory, $prefix).$suffix , which you can already use? > >Côme
Hi Côme, Thanks for the input and for going through the proposal. As the tempnam short description (https://www.php.net/manual/en/function.tempnam.php) states tempnam — __Create__ file with unique file name So tempnam 1) creates a file with specific permissions in a given path ($directory); and 2) returns the full path of the created file on success. For the sole purpose of obtaining a file path (2), I see no reasons for not using "tempnam($directory, $prefix).$suffix" as you suggested. However, to create the temporary file (1) allowing appending a suffix string to the created file, we would need to change tempnam. This is the purpose of this RFC. In other words, although the return value of "tempnam($directory, $prefix).$suffix" and the proposed "tempnam($directory, $prefix, $suffix)" __may__ be the same, the outcome of running each of those, is not. The second paragraph of the RFC introduction says "It would be useful to allow users to also specify a suffix when __generating__ temporary files. [...]" Do you have any suggestions on how we could improve the RFC introduction text to make this clearer to readers of this RFC?
-- Athos Ribeiro

Athos Ribeiro

3 years ago
On Tue, Aug 08, 2023 at 04:11:05PM -0300, Athos Ribeiro wrote:
>I would like to start the discussion on the "Support optional suffix >parameter in tempnam" RFC. >https://wiki.php.net/rfc/tempnam-suffix-v2
Hi, As per item 6 at https://wiki.php.net/rfc/howto#how_to_create_an_rfc, this is a heads up to announce I am moving this to the voting phase tomorrow.
-- Athos Ribeiro