Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 690484 | Differences between
and this patch

Collapse All | Expand All

(-)a/lib/portage/dbapi/vartree.py (-4 / +52 lines)
Lines 30-35 portage.proxy.lazyimport.lazyimport(globals(), Link Here
30
	'portage.util:apply_secpass_permissions,ConfigProtect,ensure_dirs,' + \
30
	'portage.util:apply_secpass_permissions,ConfigProtect,ensure_dirs,' + \
31
		'writemsg,writemsg_level,write_atomic,atomic_ofstream,writedict,' + \
31
		'writemsg,writemsg_level,write_atomic,atomic_ofstream,writedict,' + \
32
		'grabdict,normalize_path,new_protect_filename',
32
		'grabdict,normalize_path,new_protect_filename',
33
	'portage.util.compare_files:compare_files',
33
	'portage.util.digraph:digraph',
34
	'portage.util.digraph:digraph',
34
	'portage.util.env_update:env_update',
35
	'portage.util.env_update:env_update',
35
	'portage.util.install_mask:install_mask_dir,InstallMask',
36
	'portage.util.install_mask:install_mask_dir,InstallMask',
Lines 3418-3423 class dblink(object): Link Here
3418
3419
3419
			os = _os_merge
3420
			os = _os_merge
3420
3421
3422
			real_relative_paths = {}
3423
3421
			collision_ignore = []
3424
			collision_ignore = []
3422
			for x in portage.util.shlex_split(
3425
			for x in portage.util.shlex_split(
3423
				self.settings.get("COLLISION_IGNORE", "")):
3426
				self.settings.get("COLLISION_IGNORE", "")):
Lines 3469-3476 class dblink(object): Link Here
3469
					previous = current
3472
					previous = current
3470
					progress_shown = True
3473
					progress_shown = True
3471
3474
3472
				dest_path = normalize_path(
3475
				dest_path = normalize_path(os.path.join(destroot, f.lstrip(os.path.sep)))
3473
					os.path.join(destroot, f.lstrip(os.path.sep)))
3476
3477
				# Relative path with symbolic links resolved only in parent directories
3478
				real_relative_path = os.path.join(os.path.realpath(os.path.dirname(dest_path)), os.path.basename(dest_path))[len(destroot):]
3479
3480
				real_relative_paths.setdefault(real_relative_path, []).append(f.lstrip(os.path.sep))
3474
3481
3475
				parent = os.path.dirname(dest_path)
3482
				parent = os.path.dirname(dest_path)
3476
				if parent not in dirs:
3483
				if parent not in dirs:
Lines 3556-3564 class dblink(object): Link Here
3556
							break
3563
							break
3557
					if stopmerge:
3564
					if stopmerge:
3558
						collisions.append(f)
3565
						collisions.append(f)
3566
3567
			internal_collisions = {}
3568
			for real_relative_path, files in real_relative_paths.items():
3569
				# Detect internal collisions between non-identical files.
3570
				if len(files) >= 2:
3571
					files.sort()
3572
					for i in range(len(files) - 1):
3573
						file1 = normalize_path(os.path.join(srcroot, files[i]))
3574
						file2 = normalize_path(os.path.join(srcroot, files[i+1]))
3575
						differences = compare_files(file1, file2)
3576
						# Ignore differences in times.
3577
						for time_type in ("atime", "mtime", "ctime"):
3578
							if time_type in differences:
3579
								differences.remove(time_type)
3580
						if differences:
3581
							internal_collisions.setdefault(real_relative_path, {})[(files[i], files[i+1])] = differences
3582
3559
			if progress_shown:
3583
			if progress_shown:
3560
				showMessage(_("100% done\n"))
3584
				showMessage(_("100% done\n"))
3561
			return collisions, dirs_ro, symlink_collisions, plib_collisions
3585
3586
			return collisions, internal_collisions, dirs_ro, symlink_collisions, plib_collisions
3562
3587
3563
	def _lstat_inode_map(self, path_iter):
3588
	def _lstat_inode_map(self, path_iter):
3564
		"""
3589
		"""
Lines 4081-4087 class dblink(object): Link Here
4081
			if blocker.exists():
4106
			if blocker.exists():
4082
				blockers.append(blocker)
4107
				blockers.append(blocker)
4083
4108
4084
		collisions, dirs_ro, symlink_collisions, plib_collisions = \
4109
		collisions, internal_collisions, dirs_ro, symlink_collisions, plib_collisions = \
4085
			self._collision_protect(srcroot, destroot,
4110
			self._collision_protect(srcroot, destroot,
4086
			others_in_slot + blockers, filelist, linklist)
4111
			others_in_slot + blockers, filelist, linklist)
4087
4112
Lines 4109-4114 class dblink(object): Link Here
4109
			eerror(msg)
4134
			eerror(msg)
4110
			return 1
4135
			return 1
4111
4136
4137
		if internal_collisions:
4138
			msg = _("Package '%s' has internal collisions (between files "
4139
				"in separate directories in the installation image (${D}) "
4140
				"corresponding to merged directories in the target "
4141
				"filesystem (${ROOT})):") % self.settings.mycpv
4142
			msg = textwrap.wrap(msg, 70)
4143
			msg.append("")
4144
			for k, v in sorted(internal_collisions.items()):
4145
				msg.append("\t%s" % os.path.join(destroot, k.lstrip(os.path.sep)))
4146
				for (file1, file2), differences in sorted(v.items()):
4147
					msg.append("\t\t%s" % os.path.join(destroot, file1.lstrip(os.path.sep)))
4148
					msg.append("\t\t%s" % os.path.join(destroot, file2.lstrip(os.path.sep)))
4149
					msg.append("\t\t\tDifferences: %s" % ", ".join(differences))
4150
					msg.append("")
4151
			self._elog("eerror", "preinst", msg)
4152
4153
			msg = _("Package '%s' NOT merged due to internal collisions.") % \
4154
				self.settings.mycpv
4155
			msg += _(" If necessary, refer to your elog messages for the whole "
4156
				"content of the above message.")
4157
			eerror(textwrap.wrap(msg, 70))
4158
			return 1
4159
4112
		if symlink_collisions:
4160
		if symlink_collisions:
4113
			# Symlink collisions need to be distinguished from other types
4161
			# Symlink collisions need to be distinguished from other types
4114
			# of collisions, in order to avoid confusion (see bug #409359).
4162
			# of collisions, in order to avoid confusion (see bug #409359).
(-)a/lib/portage/util/compare_files.py (-1 / +91 lines)
Line 0 Link Here
0
- 
1
# Copyright 2019 Gentoo Authors
2
# Distributed under the terms of the GNU General Public License v2
3
4
__all__ = ["compare_files"]
5
6
import io
7
import os
8
import stat
9
import sys
10
11
from portage import _encodings
12
from portage import _unicode_encode
13
import portage.util._xattr
14
15
def compare_files(file1, file2):
16
	"""
17
	Compare metadata and contents of two files.
18
19
	@param file1: File 1
20
	@type file1: str
21
	@param file2: File 2
22
	@type file2: str
23
	@rtype: list
24
	@return: List of strings specifying types of differences
25
	"""
26
27
	file1_stat = os.lstat(file1)
28
	file2_stat = os.lstat(file2)
29
30
	differences = []
31
32
	if (file1_stat.st_dev, file1_stat.st_ino) == (file2_stat.st_dev, file2_stat.st_ino):
33
		return differences
34
35
	if stat.S_IFMT(file1_stat.st_mode) != stat.S_IFMT(file2_stat.st_mode):
36
		differences.append("type")
37
	if stat.S_IMODE(file1_stat.st_mode) != stat.S_IMODE(file2_stat.st_mode):
38
		differences.append("mode")
39
	if file1_stat.st_uid != file2_stat.st_uid:
40
		differences.append("owner")
41
	if file1_stat.st_gid != file2_stat.st_gid:
42
		differences.append("group")
43
	if file1_stat.st_rdev != file2_stat.st_rdev:
44
		differences.append("device_number")
45
46
	if sorted(portage.util._xattr.xattr.get_all(file1, nofollow=True)) != sorted(portage.util._xattr.xattr.get_all(file2, nofollow=True)):
47
		differences.append("xattr")
48
49
	if sys.hexversion >= 0x3030000:
50
		if file1_stat.st_atime_ns != file2_stat.st_atime_ns:
51
			differences.append("atime")
52
		if file1_stat.st_mtime_ns != file2_stat.st_mtime_ns:
53
			differences.append("mtime")
54
		if file1_stat.st_ctime_ns != file2_stat.st_ctime_ns:
55
			differences.append("ctime")
56
	else:
57
		if file1_stat.st_atime != file2_stat.st_atime:
58
			differences.append("atime")
59
		if file1_stat.st_mtime != file2_stat.st_mtime:
60
			differences.append("mtime")
61
		if file1_stat.st_ctime != file2_stat.st_ctime:
62
			differences.append("ctime")
63
64
	if file1_stat.st_size != file2_stat.st_size:
65
		differences.append("size")
66
		differences.append("content")
67
	else:
68
		if stat.S_ISLNK(file1_stat.st_mode):
69
			file1_stream = io.BytesIO(os.readlink(_unicode_encode(file1,
70
							encoding=_encodings["fs"],
71
							errors="strict")))
72
		else:
73
			file1_stream = open(file1, "rb")
74
		if stat.S_ISLNK(file2_stat.st_mode):
75
			file2_stream = io.BytesIO(os.readlink(_unicode_encode(file2,
76
							encoding=_encodings["fs"],
77
							errors="strict")))
78
		else:
79
			file2_stream = open(file2, "rb")
80
		while True:
81
			file1_content = file1_stream.read(4096)
82
			file2_content = file2_stream.read(4096)
83
			if file1_content == b"" or file2_content == b"":
84
				break
85
			if file1_content != file2_content:
86
				differences.append("content")
87
				break
88
		file1_stream.close()
89
		file2_stream.close()
90
91
	return differences

Return to bug 690484