chiark / gitweb /
desymlink: Use File::Copy rather than a call to system(). Add more error
authorColin Watson <cjwatson@chiark.greenend.org.uk>
Tue, 31 Dec 2002 02:44:30 +0000 (02:44 +0000)
committerColin Watson <cjwatson@chiark.greenend.org.uk>
Tue, 31 Dec 2002 02:44:30 +0000 (02:44 +0000)
checking.

desymlink

index a1a40ee..f3cf416 100755 (executable)
--- a/desymlink
+++ b/desymlink
@@ -1,16 +1,17 @@
 #! /usr/bin/perl -w
 use strict;
 #! /usr/bin/perl -w
 use strict;
+use File::Copy;
 
 for (@ARGV) {
     my $source = $_;
     next unless -l $source;
 
 for (@ARGV) {
     my $source = $_;
     next unless -l $source;
-    my $target = readlink $source or die "readlink: $!";
+    my $target = readlink $source or die "readlink $source: $!";
     my $trap = sub { unlink $source;
                     symlink $target, $source;
                     print "Caught a SIG$_[0]!\n";
                     exit; };
     local ($SIG{HUP}, $SIG{INT}, $SIG{TERM}, $SIG{QUIT}, $SIG{__DIE__}) =
        ($trap, $trap, $trap, $trap, $trap);
     my $trap = sub { unlink $source;
                     symlink $target, $source;
                     print "Caught a SIG$_[0]!\n";
                     exit; };
     local ($SIG{HUP}, $SIG{INT}, $SIG{TERM}, $SIG{QUIT}, $SIG{__DIE__}) =
        ($trap, $trap, $trap, $trap, $trap);
-    unlink $source;
-    system '/bin/cp', $target, $source;
+    unlink $source or die "unlink $source: $!";
+    copy $target, $source or die "copy $source to $target: $!";
 }
 }