Handle missing `File::Remove'.
authorlace <>
Wed, 11 Apr 2007 14:44:42 +0000 (14:44 +0000)
committerlace <>
Wed, 11 Apr 2007 14:44:42 +0000 (14:44 +0000)
&localactionrm: Handle write-protected files to be removed.

bin/cvsutil

index 1048e97..26b49a9 100755 (executable)
@@ -16,8 +16,22 @@ use warnings;
 use Getopt::Long;
 use Cwd qw(chdir fastgetcwd);
 use Errno qw(ENOENT);
-use File::Remove qw(remove);
 use Carp qw(confess cluck croak carp);
+BEGIN {
+       if (!eval q{use File::Remove qw(remove);}) {{
+               sub main::remove
+               {
+                       my $r="";
+                       if ("SCALAR" eq ref $_[0]) {
+                               $r="-r" if ${$_[0]};
+                               shift;
+                               }
+                       my $cmd="rm -f $r ".join(" ",map({s/'/'\\''/g;"'$_'";} @_));
+                       my $err=system($cmd) and confess("$cmd: $cmd");
+                       return @_;
+               }
+               }}
+}
 
 use constant ENTRIES  =>"CVS/Entries";
 use constant CVSIGNORE=>".cvsignore";
@@ -207,10 +221,13 @@ sub localactionrm
 {
 my($filename)=@_;
 
+       chmod 0600,$filename or do {
+               mayfatal "File \"$_\" cannot be chmod(2)ed" if !$!{ENOENT};
+               };
        # '\1' for '-r':
-       if (!remove \1,$filename) {
+       remove \1,$filename or do {
                mayfatal "File \"$_\" cannot be removed" if !$!{ENOENT};
-               }
+               };
 }
 
 sub localactionrootset