From 526c35ce2f434fc116773c6db3576349ec184565 Mon Sep 17 00:00:00 2001 From: "Yichun Zhang (agentzh)" Date: Sun, 17 Aug 2014 22:15:48 -0700 Subject: [PATCH] util/install: rm the target file before overwriting to prevent running process from crashing. --- util/install | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/util/install b/util/install index 4e68d79..34ae937 100755 --- a/util/install +++ b/util/install @@ -42,6 +42,21 @@ if (!-d $target_dir) { shell("mkdir -p $target_dir"); } +if (-f $dst) { + shell("rm $dst"); + +} else { + for my $f (@src) { + if (-f $f) { + (my $name = $f) =~ s{.*/}{}g; + my $target = "$target_dir/$name"; + if (-f $target) { + shell("rm $target"); + } + } + } +} + shell("cp @src $dst"); if (-f $dst) { @@ -76,6 +91,7 @@ sub usage { sub shell { my $cmd = shift; + #warn $cmd; system($cmd) == 0 or die "failed to run command $cmd\n"; }