From 3548aaa212dacd286990ddca15c3b539c54fadf8 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 18 Jan 2007 23:51:53 +0000 Subject: Simplify rsync timestamp.chk handling and print the correct path for bug #50738. Thanks to jeka for reporting on irc. (trunk r5716) svn path=/main/branches/2.1.2/; revision=5717 --- bin/emerge | 152 +++++++++++++++++-------------------------------------------- 1 file changed, 43 insertions(+), 109 deletions(-) diff --git a/bin/emerge b/bin/emerge index 95aae5ef2..88940f177 100755 --- a/bin/emerge +++ b/bin/emerge @@ -29,8 +29,7 @@ except ImportError: sys.path.insert(0, "/usr/lib/portage/pym") import portage del os.environ["PORTAGE_LEGACY_GLOBALS"] -from portage import digraph, portdbapi -from portage_const import NEWS_LIB_PATH +from portage import digraph import emergehelp, xpak, commands, errno, re, socket, time, types import output @@ -3525,25 +3524,6 @@ def chk_updated_info_files(root, infodirs, prev_mtimes, retval): def post_emerge(settings, mtimedb, retval): - """ - Misc. things to run at the end of a merge session. - - Update Info Files - Update Config Files - Update News Items - Commit mtimeDB - Exit Emerge - - @param settings: Configuration settings (typically portage.settings) - @type settings: portage.config() - @param mtimedb: The mtimeDB to store data needed across merge invocations - @type mtimedb: MtimeDB class instance - @param retval: Emerge's return value - @type retval: Int - @rype: None - @returns: - 1. Calls sys.exit(retval) - """ target_root = settings["ROOT"] info_mtimes = mtimedb["info"] config_protect = settings.get("CONFIG_PROTECT","").split() @@ -3559,23 +3539,6 @@ def post_emerge(settings, mtimedb, retval): chk_updated_info_files(target_root, infodirs, info_mtimes, retval) chk_updated_cfg_files(target_root, config_protect) - - NEWS_PATH = os.path.join( "metadata", "news" ) - UNREAD_PATH = os.path.join( target_root, NEWS_LIB_PATH, 'news') - porttree = portdbapi( porttree_root = settings["PORTDIR"], mysettings = settings ) - newsReaderDisplay = False - - for repo in porttree.getRepositories(): - unreadItems = checkUpdatedNewsItems(target_root, NEWS_PATH, UNREAD_PATH, repo) - if unreadItems: - print colorize("WARN", " * IMPORTANT:"), - print "%s news items need reading for repository '%s'." % (unreadItems, repo) - newsReaderDisplay = True - - if newsReaderDisplay: - print colorize("WARN", " *"), - print "Use " + colorize("GOOD", "eselect news") + " to read news items." - mtimedb.commit() sys.exit(retval) @@ -3614,28 +3577,6 @@ def chk_updated_cfg_files(target_root, config_protect): print " "+yellow("*")+" Type "+green("emerge --help config")+" to learn how to update config files." print -def checkUpdatedNewsItems( root, NEWS_PATH, UNREAD_PATH, repo_id ): - """ - Examines news items in repodir + '/' + NEWS_PATH and attempts to find unread items - Returns the number of unread (yet relevent) items. - - @param root: - @type root: - @param NEWS_PATH: - @type NEWS_PATH: - @param UNREAD_PATH: - @type UNREAD_PATH: - @param repo_id: - @type repo_id: - @rtype: Integer - @returns: - 1. The number of unread but relevant news items. - - """ - from portage_news import NewsManager - manager = NewsManager( root, NEWS_PATH, UNREAD_PATH ) - return manager.getUnreadItems( repo_id, update=True ) - def is_valid_package_atom(x): try: testkey = portage.dep_getkey(x) @@ -3796,32 +3737,23 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): rsync_opts.append("--bwlimit=%s" % \ settings["RSYNC_RATELIMIT"]) - servertimestampdir = settings.depcachedir+"/" - servertimestampfile = settings.depcachedir+"/timestamp.chk" - tmpservertimestampdir = settings["PORTAGE_TMPDIR"]+"/" - tmpservertimestampfile = settings["PORTAGE_TMPDIR"]+"/timestamp.chk" - - # We only use the backup if a timestamp exists in the portdir. - content=None - if os.path.exists(myportdir+"/metadata/timestamp.chk"): - content=portage.grabfile(servertimestampfile) - if (not content): - content=portage.grabfile(myportdir+"/metadata/timestamp.chk") + # Real local timestamp file. + servertimestampfile = os.path.join( + myportdir, "metadata", "timestamp.chk") + # Temporary file for remote server timestamp comparison. + tmpservertimestampfile = os.path.join( + settings["PORTAGE_TMPDIR"], "timestamp.chk") - if (content): + content = portage_util.grabfile(servertimestampfile) + mytimestamp = 0 + if content: try: - mytimestamp=time.mktime(time.strptime(content[0], "%a, %d %b %Y %H:%M:%S +0000")) - except ValueError: - mytimestamp=0 - else: - mytimestamp=0 - - if not os.path.exists(servertimestampdir): - os.mkdir(servertimestampdir) - os.chown(servertimestampdir, os.getuid(), portage.portage_gid) - os.chmod(servertimestampdir, 02775) + mytimestamp = time.mktime(time.strptime(content[0], + "%a, %d %b %Y %H:%M:%S +0000")) + except OverflowError, ValueError: + pass + del content - #exitcode=0 try: if settings.has_key("RSYNC_RETRIES"): print yellow("WARNING:")+" usage of RSYNC_RETRIES is deprecated, use PORTAGE_RSYNC_RETRIES instead" @@ -3896,7 +3828,7 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): (retries,maxretries,dosyncuri)) print "\n\n>>> Starting retry %d of %d with %s" % (retries,maxretries,dosyncuri) - if "--quiet" not in myopts: + if mytimestamp != 0 and "--quiet" not in myopts: print ">>> Checking server timestamp ..." rsynccommand = " ".join(["/usr/bin/rsync", " ".join(rsync_opts), @@ -3905,18 +3837,32 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): if "--debug" in myopts: print rsynccommand - mycommand = " ".join([rsynccommand, - dosyncuri + "/metadata/timestamp.chk", - tmpservertimestampdir]) - exitcode=portage.spawn(mycommand,settings,free=1) - if (exitcode==0): + exitcode = os.EX_OK + servertimestamp = 0 + if mytimestamp != 0: + mycommand = rsynccommand.split() + mycommand.append(dosyncuri.rstrip("/") + \ + "/metadata/timestamp.chk") + mycommand.append(tmpservertimestampfile) + import portage_exec try: - servertimestamp = time.mktime(time.strptime(portage.grabfile(tmpservertimestampfile)[0], "%a, %d %b %Y %H:%M:%S +0000")) - except SystemExit, e: - raise # Needed else can't exit - except: - servertimestamp = 0 - + exitcode = portage_exec.spawn( + mycommand, env=settings.environ()) + content = portage.grabfile(tmpservertimestampfile) + if content: + try: + servertimestamp = time.mktime(time.strptime( + content[0], "%a, %d %b %Y %H:%M:%S +0000")) + except OverflowError, ValueError: + pass + del content + finally: + try: + os.unlink(tmpservertimestampfile) + except OSError: + pass + del mycommand + if exitcode == os.EX_OK: if (servertimestamp != 0) and (servertimestamp == mytimestamp): emergelog(xterm_titles, ">>> Cancelling sync -- Already current.") @@ -3925,7 +3871,7 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): print ">>> Timestamps on the server and in the local repository are the same." print ">>> Cancelling all further sync action. You are already up to date." print ">>>" - print ">>> In order to force sync, remove '%s'." % tmpservertimestampfile + print ">>> In order to force sync, remove '%s'." % servertimestampfile print ">>>" print sys.exit(0) @@ -3936,7 +3882,7 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): print ">>>" print ">>> SERVER OUT OF DATE: %s" % dosyncuri print ">>>" - print ">>> In order to force sync, remove '%s'." % tmpservertimestampfile + print ">>> In order to force sync, remove '%s'." % servertimestampfile print ">>>" print elif (servertimestamp == 0) or (servertimestamp > mytimestamp): @@ -3961,18 +3907,6 @@ def action_sync(settings, trees, mtimedb, myopts, myaction): if (exitcode==0): emergelog(xterm_titles, "=== Sync completed with %s" % dosyncuri) - # save timestamp.chk for next timestamp check. - try: - if tmpservertimestampfile is not None: - portage.movefile(tmpservertimestampfile, - servertimestampfile, mysettings=settings) - except SystemExit, e: - raise - except Exception, e: - portage.writemsg("!!! Failed to save current timestamp.\n", - noiselevel=-1) - portage.writemsg("!!! %s\n" % str(e), noiselevel=-1) - del e elif (exitcode>0): print if exitcode==1: -- cgit v1.2.3-1-g7c22