Created
February 14, 2013 08:17
-
-
Save knu/4951299 to your computer and use it in GitHub Desktop.
A patch for FreeBSD cp(1) to fix PR bin/176136: http://www.freebsd.org/cgi/query-pr.cgi?pr=176136
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: cp.c | |
=================================================================== | |
--- cp.c (revision 246770) | |
+++ cp.c (working copy) | |
@@ -262,7 +262,7 @@ copy(char *argv[], enum op type, int fts | |
struct stat to_stat; | |
FTS *ftsp; | |
FTSENT *curr; | |
- int base = 0, dne, badcp, rval; | |
+ int base = 0, dne, badcp, rval, sval; | |
size_t nlen; | |
char *p, *target_mid; | |
mode_t mask, mode; | |
@@ -383,8 +383,18 @@ copy(char *argv[], enum op type, int fts | |
continue; | |
} | |
+ /* | |
+ * lstat(2) should be used if neither -H or -L is | |
+ * given, or we will fail to overwrite an existing | |
+ * symlink pointing to a directory. | |
+ */ | |
+ if (fts_options & (FTS_LOGICAL | FTS_COMFOLLOW)) | |
+ sval = stat(to.p_path, &to_stat); | |
+ else | |
+ sval = lstat(to.p_path, &to_stat); | |
+ | |
/* Not an error but need to remember it happened */ | |
- if (stat(to.p_path, &to_stat) == -1) | |
+ if (sval == -1) | |
dne = 1; | |
else { | |
if (to_stat.st_dev == curr->fts_statp->st_dev && |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment