summaryrefslogtreecommitdiffstats
path: root/bin/cp
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1995-06-14 05:41:27 +0000
committerbde <bde@FreeBSD.org>1995-06-14 05:41:27 +0000
commit0368f74e331476bb51c2d8a8057a96787a3c6a05 (patch)
treea9d807b9a93c6861a840e2bbb0088433a7066bea /bin/cp
parentc4baec265f7ecc21e0f1b2825811fc940be76005 (diff)
downloadFreeBSD-src-0368f74e331476bb51c2d8a8057a96787a3c6a05.zip
FreeBSD-src-0368f74e331476bb51c2d8a8057a96787a3c6a05.tar.gz
Don't unlink the target file if the copy failed. This behaviour isn't
documented and is incompatible with gnu cp. It has very few good effects (it recovers some disk space) and many bad ones: - special files are unlinked after certain errors. - the data may not be recoverable if the source is a special file or fifo. - unlinking destroys the target attributes as well as the target data. - unlinking doesn't actually remove the target data if the target is multiply linked.
Diffstat (limited to 'bin/cp')
-rw-r--r--bin/cp/utils.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index c378103..600f999 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: utils.c,v 1.2 1994/09/24 02:53:42 davidg Exp $
+ * $Id: utils.c,v 1.3 1995/05/30 00:06:22 rgrimes Exp $
*/
#ifndef lint
@@ -143,13 +143,12 @@ copy_file(entp, dne)
}
}
- /* If the copy went bad, lose the file. */
- if (rval == 1) {
- (void)unlink(to.p_path);
- (void)close(from_fd);
- (void)close(to_fd);
- return (1);
- }
+ /*
+ * Don't remove the target even after an error. The target might
+ * not be a regular file, or its attributes might be important,
+ * or its contents might be irreplacable. It would only be safe
+ * to remove it if we created it and its length is 0.
+ */
if (pflag && setfile(fs, to_fd))
rval = 1;
OpenPOWER on IntegriCloud