use Time::HiRes qw(sleep);
use Linux::Inotify2;
-use POSIX qw(strftime);
+use POSIX qw(strftime WIFSIGNALED WTERMSIG SIGINT);
use Mojo::File;
use Y::AoC qw(grey red);
$cmd = "./$cmd" if $cmd !~ /\//;
my $last_backup;
+my $file = Mojo::File->new($cmd);
+my $mtime;
while (1) {
my $b = "$backup-".strftime("%H-%M-%S", localtime(time));
- system 'cp', $cmd, $b;
+ $file->copy_to($b);
+ $mtime = $file->stat->mtime;
say grey("\nrunning $cmd @ARGV... ============================");
system $cmd, @ARGV;
- if ($?) {
+ if ($? && WIFSIGNALED($?) && WTERMSIG($?) == SIGINT) {
+ say red(" Got SIGINT");
+ if ($file->stat->mtime > $mtime) {
+ next;
+ }
+ } elsif ($?) {
say grey("FAILED: $?");
} else {
say grey("finished OK");