Blame SOURCES/0004-Backup-upgrade-tracker.patch

f332ec
From 75bf654f1023e36f67b27d8e47e077400c072b84 Mon Sep 17 00:00:00 2001
f332ec
From: "Endi S. Dewata" <edewata@redhat.com>
f332ec
Date: Mon, 28 Oct 2013 17:21:59 -0400
f332ec
Subject: [PATCH 4/6] Backup upgrade tracker.
f332ec
f332ec
The upgrade framework has been modified to backup the files used
f332ec
to track the upgrade progress. If the tracker file is also modified
f332ec
by the upgrade scriptlet, it will only keep the initial backup
f332ec
(before any modifications were made).
f332ec
f332ec
Ticket #763
f332ec
---
f332ec
 base/common/python/pki/upgrade.py        | 8 ++++++--
f332ec
 base/common/python/pki/util.py           | 6 +++++-
f332ec
 base/server/python/pki/server/upgrade.py | 1 +
f332ec
 3 files changed, 12 insertions(+), 3 deletions(-)
f332ec
f332ec
diff --git a/base/common/python/pki/upgrade.py b/base/common/python/pki/upgrade.py
f332ec
index bd78ec9..7e48180 100644
f332ec
--- a/base/common/python/pki/upgrade.py
f332ec
+++ b/base/common/python/pki/upgrade.py
f332ec
@@ -110,6 +110,7 @@ class PKIUpgradeTracker(object):
f332ec
         index_key='PKI_UPGRADE_INDEX'):
f332ec
 
f332ec
         self.name = name
f332ec
+        self.filename = filename
f332ec
 
f332ec
         self.version_key = version_key
f332ec
         self.index_key = index_key
f332ec
@@ -267,6 +268,7 @@ class PKIUpgradeScriptlet(object):
f332ec
         # in this version, update the tracker version.
f332ec
 
f332ec
         tracker = self.upgrader.get_tracker()
f332ec
+        self.backup(tracker.filename)
f332ec
 
f332ec
         if not self.last:
f332ec
             tracker.set_index(self.index)
f332ec
@@ -389,7 +391,8 @@ class PKIUpgradeScriptlet(object):
f332ec
 
f332ec
             if os.path.isfile(path):
f332ec
                 if verbose: print 'Saving ' + path
f332ec
-                pki.util.copyfile(path, dest)
f332ec
+                # do not overwrite initial backup
f332ec
+                pki.util.copyfile(path, dest, overwrite=False)
f332ec
 
f332ec
             else:
f332ec
                 for sourcepath, _, filenames in os.walk(path):
f332ec
@@ -405,7 +408,8 @@ class PKIUpgradeScriptlet(object):
f332ec
                         targetfile = os.path.join(destpath, filename)
f332ec
 
f332ec
                         if verbose: print 'Saving ' + sourcefile
f332ec
-                        pki.util.copyfile(sourcefile, targetfile)
f332ec
+                        # do not overwrite initial backup
f332ec
+                        pki.util.copyfile(sourcefile, targetfile, overwrite=False)
f332ec
 
f332ec
         else:
f332ec
 
f332ec
diff --git a/base/common/python/pki/util.py b/base/common/python/pki/util.py
f332ec
index 4d25390..62aec2c 100644
f332ec
--- a/base/common/python/pki/util.py
f332ec
+++ b/base/common/python/pki/util.py
f332ec
@@ -53,11 +53,15 @@ def copy(source, dest):
f332ec
                 targetfile = os.path.join(destpath, filename)
f332ec
                 copyfile(sourcefile, targetfile)
f332ec
 
f332ec
-def copyfile(source, dest):
f332ec
+def copyfile(source, dest, overwrite=True):
f332ec
     """
f332ec
     Copy a file or link while preserving its attributes.
f332ec
     """
f332ec
 
f332ec
+    # if dest already exists and not overwriting, do nothing
f332ec
+    if os.path.exists(dest) and not overwrite:
f332ec
+        return
f332ec
+
f332ec
     if os.path.islink(source):
f332ec
         target = os.readlink(source)
f332ec
         os.symlink(target, dest)
f332ec
diff --git a/base/server/python/pki/server/upgrade.py b/base/server/python/pki/server/upgrade.py
f332ec
index 940dbe4..ee0dfed 100644
f332ec
--- a/base/server/python/pki/server/upgrade.py
f332ec
+++ b/base/server/python/pki/server/upgrade.py
f332ec
@@ -60,6 +60,7 @@ class PKIServerUpgradeScriptlet(pki.upgrade.PKIUpgradeScriptlet):
f332ec
         # in this version, update the tracker version.
f332ec
 
f332ec
         tracker = self.upgrader.get_tracker(instance, subsystem)
f332ec
+        self.backup(tracker.filename)
f332ec
 
f332ec
         if not self.last:
f332ec
             tracker.set_index(self.index)
f332ec
-- 
f332ec
1.8.3.1
f332ec