ruby / tempfile

A utility class for managing temporary files.
Other
29 stars 10 forks source link

Fix Tempfile#{dup,clone} #17

Closed jeremyevans closed 10 months ago

jeremyevans commented 1 year ago

Instead of storing the delegate in @tmpfile, use getobj, since delegate library already handles dup/clone for that. Copy the unlinked, mode, and opts instance variables to the returned object when using dup/clone.

Split the close/unlink finalizer into two finalizers. The close finalizer always closes when any Tempfile instance is GCed, since each Tempfile instance uses a separate file descriptor. The unlink finalizer unlinks only when the original and all duped/cloned Tempfiles are GCed, since all share the same path.

For Tempfile#open, undefine the close finalizer after closing the current file, the redefine the close finalizer with the new file.

Fixes [Bug #19441]

jeremyevans commented 1 year ago

@hsbt Can you please review and merge this (or let me know who would be better to review)?

jeremyevans commented 1 year ago

@nobu Looks like I don't have commit access to the tempfile repository. Could you review and merge?

hsbt commented 1 year ago

@jeremyevans Sorry that. I added write access to you for this repository.

jeremyevans commented 1 year ago

@hsbt Thank you!