Repository navigation
Tempfile.create_io implemented. - #10803
Conversation
Tempfile.create_io creates an unnamed file. It is implemented using Tempfile.create and unlink. It try to use O_TMPFILE available since Linux 3.11.
|
Unfortunately, create-and-unlink can't work on Windows. |
I heard that it is possible on Windows. |
|
Hmm, I've forgot it. |
This comment has been minimized.
This comment has been minimized.
|
I added I searched FILE_SHARE_DELETE. I also found FILE_FLAG_DELETE_ON_CLOSE and FILE_ATTRIBUTE_TEMPORARY. |
|
|
||
| def test_create_io_removes_file | ||
| Dir.mktmpdir {|d| | ||
| tmpio = Tempfile.create_io(nil, d) |
There was a problem hiding this comment.
| tmpio = Tempfile.create_io(nil, d) | |
| tmpio = Tempfile.create_io("", d) |
| end | ||
| end | ||
| if tmpio.nil? | ||
| mode |= File::SHARE_DELETE |
There was a problem hiding this comment.
In w32_wopen, _wopen is used unless binary mode, and it does not have share mode argument.
| mode |= File::SHARE_DELETE | |
| mode |= File::SHARE_DELETE | File::BINARY |
The default value of the 1st argument is "".
nobu's comment: In w32_wopen, _wopen is used unless binary mode, and it does not have share mode argument.
|
I believe we used the same feature for unnamed unix sockets on Windows. |
API changed: `Tempfile.create_io` method is removed. `Tempfile.create` method may take `unlink_first: true`. `Tempfile.create(unlink_first: true)` deletes the created temporary file just after creation.
`Tempfile.create(unlink_first: true)` returns a File object which path method returns the temporary directory with a trailing slash.
private method names renamed.
Ruby 3.4 added the `anonymous:` keyword to Tempfile.create, so update the reference manual to reflect the new method signature and document the new parameter. When `anonymous: true` is given, the temporary file is unlinked immediately after creation to reduce the chance of being accessed via its pathname (while the returned File can still be used). The default remains false, so existing behavior is unchanged. [#10803(ruby/ruby#10803)
Ruby 3.4 added the `anonymous:` keyword to Tempfile.create, so update the reference manual to reflect the new method signature and document the new parameter. When `anonymous: true` is given, the temporary file is unlinked immediately after creation to reduce the chance of being accessed via its pathname (while the returned File can still be used). The default remains false, so existing behavior is unchanged. [#10803](ruby/ruby#10803)
Ruby 3.4 added the `anonymous:` keyword to Tempfile.create, so update the reference manual to reflect the new method signature and document the new parameter. When `anonymous: true` is given, the temporary file is unlinked immediately after creation to reduce the chance of being accessed via its pathname (while the returned File can still be used). The default remains false, so existing behavior is unchanged. [#10803](ruby/ruby#10803)
Tempfile.create_io creates an unnamed file.
It is implemented using Tempfile.create and unlink. It try to use O_TMPFILE available since Linux 3.11.