Even if you delete the temporary folder, the file will not be deleted completely and it will put pressure on the hard disk, so let's close it properly
In Ruby, you can easily create a temporary folder and the folder disappears when the block ends, so it is easy to handle as a working folder.
Dir.mktmpdir('test') do |dir|
#Create and open files
end
If you forget to close it just by opening it because it disappears in the temporary folder anyway ....
Dir.mktmpdir('test') do |dir|
#File generation process
f = File.open(path)
#work
end
The tmp folder is empty, but the hard disk is getting more and more compressed ... Yes, on Linux it's not completely gone as long as the process remains. Unless you restart the Rails server or Delayed Job Woker and drop the process that handles the problem, it will continue to remain.
$ lsof | grep delete
bundle 23931 (Abbreviation) /tmp/test20200317-23931-cayd6g/test.pdf (deleted)
*) In the above example, process 23931 is grasping, so it is temporarily deleted.
Since the file is released, it will be permanently deleted when the temporary folder is deleted. If you do this you don't have to drop the whole process
Dir.mktmpdir('test') do |dir|
#File generation process
File.open(path) do
#work
end
end
Recommended Posts