Date: Fri, 20 Nov 2015 08:45:59 +0000 (UTC) From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291091 - head/usr.bin/xinstall Message-ID: <201511200845.tAK8jxbx097270@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bapt Date: Fri Nov 20 08:45:59 2015 New Revision: 291091 URL: https://svnweb.freebsd.org/changeset/base/291091 Log: install: do not follow symlinks In case the target of install is a dead symlink, install(1) used to not consider it as "existing" because of the usage of stat(2) instead of lstat(2). meaning the old file (the symlink) is not removed before the new file is created. The symlink is being followed and the new file becoming the target of the symlink instead of the target of install(1) Reviewed by: jhb, brooks MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D4191 Modified: head/usr.bin/xinstall/xinstall.c Modified: head/usr.bin/xinstall/xinstall.c ============================================================================== --- head/usr.bin/xinstall/xinstall.c Fri Nov 20 05:15:34 2015 (r291090) +++ head/usr.bin/xinstall/xinstall.c Fri Nov 20 08:45:59 2015 (r291091) @@ -754,10 +754,7 @@ install(const char *from_name, const cha devnull = 1; } - if (!dolink) - target = (stat(to_name, &to_sb) == 0); - else - target = (lstat(to_name, &to_sb) == 0); + target = (lstat(to_name, &to_sb) == 0); if (dolink) { if (target && !safecopy) { @@ -772,8 +769,7 @@ install(const char *from_name, const cha return; } - /* Only install to regular files. */ - if (target && !S_ISREG(to_sb.st_mode)) { + if (target && !S_ISREG(to_sb.st_mode) && !S_ISLNK(to_sb.st_mode)) { errno = EFTYPE; warn("%s", to_name); return; @@ -786,7 +782,7 @@ install(const char *from_name, const cha err(EX_OSERR, "%s", from_name); /* If we don't strip, we can compare first. */ - if (docompare && !dostrip && target) { + if (docompare && !dostrip && target && S_ISREG(to_sb.st_mode)) { if ((to_fd = open(to_name, O_RDONLY, 0)) < 0) err(EX_OSERR, "%s", to_name); if (devnull) @@ -838,7 +834,7 @@ install(const char *from_name, const cha /* * Compare the stripped temp file with the target. */ - if (docompare && dostrip && target) { + if (docompare && dostrip && target && S_ISREG(to_sb.st_mode)) { temp_fd = to_fd; /* Re-open to_fd using the real target name. */ @@ -872,9 +868,7 @@ install(const char *from_name, const cha } (void) close(temp_fd); } - } - - if (dostrip && (!docompare || !target)) + } else if (dostrip) digestresult = digest_file(tempfile); /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201511200845.tAK8jxbx097270>