diff options
author | Nicholas Clark <nick@ccl4.org> | 2013-07-13 18:33:53 +0200 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2013-07-23 13:39:51 +0200 |
commit | 4c4326140484b090df4dd2ed7165e669991744cc (patch) | |
tree | 0ccede8f1b692adedb20fe6377858534debd7669 /install_lib.pl | |
parent | 1f55bb435760d6f0cd87d3d9fd23b3c51253b43e (diff) | |
download | perl-4c4326140484b090df4dd2ed7165e669991744cc.tar.gz |
Move {safe_,}rename() from install{man,perl} into install_lib.pl
installman's rename() was identical to installperl's safe_rename() in all
but name (and whitespace), so de-duplicate by moving the code to
install_lib.pl
Diffstat (limited to 'install_lib.pl')
-rw-r--r-- | install_lib.pl | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/install_lib.pl b/install_lib.pl index 308af70ed6..1fe25794a2 100644 --- a/install_lib.pl +++ b/install_lib.pl @@ -127,4 +127,18 @@ sub samepath { } } +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); +} + 1; |