diff options
author | Endi S. Dewata <edewata@redhat.com> | 2013-10-28 17:21:59 -0400 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2013-10-31 18:04:14 -0400 |
commit | 86ef9b64cb0d71ace679881eacd2f6503afd954d (patch) | |
tree | 928d48d186bacf47e0049b81b4a1c2374973f5e7 | |
parent | aa52cb632be5f64c8859ac636937f0c526b1f10d (diff) | |
download | pki-86ef9b64cb0d71ace679881eacd2f6503afd954d.tar.gz pki-86ef9b64cb0d71ace679881eacd2f6503afd954d.tar.xz pki-86ef9b64cb0d71ace679881eacd2f6503afd954d.zip |
Backup upgrade tracker.
The upgrade framework has been modified to backup the files used
to track the upgrade progress. If the tracker file is also modified
by the upgrade scriptlet, it will only keep the initial backup
(before any modifications were made).
Ticket #763
-rw-r--r-- | base/common/python/pki/upgrade.py | 8 | ||||
-rw-r--r-- | base/common/python/pki/util.py | 6 | ||||
-rw-r--r-- | base/server/python/pki/server/upgrade.py | 1 |
3 files changed, 12 insertions, 3 deletions
diff --git a/base/common/python/pki/upgrade.py b/base/common/python/pki/upgrade.py index 05db24f63..8f1b1d896 100644 --- a/base/common/python/pki/upgrade.py +++ b/base/common/python/pki/upgrade.py @@ -107,6 +107,7 @@ class PKIUpgradeTracker(object): index_key='PKI_UPGRADE_INDEX'): self.name = name + self.filename = filename self.version_key = version_key self.index_key = index_key @@ -266,6 +267,7 @@ class PKIUpgradeScriptlet(object): # in this version, update the tracker version. tracker = self.upgrader.get_tracker() + self.backup(tracker.filename) if not self.last: tracker.set_index(self.index) @@ -388,7 +390,8 @@ class PKIUpgradeScriptlet(object): if os.path.isfile(path): if verbose: print 'Saving ' + path - pki.util.copyfile(path, dest) + # do not overwrite initial backup + pki.util.copyfile(path, dest, overwrite=False) else: for sourcepath, _, filenames in os.walk(path): @@ -404,7 +407,8 @@ class PKIUpgradeScriptlet(object): targetfile = os.path.join(destpath, filename) if verbose: print 'Saving ' + sourcefile - pki.util.copyfile(sourcefile, targetfile) + # do not overwrite initial backup + pki.util.copyfile(sourcefile, targetfile, overwrite=False) else: diff --git a/base/common/python/pki/util.py b/base/common/python/pki/util.py index 4d25390a6..62aec2c47 100644 --- a/base/common/python/pki/util.py +++ b/base/common/python/pki/util.py @@ -53,11 +53,15 @@ def copy(source, dest): targetfile = os.path.join(destpath, filename) copyfile(sourcefile, targetfile) -def copyfile(source, dest): +def copyfile(source, dest, overwrite=True): """ Copy a file or link while preserving its attributes. """ + # if dest already exists and not overwriting, do nothing + if os.path.exists(dest) and not overwrite: + return + if os.path.islink(source): target = os.readlink(source) os.symlink(target, dest) diff --git a/base/server/python/pki/server/upgrade.py b/base/server/python/pki/server/upgrade.py index 4afa5a72f..a9911b6ed 100644 --- a/base/server/python/pki/server/upgrade.py +++ b/base/server/python/pki/server/upgrade.py @@ -60,6 +60,7 @@ class PKIServerUpgradeScriptlet(pki.upgrade.PKIUpgradeScriptlet): # in this version, update the tracker version. tracker = self.upgrader.get_server_tracker(instance, subsystem) + self.backup(tracker.filename) if not self.last: tracker.set_index(self.index) |