dagolden / Path-Tiny

File path utility
41 stars 59 forks source link

spew can die with "File name too long" #222

Closed regina-verbae closed 1 year ago

regina-verbae commented 5 years ago

On a filesystem with a maximum filename size of 256, the following will die because of the naming scheme of the temporary file used within spew:

path("LONG!" x 51)->spew(@data);

In this case, the target filename is legal, but the name of the temporary file is not.

A possible solution would be to set $temp = tempfile(DIR => $resolved_path->parent). I'm sure there is good reason, however, why that approach was not used at the offset. I suppose this could work:

$temp = $resolved_path->sibling($$ . int( rand( 2**31 ) ));

I would feel compelled to make sure that file didn't already exist before writing to it. Admittedly, I would add that check in the current code. I recognize that I am paranoid from years of working with data that delights in hitting edge cases, but it is not impossible for those added random digits to stomp an existing file...

xdg commented 1 year ago

Side note: the temp files are opened with O_EXCL so will fail if the file already exists