Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 304129
Collapse All | Expand All

(-)../../trunk/pym/_emerge/EbuildFetcher.py (+52 lines)
Lines 26-31 Link Here
26
			raise AssertionError("ebuild not found for '%s'" % self.pkg.cpv)
26
			raise AssertionError("ebuild not found for '%s'" % self.pkg.cpv)
27
		settings = self.config_pool.allocate()
27
		settings = self.config_pool.allocate()
28
		settings.setcpv(self.pkg)
28
		settings.setcpv(self.pkg)
29
		if self.prefetch and \
30
			self._prefetch_size_ok(portdb, settings, ebuild_path):
31
			self.config_pool.deallocate(settings)
32
			self.returncode = os.EX_OK
33
			self.wait()
34
			return
29
35
30
		# In prefetch mode, logging goes to emerge-fetch.log and the builddir
36
		# In prefetch mode, logging goes to emerge-fetch.log and the builddir
31
		# should not be touched since otherwise it could interfere with
37
		# should not be touched since otherwise it could interfere with
Lines 78-83 Link Here
78
			self.config_pool.deallocate(settings)
84
			self.config_pool.deallocate(settings)
79
		SpawnProcess._start(self)
85
		SpawnProcess._start(self)
80
86
87
	def _prefetch_size_ok(self, portdb, settings, ebuild_path):
88
		pkgdir = os.path.dirname(ebuild_path)
89
		mytree = os.path.dirname(os.path.dirname(pkgdir))
90
		distdir = settings["DISTDIR"]
91
		use = None
92
		if not self.fetchall:
93
			use = frozenset(settings["PORTAGE_USE"].split())
94
95
		try:
96
			uri_map = portdb.getFetchMap(self.pkg.cpv,
97
				useflags=use, mytree=mytree)
98
		except portage.exception.InvalidDependString as e:
99
			return False
100
101
		sizes = {}
102
		for filename in uri_map:
103
			try:
104
				st = os.lstat(os.path.join(distdir, filename))
105
			except OSError:
106
				return False
107
			if st.st_size == 0:
108
				return False
109
			sizes[filename] = st.st_size
110
111
		digests = portage.Manifest(pkgdir, distdir).getTypeDigests("DIST")
112
		for filename, actual_size in sizes.items():
113
			size = digests.get(filename, {}).get('size')
114
			if size is None:
115
				continue
116
			if size != actual_size:
117
				return False
118
119
		# All files are present and sizes are ok. In this case the normal
120
		# fetch code will be skipped, so we need to generate equivalent
121
		# output here.
122
		if self.logfile is not None:
123
			f = codecs.open(_unicode_encode(self.logfile,
124
				encoding=_encodings['fs'], errors='strict'),
125
				mode='a', encoding=_encodings['content'], errors='replace')
126
			for filename in uri_map:
127
				f.write((' * %s size ;-) ...' % \
128
					filename).ljust(73) + '[ ok ]\n')
129
			f.close()
130
131
		return True
132
81
	def _pipe(self, fd_pipes):
133
	def _pipe(self, fd_pipes):
82
		"""When appropriate, use a pty so that fetcher progress bars,
134
		"""When appropriate, use a pty so that fetcher progress bars,
83
		like wget has, will work properly."""
135
		like wget has, will work properly."""

Return to bug 304129