Skip to content

Commit

Permalink
Close early open files
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitfred committed Jan 16, 2025
1 parent e901464 commit 52dbc1c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apps/transport/lib/registry/gtfs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Transport.Registry.GTFS do
Logger.error(error)
Result.error(error)

{:ok, content} ->
{:ok, {content, zip_file}} ->
Logger.debug("Valid Zip archive")

try do
Expand All @@ -30,6 +30,8 @@ defmodule Transport.Registry.GTFS do
|> Stream.flat_map(&handle_stop(data_source_id, &1))
|> Enum.to_list()
|> Result.ok()
after
Unzip.LocalFile.close(zip_file)
rescue
e in NimbleCSV.ParseError ->
e
Expand Down Expand Up @@ -71,7 +73,8 @@ defmodule Transport.Registry.GTFS do
case Unzip.new(zip_file) do
{:ok, unzip} ->
if has_stops?(unzip) do
unzip |> Unzip.file_stream!("stops.txt") |> Result.ok()
content = unzip |> Unzip.file_stream!("stops.txt")
Result.ok({content, zip_file})
else
Result.error("Missing stops.txt in #{archive}")
end
Expand Down

0 comments on commit 52dbc1c

Please sign in to comment.