jnicklas/carrierwave — comment on commit ba8b9d4de5519a367d7731662d8efa8472c2f999
File:  line 0
By yfeldblum:

@geemus If Fog were to start closing my open files when I didn't tell it to, that would definitely break stuff. The approach Fog - and any general API - should take is: if you give Fog an open file (a handle, a File object, etc), Fog leaves it open; if somehow Fog started taking pathnames, then Fog is responsible for both opening and closing the file when you give it a pathname.

If you wanted to add some more smarts to Fog, the possibly remains for Fog to understand an additional parameter `:close => true` on methods that possibly take File objects, with the contract being that Fog takes complete ownership of that File object from now on, from the very first line of the method that took the File object, and is responsible for closing it the minute Fog is done with it.

Getting back to CarrierWave, though, CarrierWave should close its own open files immediately when it's done with them. Even if the GC would take care of it eventually, it's still best practice to exert rigorous control over the opening and closing of external resources such as file handles.

So in an ensure block at the end of `#store`, be sure to `fog_file.close if fog_file`.