[ruby-core:25131] [Feature #1999] Improved Tempfile

View: New views
10 Messages — Rating Filter:   Alert me  

[ruby-core:25131] [Feature #1999] Improved Tempfile

by Dennis Ranke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Feature #1999: Improved Tempfile
http://redmine.ruby-lang.org/issues/show/1999

Author: Hongli Lai
Status: Open, Priority: Normal
Category: lib

I've written an improved version of Tempfile. The changes are as follows:
- Much better documentation.
- A large unit test suite to prevent future regressions.
- Fixes a bug in the finalizer: if one calls #unlink on a Tempfile, then recreates the same file outside Ruby, and then runs the garbage collector, then the Tempfile's finalizer will delete the newly created file even when it's not supposed to:

  t = Tempfile.new('foo')
  path = t.path
  t.close
  t.unlink
  system("touch #{path}")
  exit  # Run finalizers
  # => The file as referred to by 'path' doesn't exist anymore.

The source code can be found here:

http://github.com/FooBarWidget/better/blob/232a0a4f68dab7950c06390fddb940e7af1ff607/lib/better/tempfile.rb

It's compatible with both 1.8 and 1.9.

The tests are here:
http://github.com/FooBarWidget/better/blob/232a0a4f68dab7950c06390fddb940e7af1ff607/test/tempfile_test.rb
http://github.com/FooBarWidget/better/blob/232a0a4f68dab7950c06390fddb940e7af1ff607/test/tempfile_unlink_on_exit_example.rb
http://github.com/FooBarWidget/better/blob/232a0a4f68dab7950c06390fddb940e7af1ff607/test/tempfile_explicit_unlink_example.rb
http://github.com/FooBarWidget/better/blob/232a0a4f68dab7950c06390fddb940e7af1ff607/test/tempfile_explicit_close_and_unlink_example.rb


----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:25141] [Feature #1999] Improved Tempfile

by Dennis Ranke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1999 has been updated by Yui NARUSE.


nobu added your tests and I add your documents.

For addiotional changes, please see [ruby-core:25139].
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1999

----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:25175] [Feature #1999] Improved Tempfile

by Dennis Ranke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1999 has been updated by Hongli Lai.


Thanks. But revision 24666 should be reverted. It breaks the test_finalizer_does_not_unlink_if_already_unlinked test.
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1999

----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:25176] [Feature #1999] Improved Tempfile

by Dennis Ranke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1999 has been updated by Hongli Lai.


Sorry, please ignore my last message, I ran the test in a wrong way.

I'm working on some patches in the format as required by ruby-core:25139.
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1999

----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:25177] [Feature #1999] Improved Tempfile

by Dennis Ranke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1999 has been updated by Hongli Lai.

File tempfile-creation-error.diff added

Here is a patch which implements the CreationError exception class, as documented in the Tempfile API documentation. However, I could not write a unit test for it because there seems to be no mocking/stubbing framework that I could use.
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1999

----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:25878] [Feature #1999](Closed) Improved Tempfile

by Dennis Ranke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1999 has been updated by Yui NARUSE.

Status changed from Open to Closed

Close this ticket and newly open #2166 for adding CreationError.
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1999

----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:26538] [Feature #1999] Improved Tempfile

by Dennis Ranke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1999 has been updated by Christian Höltje.


I'm confused.  Was this newer Tempfile added?  If so, which version of ruby 1.9?  Why was it closed just for adding CreationError?
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1999

----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:26539] [Feature #1999] Improved Tempfile

by Dennis Ranke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Issue #1999 has been updated by Yui NARUSE.

Target version set to 1.9.1 Release Candidate

A patch must be well explained and include only one feature.
This principle should be universal, shouldn't it?

Hongli's proposal is not well explained.
We can't know why their changes are implemented as they are.

His files are not atomic patches.
They are only files.
Not for a patch for ruby-trunk and their changesets are not atomic.
We don't like mixed patch.


I didn't want to simply reject his proposal,
so I intended to show the way of suggesting a new feature in Ruby on #2166.
He seems not understand because of my poor introduction.
----------------------------------------
http://redmine.ruby-lang.org/issues/show/1999

----------------------------------------
http://redmine.ruby-lang.org


[ruby-core:26548] Re: [Feature #1999] Improved Tempfile

by Daniel Berger-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hongli Lai wrote:

> Feature #1999: Improved Tempfile
> http://redmine.ruby-lang.org/issues/show/1999
>
> Author: Hongli Lai
> Status: Open, Priority: Normal
> Category: lib
>
> I've written an improved version of Tempfile. The changes are as follows:
> - Much better documentation.
> - A large unit test suite to prevent future regressions.
> - Fixes a bug in the finalizer: if one calls #unlink on a Tempfile, then recreates the same file outside Ruby, and then runs the garbage collector, then the Tempfile's finalizer will delete the newly created file even when it's not supposed to:
>
>   t = Tempfile.new('foo')
>   path = t.path
>   t.close
>   t.unlink
>   system("touch #{path}")
>   exit  # Run finalizers
>   # => The file as referred to by 'path' doesn't exist anymore.
>
> The source code can be found here:
>
> http://github.com/FooBarWidget/better/blob/232a0a4f68dab7950c06390fddb940e7af1ff607/lib/better/tempfile.rb
>
> It's compatible with both 1.8 and 1.9.
>
> The tests are here:
> http://github.com/FooBarWidget/better/blob/232a0a4f68dab7950c06390fddb940e7af1ff607/test/tempfile_test.rb
> http://github.com/FooBarWidget/better/blob/232a0a4f68dab7950c06390fddb940e7af1ff607/test/tempfile_unlink_on_exit_example.rb
> http://github.com/FooBarWidget/better/blob/232a0a4f68dab7950c06390fddb940e7af1ff607/test/tempfile_explicit_unlink_example.rb
> http://github.com/FooBarWidget/better/blob/232a0a4f68dab7950c06390fddb940e7af1ff607/test/tempfile_explicit_close_and_unlink_example.rb

I ditched Tempfile altogether and wrote my own version:

http://github.com/djberg96/file-temp

Regards,

Dan


[ruby-core:26551] Re: [Feature #1999] Improved Tempfile

by Vladimir Sizikov-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Nov 5, 2009 at 5:31 AM, Daniel Berger <djberg96@...> wrote:
> I ditched Tempfile altogether and wrote my own version:

In JRuby, we also provide our own, custom Java-based version of
Tempfile, so the actualy implementation in MRI is not that important
to us. *BUT*, what I really liked in Hongli Lai version is a better,
more extensive and precise documentation.

Thanks,
  --Vladimir