mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-21 10:19:04 +00:00
cp: Further simplify the core logic.
If the destination file exists but we decide unlink it, set the dne flag. This means we don't need to re-check the conditions that would have caused us to delete the file when we later need to decide whether to create or replace it. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D43064
This commit is contained in:
parent
0f4467ce44
commit
3850927066
|
@ -145,6 +145,7 @@ copy_file(const FTSENT *entp, int dne)
|
|||
if (fflag) {
|
||||
/* remove existing destination file */
|
||||
(void)unlink(to.p_path);
|
||||
dne = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,7 +167,7 @@ copy_file(const FTSENT *entp, int dne)
|
|||
goto done;
|
||||
}
|
||||
|
||||
if (!dne && !fflag) {
|
||||
if (!dne) {
|
||||
/* overwrite existing destination file */
|
||||
to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue