From: Sam Mikes Date: Sat, 26 Mar 2022 16:14:10 +0000 (-0600) Subject: Extract unlink_and_reopen from copy_file (#294) X-Git-Tag: v3.2.4pre4~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef76d6cfa5ff6b33974083756d3ff0921e5304be;p=thirdparty%2Frsync.git Extract unlink_and_reopen from copy_file (#294) * add tests to exercise copy_file * Extract new function unlink_and_reopen from copy_file The argument `ofd` to copy_file is always set to -1 unless `open_tmpfile()` is called at generator.c:909 This change * removes assignment to a function argument * renames argument `ofd` to `tmpfilefd` in line with existing uses * extracts a new function `unlink_and_reopen` which is static to util1.c * rewrites header comments for copy_file --- diff --git a/testsuite/copy-file-inplace.test b/testsuite/copy-file-inplace.test new file mode 100755 index 000000000..a3d124f7f --- /dev/null +++ b/testsuite/copy-file-inplace.test @@ -0,0 +1,45 @@ +#!/bin/sh + +# Copyright (C) 2008-2022 Wayne Davison + +# This program is distributable under the terms of the GNU GPL (see +# COPYING). + +# Test that copy_file works correctly with tmpfiles + +. "$suitedir/rsync.fns" + +SSH="$scratchdir/src/support/lsh.sh" + +hands_setup + +# Create a side dir where there is a candidate destfile of the same name as a sourcefile +cat >"$scratchdir/from/likely" <"$scratchdir/demo/likely" <"$scratchdir/from/likely" <"$scratchdir/demo/likely" <= 0) { + ofd = tmpfilefd; + } else { + ofd = unlink_and_reopen(dest, mode); + if (ofd < 0) { int save_errno = errno; - rsyserr(FERROR_XFER, save_errno, "open %s", full_fname(dest)); close(ifd); errno = save_errno; return -1;