Skip to content

Commit

Permalink
feat: check if the input file already exists when trying to fetch it …
Browse files Browse the repository at this point in the history
…and return an error without trying to downloading it again if that's the case
  • Loading branch information
renaudlenne committed Dec 4, 2024
1 parent 94b0d72 commit 787b58f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/gladvent/internal/cmd/new.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ fn create_input_file(
let input_path = input.get_file_path(ctx.year, ctx.day, kind)
case kind {
input.Puzzle if ctx.fetch_input -> {
use content <- result.try(download_input(ctx))
simplifile.write(input_path, content)
|> result.map_error(FailedToWriteToFile(_))
case
simplifile.is_file(input_path),
simplifile.is_directory(input_path)
{
Ok(False), Ok(False) -> {
use content <- result.try(download_input(ctx))
simplifile.write(input_path, content)
|> result.map_error(FailedToWriteToFile(_))
}
_, _ -> Error(FileAlreadyExists(input_path))
}
}
_ -> {
simplifile.create_file(input_path)
Expand Down

0 comments on commit 787b58f

Please sign in to comment.