Ensure only new updates are installed 09/6109/1
authorWilliam Douglas <william.douglas@intel.com>
Tue, 30 Jul 2013 20:55:12 +0000 (13:55 -0700)
committerWilliam Douglas <william.douglas@intel.com>
Tue, 30 Jul 2013 20:55:12 +0000 (13:55 -0700)
The previously get_uninstalled_updates would look only at updates
which had been installed by the system updater and would then add
updates that didn't need to be applied because the current system
was installed from a later image than the earlier updates.

This patch adds a check for said invalid updates as well as creates
a folder for the zypper rpm cache of the update when needed.

Signed-off-by: William Douglas <william.douglas@intel.com>
swup.py

diff --git a/swup.py b/swup.py
index f61f052..cf270b1 100755 (executable)
--- a/swup.py
+++ b/swup.py
@@ -21,6 +21,7 @@ import re
 
 update_repo="http://www.planux.com/updates"
 update_cache="/var/cache/updatemanager"
+zypp_cache="/var/cache/zypp"
 # zypper return values that are acceptable when running the patch command
 patch_okay_codes = [0, 102, 103]
 
@@ -287,6 +288,16 @@ def list_updates():
 
 def get_uninstalled_updates(updates):
     uninstalled = copy.deepcopy(updates)
+    to_install = []
+    to_install_fixed = []
+    if os.path.isdir("%s/install/" % update_cache):
+        to_install = os.listdir("%s/install/" % update_cache)
+    for i in to_install:
+        to_install_fixed.append(re.sub('^[0-9]*-', '', i))
+    for i in uninstalled.keys():
+        if i not in to_install_fixed:
+            uninstalled.pop(i)
+
     if os.path.isdir("%s/installed/" % update_cache):
         update_ids = sorted(uninstalled.keys(), reverse=True)
         installed = sorted(os.listdir("%s/installed/" % update_cache), reverse=True)
@@ -377,6 +388,8 @@ def run_action(options):
         updates = parse_updates()
         uninstalled_updates = get_uninstalled_updates(updates)
         for u in uninstalled_updates.values():
+            if not os.path.exists("%s/packages/%s/rpms" % (zypp_cache, u['id'])):
+                os.makedirs("%s/packages/%s/rpms" % (zypp_cache, u['id']))
             download_update(u)
             install_update(u)