agardiner/csv-diff

CSV.open call in csv_source.rb is leaking file handle

NickDiMucci opened this issue · 0 comments

source = CSV.open(@path, mode_string, csv_options).readlines

CSV.open has a design flaw where the underlying file handle gets lost if you chain a call after it. This is an issue if you need to, for one example, delete the file used as the source after you are done diffing/parsing/etc. The CSV class doesn't let go of the handle and you can't get it back.

I have opened a PR to fix this.

#8

To reproduce the issue, simply call CSVDiff.new with two files and then try to call File.delete on them.

And for context, I have a use case where I download two, third party CSV reports, do a diff on them to obtain an array of the differences (using CSVDiff) and need to delete the downloaded reports once I'm done. This is how I discovered the issue.