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.
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.
https://github.com/agardiner/csv-diff/blob/abff443e856e9d88f711a4d6bcc688c8c6ab7139/lib/csv-diff/csv_source.rb#L107
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. TheCSV
class doesn't let go of the handle and you can't get it back.I have opened a PR to fix this.
https://github.com/agardiner/csv-diff/pull/8
To reproduce the issue, simply call
CSVDiff.new
with two files and then try to callFile.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.