aocinit

Perl utility to initialize directories and files for the Advent of Code
git clone git://git.samirparikh.com/aocinit
Log | Files | Refs | README | LICENSE

commit d05c6679bcd6066235a88279719ca2dde2a5181a
parent d010e0bbab16540c063001884aae2aec550baf88
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Fri, 23 Dec 2022 20:24:40 +0000

update so that we don't overwrite already existing solution or input files

Diffstat:
Maocinit | 8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/aocinit b/aocinit @@ -90,6 +90,10 @@ sub read_boilerplate { sub create_boilerplate_file { my ( $day_file, $boilerplate ) = @_; say "creating boilerplate file..."; + if ( -e $day_file ) { + # don't overwrite existing file + die "solution file for this day already exists"; + } open my $bp_file, '>', $day_file; say $bp_file $boilerplate; close $bp_file; @@ -114,6 +118,10 @@ sub download_input { my $res = $ua->get( $url )->result; if ($res->is_success) { my $filename = catfile( $day_subdir, 'input' ); + if ( -e $filename ) { + # don't overwrite existing file + die "input file for this day already exists."; + } open my $input_fh, '>', $filename; say $input_fh $res->body; close $input_fh;