-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
test/test_tempfile.rb
Outdated
|
||
def test_create_io_removes_file | ||
Dir.mktmpdir {|d| | ||
tmpio = Tempfile.create_io(nil, d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tmpio = Tempfile.create_io(nil, d) | |
tmpio = Tempfile.create_io("", d) |
lib/tempfile.rb
Outdated
end | ||
end | ||
if tmpio.nil? | ||
mode |= File::SHARE_DELETE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.