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.
This commit is contained in:
parent
5dce8a63fc
commit
6a834fc3f1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=9220
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user