[#99856] [Ruby master Feature#17143] Improve support for warning categories — merch-redmine@...

Issue #17143 has been reported by jeremyevans0 (Jeremy Evans).

16 messages 2020/09/03

[#99868] [Ruby master Bug#17144] Tempfile.open { ... } does not unlink the file — eregontp@...

Issue #17144 has been reported by Eregon (Benoit Daloze).

15 messages 2020/09/03

[#99885] [Ruby master Feature#17145] Ractor-aware `Object#deep_freeze` — marcandre-ruby-core@...

Issue #17145 has been reported by marcandre (Marc-Andre Lafortune).

32 messages 2020/09/03

[#99903] [Ruby master Bug#17146] Queue operations are allowed after it is frozen — eregontp@...

Issue #17146 has been reported by Eregon (Benoit Daloze).

16 messages 2020/09/03

[#100016] [Ruby master Feature#17171] Why is the visibility of constants not affected by `private`? — marcandre-ruby-core@...

Issue #17171 has been reported by marcandre (Marc-Andre Lafortune).

10 messages 2020/09/15

[#100024] [Ruby master Bug#17175] Ruby 2.5: OpenSSL related test failures — jaruga@...

Issue #17175 has been reported by jaruga (Jun Aruga).

10 messages 2020/09/16

[#100025] [Ruby master Feature#17176] GC.enable_autocompact / GC.disable_autocompact — tenderlove@...

Issue #17176 has been reported by tenderlovemaking (Aaron Patterson).

11 messages 2020/09/16

[#100099] [Ruby master Bug#17184] No stdlib function to perform simple string replacement — sheerun@...

Issue #17184 has been reported by sheerun (Adam Stankiewicz).

18 messages 2020/09/24

[#100192] [Ruby master Bug#17197] Some Hash methods still have arity 2 instead of 1 — marcandre-ruby-core@...

Issue #17197 has been reported by marcandre (Marc-Andre Lafortune).

14 messages 2020/09/28

[#100200] [Ruby master Misc#17199] id outputed by inspect and to_s output does not allow to find actual object_id and vice-versa — baptiste.courtois@...

Issue #17199 has been reported by Annih (Baptiste Courtois).

7 messages 2020/09/28

[#100206] [Ruby master Misc#17200] DevelopersMeeting20201026Japan — mame@...

Issue #17200 has been reported by mame (Yusuke Endoh).

18 messages 2020/09/28

[#100239] [Ruby master Feature#17206] Introduce new Regexp option to avoid MatchData allocation — fatkodima123@...

Issue #17206 has been reported by fatkodima (Dima Fatko).

8 messages 2020/09/30

[ruby-core:99881] [Ruby master Bug#17144] Tempfile.open { ... } does not unlink the file

Date: 2020-09-03 15:14:15 UTC
List: ruby-core #99881
Issue #17144 has been updated by Dan0042 (Daniel DeLorme).


-1 for breaking compatibility with no deprecation, just for the sake of perceived consistency.

But then again it's important to note that `Tempfile.open{ }` returns nil, so the only way to cause an incompatibility is if the blocks "leaks" the Tempfile reference, like `Tempfile.open{ @f = _1 }` or `Tempfile.open{ return _1 }`

----------------------------------------
Bug #17144: Tempfile.open { ... } does not unlink the file
https://bugs.ruby-lang.org/issues/17144#change-87410

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
```
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 basically all usages of `SomeClass.open { ... }`.
There are more than 10 SomeClass.open in core+stdlib, and AFAIK all these methods release all resources at the end of the block, except Tempfile.open.

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

The (English) docs don't mention the file is kept on disk after the block:
https://docs.ruby-lang.org/en/2.7.0/Tempfile.html#method-c-open

I made a PR to do unlink in https://github.com/ruby/tempfile/pull/3 and some commits in ruby/ruby (notably https://github.com/ruby/ruby/commit/fa21985a7a2f8f52a8bd82bd12a724e9dca74934).

However it can cause some incompatibility, if an existing usage relied on the block only closing the file descriptor but not unlink the path.
See https://github.com/ruby/tempfile/issues/2#issuecomment-686323507

When integrating this change in ruby/ruby, I found that many usages expected that the file be unlinked automatically, but had to add an extra `ensure tempfile.close!` on top of the block:
https://github.com/ruby/ruby/commit/e8c3872555fc85640505974e6b1c39d315572689 (later partially reverted because such libraries probably want to keep compat with older Rubies)

In all of ruby/ruby I found only [2 usages](https://github.com/ruby/ruby/commit/3beecafc2cae86290a191c1e841be13f5b08795d) depending on the file to still be on disk after the block.

@shugo brought to my attention that `Tempfile.create { ... }` unlinks the file (Tempfile.create seems to exist since 2.1 yet very few seem to know about it).
I think the semantics of `Tempfile.create { ... }` is what the vast majority of usages want for `Tempfile.open { ... }`.
`open` is the name everyone expects, so I think it's best if `Tempfile.open { ... }` also links.
`create` doesn't sound like it will cleanup to me.

As an optimization we can use `Tempfile.create(&block)` to implement `Tempfile.open { ... }` to avoid creating needlessly a finalizer.

Found by https://github.com/ruby/spec/commit/d347e89ef6c817e469a1c25985dbd729c52b80fd and the leak detector.

From https://github.com/ruby/tempfile/issues/2

So, OK to keep this change and make `Tempfile.open { ... }` do what most usages expect,
even if we have to update a few usages that relied on the file to still exist after the block?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread