Feature #20492
openDebug option for tempfile
Description
Hi,
the ruby lib tempfile is quite useful, but since it always deletes files once the object is garbage collected or the program terminates (or the program explicitely asks to remove the file) it is difficult to debug programs and to check the file contents, after program termination.
Replacing all tempfile uses with regular file operations is awkward.
It therefore would be useful, if file deletion of tempfiles could be completely turned of e.g. through an environment variable or by the program itself, like through a --debug option or when catching errors, like deleting all files during normal program termination, but not if there's a runtime error.
regards
Updated by kjtsanaktsidis (KJ Tsanaktsidis) 6 months ago
Since you say you're OK with solutions requiring modifying the program though, have you tried doing something like this?
Tempfile::Remover.class_eval { def call(...) = nil }
I realise if this is a common use-case it would be nice to provide a toggle or some such in the tempfile module which did this with less patching though. Is this a problem that other people on this list have run into before, I wonder?
Updated by mame (Yusuke Endoh) 6 months ago
I too have wanted to do this multiple times. However, I am also a little concerned about the possibility of security risks (such as, DoS to make the storage full, failure to delete sensitive information, etc.) if it can be specified too easily.
Just an idea, but how about using a debugger to stop just before the deletion?