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

···

--
Posted via http://www.ruby-forum.com/\.

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."

http://ruby-doc.org/stdlib-1.9.3/libdoc/tmpdir/rdoc/Dir.html#method-c-mktmpdir

-- Matma Rex

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

···

--
Posted via http://www.ruby-forum.com/.

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.

···

--
Posted via http://www.ruby-forum.com/.

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

···

On Mon, Sep 17, 2012 at 10:57 AM, Roger Pack <lists@ruby-forum.com> wrote:

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

--
Tony Arcieri

"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.

···

On Mon, Sep 17, 2012 at 11:30 AM, Marc Heiler <lists@ruby-forum.com> wrote:

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

--
Tony Arcieri

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.

···

--
Posted via http://www.ruby-forum.com/\.

Roger Pack писал 18.09.2012 01:22:

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.

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

···

--
   WBR, Peter Zotov.