commit 357efc9b89710a1ed6f4544aae54ff9761c57971 from: jrmu date: Tue Mar 07 15:15:00 2023 UTC Safer writes commit - 4a735b997384098182ff11ac0c93cb0b0a794984 commit + 357efc9b89710a1ed6f4544aae54ff9761c57971 blob - 258bb9db5be5d0996d84148bf4f038769cea4a55 blob + af1bae59f74297fdd1b70187b06f561e5c000f61 --- botnow +++ botnow @@ -7,7 +7,15 @@ use IO::Socket; use IO::Select; use OpenBSD::Pledge; use OpenBSD::Unveil; +use File::Copy qw(copy); +# Returns date in YYYYMMDD format +sub date { + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); + my $localtime = sprintf("%04d%02d%02d", $year+1900, $mon+1, $mday); + return $localtime; +} + # Read from filename and return array of lines without trailing newlines sub readarray { my ($filename) = @_; @@ -29,6 +37,8 @@ sub readstr { # Write str to filename sub writefile { my ($filename, $str) = @_; + my $date = date(); + copy($filename, $filename.date()) or die "Could not make backup of $filename"; open(my $fh, '>', "$filename") or die "Could not write to $filename"; print $fh $str; close $fh; @@ -48,13 +58,6 @@ sub gettime { my @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); my $localtime = sprintf("%s %s %d %02d:%02d:%02d", $days[$wday], $months[$mon], $mday, $hour, $min, $sec); - return $localtime; -} - -# Returns date in YYYYMMDD format -sub date { - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); - my $localtime = sprintf("%04d%02d%02d", $year+1900, $mon+1, $mday); return $localtime; }