Skip to content

Commit

Permalink
Handle file pointers at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
pedromxavier committed Dec 8, 2023
1 parent c45caf6 commit a5717eb
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions src/management/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ function _bibtex_entry(data::Dict{String,Any}; indent=2)
)

return """
@$doctype{$citekey,
$entries
}"""
@$doctype{$citekey,
$entries
}
"""
end

function _problem_name(problem::AbstractString)
Expand All @@ -316,6 +317,8 @@ end
function _problem_name(path::AbstractString, collection::AbstractString)
db = database(path::AbstractString)

@assert isopen(db)

df = DBInterface.execute(
db,
"SELECT problems.name
Expand All @@ -325,13 +328,11 @@ function _problem_name(path::AbstractString, collection::AbstractString)
[collection]
) |> DataFrame

try
return only(df[!, :name])
catch e
@show problem
@show df
rethrow(e)
end
close(db)

@assert !isopen(db)

return only(df[!, :name])
end

function _collection_size(collection::AbstractString)
Expand All @@ -341,12 +342,18 @@ end
function _collection_size(path::AbstractString, collection::AbstractString)
db = database(path)

@assert isopen(db)

df = DBInterface.execute(
db,
"SELECT COUNT(*) FROM instances WHERE collection = ?;",
[collection]
) |> DataFrame

close(db)

@assert !isopen(db)

return only(df[!, begin])
end

Expand All @@ -357,12 +364,18 @@ end
function _collection_size_range(path::AbstractString, collection::AbstractString)
db = database(path)

@assert isopen(db)

df = DBInterface.execute(
db,
"SELECT MIN(size), MAX(size) FROM instances WHERE collection = ?;",
[collection]
) |> DataFrame

close(db)

@assert !isopen(db)

return (only(df[!, 1]), only(df[!, 2]))
end

Expand All @@ -375,6 +388,9 @@ function curate(root_path::AbstractString, dist_path::AbstractString=abspath(roo
end

function curate!(index::InstanceIndex; on_read_error::Function=msg -> @warn(msg))
@assert isopen(index.db)
@assert isopen(index.fp)

# curate collections
for collection in _list_collections(index)
# extract collection metadata
Expand Down Expand Up @@ -467,5 +483,12 @@ function curate!(index::InstanceIndex; on_read_error::Function=msg -> @warn(msg)
)
end

# Close files
close(index.db)
close(index.fp)

@assert !isopen(index.db)
@assert !isopen(index.fp)

return nothing
end

0 comments on commit a5717eb

Please sign in to comment.