Skip to content

Tempfile.open { ... } does not unlink the file #2

@eregon

Description

@eregon
ruby -rtempfile -e 'Tempfile.open("txt") { |f| $path = f.path }; p File.exist?($path)'
true

but it should be false.

This means even after the block finishes to execute the file still exists on a disk
And this might or not be addressed by finalization much later on.

This is inconsistent with the resource block pattern and e.g. File.open.

Since the block creates the file, it should also delete it, so there are no leftovers after the block.

How about using close! instead of close in

tempfile.close
?

Found by ruby/spec@d347e89 and the leak detector.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions