Dir.mktmpdir doesn't remove it at exit?

Hello.
I would have expected that creating a “temporary dir” would be deleted
at application exit. Should it?

It doesn’t appear to today, which surprised me…

Dir.mktmpdir
=> “C:/Users/packrd/AppData/Local/Temp/d20120917-5400-1rz8p6k”

File.directory? “C:/Users/packrd/AppData/Local/Temp/d20120917-5400-1rz8p6k”
=> true

exit

C:>irb

File.directory? “C:/Users/packrd/AppData/Local/Temp/d20120917-5400-1rz8p6k”
=> true

Thanks.
-r

Per the docs:

“If a block is given, it is yielded with the path of the directory.
The directory and its contents are removed using
FileUtils.remove_entry_secure before ::mktmpdir returns. The value of
the block is returned.”

“If a block is not given, The path of the directory is returned. In
this case, ::mktmpdir doesn’t remove the directory.”

– Matma R.

so in your opinion should it remove the “temp dir” at exit, or not?

On Mon, Sep 17, 2012 at 10:57 AM, Roger P. [email protected]
wrote:

so in your opinion should it remove the “temp dir” at exit, or not?

You need both options. The block form gives you automatic cleanup (as
the
block form of many things do). The non-block form is nice if you want to
manage your own temporary directories

Hmmm. IMO, the behaviour should be consistent, and not depend on whether
a block form was used.

But I never had to create temporary directories that way.

If I need to create a directory and remove it lateron, I do so on my
own.

Via FileUtils usually.

Many methods in Ruby which deal with external resources
(File.open/Socket.open anyone?) have both a block form (that cleans
itself
up automatically) and a non-block form that requires manual cleanup
(e.g.
close your file descriptors, although the GC will eventually do it for
you if you can’t be bothered to do that)

This is no different.

It also closes file descriptors “at_exit” for you, which is what I
expected here.

Really what I’d expect here is for it to remove the directory “if empty”
at exit, but maybe that is too hard in windows, which disallows removing
non-empty directories? A pity if that’s why the inconsistency was
introduced.

On Mon, Sep 17, 2012 at 11:30 AM, Marc H. [email protected]
wrote:

Hmmm. IMO, the behaviour should be consistent, and not depend on whether
a block form was used.

“A foolish consistency is the hobgoblin of little minds”

Many methods in Ruby which deal with external resources
(File.open/Socket.open anyone?) have both a block form (that cleans
itself
up automatically) and a non-block form that requires manual cleanup
(e.g.
close your file descriptors, although the GC will eventually do it for
you if you can’t be bothered to do that)

This is no different.

Roger P. писал 18.09.2012 01:22:

It also closes file descriptors “at_exit” for you, which is what I
expected here.

Really what I’d expect here is for it to remove the directory “if
empty”
at exit, but maybe that is too hard in windows, which disallows
removing
non-empty directories? A pity if that’s why the inconsistency was
introduced.

Unixen don’t allow removal of non-empty directories as well.