Commits

Michał Górny  committed d515e3c

Move pretend option handling completely to SmartLiveRebuild.cli.

  • Participants
  • Parent commits 9ead1e5

Comments (0)

Files changed (3)

File SmartLiveRebuild/cli.py

 import os
 from optparse import OptionParser
 
+import portage
+
 from SmartLiveRebuild import PV
 from SmartLiveRebuild.core import Config, SmartLiveRebuild, SLRFailure
 from SmartLiveRebuild.output import out
 		except Exception:
 			pass
 
+	if opts.setuid:
+		puid = portage.data.portage_uid
+		pgid = portage.data.portage_gid
+		if puid and pgid and os.geteuid() != 0 and os.getuid() == puid:
+			if not opts.pretend:
+				out.s1('Running as the portage user, assuming --pretend.')
+				opts.pretend = True
+			if opts.quickpkg:
+				out.err("Running as the portage user, --quickpkg probably won't work")
+
 	try:
-		packages = SmartLiveRebuild(opts)
+		packages = SmartLiveRebuild(opts, saveuid = not opts.pretend)
 	except SLRFailure:
 		return 1
 

File SmartLiveRebuild/core.py

 		if puid and pgid:
 			if not userok:
 				if os.getuid() == puid:
-					if not opts.pretend:
-						out.s1('Running as the portage user, assuming --pretend.')
-						opts.pretend = True
-					if opts.quickpkg:
-						out.err("Running as the portage user, --quickpkg probably won't work")
 					userok = True
-			elif opts.pretend and not opts.quickpkg and not saveuid:
+			elif not saveuid and not opts.quickpkg:
 				out.s1('Dropping superuser privileges ...')
 				os.setuid(puid)
 			else:
 				childpid = os.fork()
 		else:
 			out.err("setuid requested but there's no 'portage' user in the system")
+			return 1
 
 	if not opts.unprivileged_user and not userok:
 		out.err('Either superuser or portage privileges are required!')

File SmartLiveRebuild/sets.py

 	description = "Package set containing live packages awaiting update"
 
 	def __init__(self, opts, dbapi, settings):
-		opts.pretend = True
-
 		self._options = opts
 		self._dbapi = dbapi
 		self._settings = settings