-
Notifications
You must be signed in to change notification settings - Fork 31
Do not use File.each_line iterator to ensure Files are closed #116
Conversation
@@ -122,16 +122,17 @@ module Scry::Completion::DependencyGraph | |||
|
|||
def parse_requires(file_path) | |||
file_dir = File.dirname(file_path) | |||
File.each_line(file_path).reduce([] of String) do |acc, line| | |||
paths = [] of String | |||
File.each_line(file_path) do |line| | |||
require_statement = /^\s*require\s*\"(?<file>.*)\"\s*$/.match(line) | |||
unless require_statement.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: can be written as if require_statement
But that's not related to this pr
I don't get it, why this change fixes the file open issue? It basically doesn't change anything, it's just written differently |
@bew |
Nice find! Can you open an issue on Crystal on this, I think this is a bug, or it should be documented |
@bmulvihill Nice, Thank you! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis on macOS is passing now 🎉
Currently when running the specs on my Mac I get a
Too many files open
error. This is because when loading the DependencyGraph we are using theFile.each_line
iterator method, which does not close the file. This changes the DependencyGraph to use theFile.each_line
method which yields to a block, and properly closes the File.