In a project I am working on, Tempfile objects are used. Fine, but I
would like to add an option “keep temp file”, in order to facilitate
debug in case of error.
It seems that Tempfile object doesn’t provide any way to do that. Would
you think it could a possible enhancement?
I am surprised to not find any other thread about this limitation on
google…
In a project I am working on, Tempfile objects are used. Fine, but I
would like to add an option “keep temp file”, in order to facilitate
debug in case of error.
It seems that Tempfile object doesn’t provide any way to do that. Would
you think it could a possible enhancement?
I think it may be an enhancement for your program, not for Tempfile:
the reson for existence of that class is to make sure the files it
handle will be deleted as soon as they get closed.
If you want to keep your files, designate a directory for them (I
generally create a directory under /usr/share) and give to them names
that include the time and date (to make sure there are no risk of
duplicate names). Something like:
FILE_PATH=’/usr/share/myproject/’
def file_name
FILE_PATH+‘file.’+Time::now.strftime(’%y%m%d.%H%M%S’)
end
You then may want to write a cleanup script that makes sure files
older than a few weeks/months are deleted.
In a project I am working on, Tempfile objects are used. Fine, but I
would like to add an option “keep temp file”, in order to facilitate
debug in case of error.
It seems that Tempfile object doesn’t provide any way to do that. Would
you think it could a possible enhancement?
You just need to create a class with the same interface as Tempfile
and use that interchangeably with Tempfile - depending on whether you
want to keep or get rid of temp files. Or you add that option to your
version of Tempfile if you need to decide this while you go.