Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177869840
D17105.1795475211.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D17105.1795475211.diff
View Options
Index: usr.bin/xinstall/tests/install_test.sh
===================================================================
--- usr.bin/xinstall/tests/install_test.sh
+++ usr.bin/xinstall/tests/install_test.sh
@@ -377,6 +377,44 @@
atf_check install -d dir1/dir2/dir3
}
+hardlink_snap_helper() {
+ echo test1 > s
+ atf_check install -C "$@" s a
+ ln a b
+ atf_check install -C "$@" s a
+ [ "$(stat -f %i a)" = "$(stat -f %i b)" ] ||
+ atf_fail 'inode changed when files were the same'
+ echo test2 > s
+ atf_check install -C "$@" s a
+ [ "$(stat -f %i a)" = "$(stat -f %i b)" ] &&
+ atf_fail 'inode not changed when files were different'
+ touch -A -60 a
+ ln -f a b
+ atf_check install -C "$@" -m 0 s a
+ [ "$(stat -f %i a)" = "$(stat -f %i b)" ] &&
+ atf_fail 'inode not changed when mode was different'
+ [ "$(stat -f %m a)" = "$(stat -f %m b)" ] ||
+ atf_fail 'the modification time was not preserved'
+ true
+}
+
+atf_test_case hardlink_snap
+hardlink_snap_head() {
+ atf_set "descr" "Check that -C snaps hardlinks when necessary"
+}
+hardlink_snap_body() {
+ hardlink_snap_helper
+}
+
+atf_test_case hardlink_snap_strip
+hardlink_snap_strip_head() {
+ atf_set "descr" "Check that -C -s snaps hardlinks when necessary"
+}
+hardlink_snap_strip_body() {
+ export STRIPBIN=true
+ hardlink_snap_helper -s
+}
+
atf_init_test_cases() {
atf_add_test_case copy_to_nonexistent
atf_add_test_case copy_to_nonexistent_safe
@@ -416,4 +454,6 @@
atf_add_test_case symbolic_link_relative_absolute_source_and_dest1_double_slash
atf_add_test_case symbolic_link_relative_absolute_source_and_dest2
atf_add_test_case mkdir_simple
+ atf_add_test_case hardlink_snap
+ atf_add_test_case hardlink_snap_strip
}
Index: usr.bin/xinstall/xinstall.c
===================================================================
--- usr.bin/xinstall/xinstall.c
+++ usr.bin/xinstall/xinstall.c
@@ -739,7 +739,7 @@
{
struct stat from_sb, temp_sb, to_sb;
struct timespec tsb[2];
- int devnull, files_match, from_fd, serrno, target;
+ int devnull, files_match, from_fd, serrno, target, chgattr, tsbset;
int tempcopy, temp_fd, to_fd;
char backup[MAXPATHLEN], *p, pathbuf[MAXPATHLEN], tempfile[MAXPATHLEN];
char *digestresult;
@@ -747,6 +747,7 @@
files_match = 0;
from_fd = -1;
to_fd = -1;
+ tsbset = 0;
/* If try to install NULL file to a directory, fails. */
if (flags & DIRECTORY || strcmp(from_name, _PATH_DEVNULL)) {
@@ -792,6 +793,17 @@
return;
}
+ /* Determine if we're going to try to change the file's
+ * attributes later on. */
+ chgattr = target &&
+ ((!dounpriv && gid != (gid_t)-1 && gid != to_sb.st_gid) ||
+ (!dounpriv && uid != (uid_t)-1 && uid != to_sb.st_uid) ||
+ (mode != (to_sb.st_mode &
+ (dounpriv ? (S_IRWXU|S_IRWXG|S_IRWXO) : ALLPERMS))) ||
+ (flags & SETFLAGS ?
+ to_sb.st_flags != fset : devnull ? 0 :
+ to_sb.st_flags != (from_sb.st_flags & ~UF_NODUMP)));
+
/* Only copy safe if the target exists. */
tempcopy = safecopy && target;
@@ -802,12 +814,26 @@
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)
- files_match = to_sb.st_size == 0;
- else
- files_match = !(compare(from_fd, from_name,
+ if (devnull ? to_sb.st_size == 0 :
+ compare(from_fd, from_name,
(size_t)from_sb.st_size, to_fd,
- to_name, (size_t)to_sb.st_size, &digestresult));
+ to_name, (size_t)to_sb.st_size,
+ &digestresult) == 0) {
+ /*
+ * If target has more than one link and we
+ * want to change its attributes, we need to
+ * replace it in order to snap the extra
+ * links. Need to preserve target file times,
+ * though.
+ */
+ if (to_sb.st_nlink != 1 && chgattr) {
+ tsbset = 1;
+ tsb[0] = to_sb.st_atim;
+ tsb[1] = to_sb.st_mtim;
+ } else {
+ files_match = 1;
+ }
+ }
/* Close "to" file unless we match. */
if (!files_match)
@@ -869,14 +895,16 @@
to_name, (size_t)to_sb.st_size, &digestresult)
== 0) {
/*
- * If target has more than one link we need to
- * replace it in order to snap the extra links.
- * Need to preserve target file times, though.
+ * If target has more than one link and we
+ * want to change its attributes, we need to
+ * replace it in order to snap the extra
+ * links. Need to preserve target file times,
+ * though.
*/
- if (to_sb.st_nlink != 1) {
+ if (to_sb.st_nlink != 1 && chgattr) {
+ tsbset = 1;
tsb[0] = to_sb.st_atim;
tsb[1] = to_sb.st_mtim;
- (void)utimensat(AT_FDCWD, tempfile, tsb, 0);
} else {
files_match = 1;
(void)unlink(tempfile);
@@ -940,9 +968,11 @@
/*
* Preserve the timestamp of the source file if necessary.
*/
- if (dopreserve && !files_match && !devnull) {
- tsb[0] = from_sb.st_atim;
- tsb[1] = from_sb.st_mtim;
+ if ((dopreserve && !files_match && !devnull) || tsbset) {
+ if (!tsbset) {
+ tsb[0] = from_sb.st_atim;
+ tsb[1] = from_sb.st_mtim;
+ }
(void)utimensat(AT_FDCWD, to_name, tsb, 0);
}
@@ -992,8 +1022,9 @@
* trying to turn off UF_NODUMP. If we're trying to set real flags,
* then warn if the fs doesn't support it, otherwise fail.
*/
- if (!dounpriv & !devnull && (flags & SETFLAGS ||
- (from_sb.st_flags & ~UF_NODUMP) != to_sb.st_flags) &&
+ if (!dounpriv && (flags & SETFLAGS ||
+ (!devnull && (from_sb.st_flags & ~UF_NODUMP) !=
+ to_sb.st_flags)) &&
fchflags(to_fd,
flags & SETFLAGS ? fset : from_sb.st_flags & ~UF_NODUMP)) {
if (flags & SETFLAGS) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 23, 11:06 PM (20 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41941859
Default Alt Text
D17105.1795475211.diff (5 KB)
Attached To
Mode
D17105: Enhance install(1) -C's handling of hardlinked files
Attached
Detach File
Event Timeline