-sub safe_rename {
- my($from,$to) = @_;
- if (-f $to and not unlink($to)) {
- my($i);
- for ($i = 1; $i < 50; $i++) {
- last if rename($to, "$to.$i");
- }
- warn("Cannot rename to `$to.$i': $!"), return 0
- if $i >= 50; # Give up!
- }
- link($from,$to) || return 0;
- unlink($from);
-}
-
-sub link {
- my($from,$to) = @_;
- my($success) = 0;
-
- my $xfrom = $from;
- $xfrom =~ s/^\Q$destdir\E// if $destdir;
- my $xto = $to;
- $xto =~ s/^\Q$destdir\E// if $destdir;
- print $verbose ? " ln $xfrom $xto\n" : " $xto\n" unless $silent;
- eval {
- CORE::link($from, $to)
- ? $success++
- : ($from =~ m#^/afs/# || $to =~ m#^/afs/#)
- ? die "AFS" # okay inside eval {}
- : die "Couldn't link $from to $to: $!\n"
- unless $nonono;
- $packlist->{$xto} = { from => $xfrom, type => 'link' };
- };
- if ($@) {
- warn "Replacing link() with File::Copy::copy(): $@";
- print $verbose ? " cp $from $xto\n" : " $xto\n" unless $silent;
- print " creating new version of $xto\n"
- if $Is_VMS and -e $to and !$silent;
- unless ($nonono or File::Copy::copy($from, $to) and ++$success) {
- # Might have been that F::C::c can't overwrite the target
- warn "Couldn't copy $from to $to: $!\n"
- unless -f $to and (chmod(0666, $to), unlink $to)
- and File::Copy::copy($from, $to) and ++$success;
- }
- $packlist->{$xto} = { type => 'file' };
- }
- $success;
-}
-
-sub chmod {
- my($mode,$name) = @_;
-
- return if ($^O eq 'dos');
- printf " chmod %o %s\n", $mode, $name if $verbose;
- CORE::chmod($mode,$name)
- || warn sprintf("Couldn't chmod %o %s: $!\n", $mode, $name)
- unless $nonono;
-}
-