summaryrefslogtreecommitdiff
path: root/Debian
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2018-10-11 00:18:45 +0100
committerIan Jackson <ijackson@chiark.greenend.org.uk>2018-10-11 00:58:26 +0100
commit32c22f0a584874d61ff1697cd63b2f8eba8b75ab (patch)
tree00dee75c32313916e483e1bbcc8f619fe5a5b13d /Debian
parentc6f06a4420584ef27db3510160c16c233f071c06 (diff)
Dgit.pm: Provide rename_link_xf
This will be used for cross-filesystem support. No callers yet. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Diffstat (limited to 'Debian')
-rw-r--r--Debian/Dgit.pm38
1 files changed, 37 insertions, 1 deletions
diff --git a/Debian/Dgit.pm b/Debian/Dgit.pm
index edc57f1..b8a1b8c 100644
--- a/Debian/Dgit.pm
+++ b/Debian/Dgit.pm
@@ -48,7 +48,7 @@ BEGIN {
upstreamversion
stripepoch source_file_leafname is_orig_file_of_p_v
server_branch server_ref
- stat_exists link_ltarget
+ stat_exists link_ltarget rename_link_xf
hashfile
fail failmsg ensuredir must_getcwd executable_on_path
waitstatusmsg failedcmd_waitstatus
@@ -425,6 +425,42 @@ sub link_ltarget ($$) {
$r or fail "(sym)link $old $new: $!\n";
}
+sub rename_link_xf ($$$) {
+ # renames/moves or links/copies $src to $dst,
+ # even if $dst is on a different fs
+ # (May use the filename "$dst.tmp".);
+ # On success, returns true.
+ # On failure, returns false and sets
+ # $@ to a reason message
+ # $! to an errno value, or -1 if not known
+ # having possibly printed something about mv to stderr.
+ my ($keeporig,$src,$dst) = @_;
+ if ($keeporig
+ ? link $src, $dst
+ : rename $src, $dst) {
+ return 1;
+ } elsif ($! != EXDEV) {
+ $@ = "$!";
+ return 0;
+ }
+ $!=0; $?=0;
+ my @cmd = ($keeporig ? qw(cp) : qw(mv));
+ push @cmd, (qw(--), $src, "$dst.tmp");
+ debugcmd '+',@cmd;
+ if (system @cmd) {
+ failedcmd_report_cmd undef, @cmd;
+ $@ = failedcmd_waitstatus();
+ $! = -1;
+ return 0;
+ }
+ if (rename "$dst.tmp", $dst) {
+ return 1;
+ } else {
+ $@ = f_ "finally install file after mv: %S", $!;
+ return 0;
+ }
+}
+
sub hashfile ($) {
my ($fn) = @_;
my $h = Digest::SHA->new(256);