commit:     38903acaed401c1a5daba418172eacf052cc2435
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sun Aug  9 17:56:22 2015 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Aug  9 17:56:22 2015 +0000
URL:        https://gitweb.gentoo.org/proj/grss.git/commit/?id=38903aca

bin/grsup: backup old make.conf if clobbering.

 bin/grsup | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/bin/grsup b/bin/grsup
index 5e0a70c..d722edb 100755
--- a/bin/grsup
+++ b/bin/grsup
@@ -211,8 +211,10 @@ def main():
     # If a raw new make.conf exists, pick it, else pick the highest cycle no.
     newmakeconf = os.path.join(libdir, 'core/etc/portage/make.conf')
     oldmakeconf = os.path.join(CONST.PORTAGE_CONFIGDIR, 'make.conf')
+
+    do_copy = False
     if os.path.isfile(newmakeconf):
-        shutil.copy(newmakeconf, oldmakeconf)
+        do_copy = True
     else:
         cycled_files = {}
         for f in glob.glob('%s.*' % newmakeconf):
@@ -222,10 +224,19 @@ def main():
                 cycled_files[cycle_no] = m.group(0)
         try:
             max_cycle_no = max(cycled_files)
-            shutil.copy(cycled_files[max_cycle_no], oldmakeconf)
-        except ValueError:
+            newmakeconf = cycled_files[max_cycle_no]
+            do_copy = True
+        except ValueError: # thrown by max() if cycled_files is empty
             pass
 
+    if do_copy:
+        if os.path.isfile(oldmakeconf):
+            if not filecmp.cmp(newmakeconf, oldmakeconf):
+                print('New make.conf differs from local version. Backing up as 
make.conf.old')
+                shutil(oldmakeconf, '%s.old' % oldmakeconf)
+        shutil.copy(newmakeconf, oldmakeconf)
+
+    # Check if we left behind a dirty /etc/portage
     if os.path.isfile(CONST.PORTAGE_DIRTYFILE):
         WorldConf.clean()
     open(CONST.PORTAGE_DIRTYFILE, 'a').close()

Reply via email to