|
|
e3ffab |
From 354f11fc9f417ba777e2e010597e72a013ae5d23 Mon Sep 17 00:00:00 2001
|
|
|
e3ffab |
From: David Kupka <dkupka@redhat.com>
|
|
|
e3ffab |
Date: Fri, 21 Nov 2014 06:30:17 -0500
|
|
|
e3ffab |
Subject: [PATCH] ipa-restore: Check if directory is provided + better errors.
|
|
|
e3ffab |
|
|
|
e3ffab |
https://fedorahosted.org/freeipa/ticket/4683
|
|
|
e3ffab |
|
|
|
e3ffab |
Reviewed-By: Tomas Babej <tbabej@redhat.com>
|
|
|
e3ffab |
---
|
|
|
e3ffab |
ipaserver/install/ipa_restore.py | 14 ++++++++++----
|
|
|
e3ffab |
1 file changed, 10 insertions(+), 4 deletions(-)
|
|
|
e3ffab |
|
|
|
e3ffab |
diff --git a/ipaserver/install/ipa_restore.py b/ipaserver/install/ipa_restore.py
|
|
|
e3ffab |
index 93f176d302a49319940555a0be3037620143e1f3..f290bae4dc6455bb22c4e726e72efe98205d970e 100644
|
|
|
e3ffab |
--- a/ipaserver/install/ipa_restore.py
|
|
|
e3ffab |
+++ b/ipaserver/install/ipa_restore.py
|
|
|
e3ffab |
@@ -152,6 +152,9 @@ class Restore(admintool.AdminTool):
|
|
|
e3ffab |
else:
|
|
|
e3ffab |
self.backup_dir = dirname
|
|
|
e3ffab |
|
|
|
e3ffab |
+ if not os.path.isdir(dirname):
|
|
|
e3ffab |
+ raise self.option_parser.error("must provide path to backup directory")
|
|
|
e3ffab |
+
|
|
|
e3ffab |
if options.gpg_keyring:
|
|
|
e3ffab |
if (not os.path.exists(options.gpg_keyring + '.pub') or
|
|
|
e3ffab |
not os.path.exists(options.gpg_keyring + '.sec')):
|
|
|
e3ffab |
@@ -213,7 +216,10 @@ class Restore(admintool.AdminTool):
|
|
|
e3ffab |
try:
|
|
|
e3ffab |
dirsrv = services.knownservices.dirsrv
|
|
|
e3ffab |
|
|
|
e3ffab |
- self.read_header()
|
|
|
e3ffab |
+ try:
|
|
|
e3ffab |
+ self.read_header()
|
|
|
e3ffab |
+ except IOError as e:
|
|
|
e3ffab |
+ raise admintool.ScriptError('Cannot read backup metadata: %s' % e)
|
|
|
e3ffab |
# These two checks would normally be in the validate method but
|
|
|
e3ffab |
# we need to know the type of backup we're dealing with.
|
|
|
e3ffab |
if (self.backup_type != 'FULL' and not options.data_only and
|
|
|
e3ffab |
@@ -546,9 +552,9 @@ class Restore(admintool.AdminTool):
|
|
|
e3ffab |
Read the backup file header that contains the meta data about
|
|
|
e3ffab |
this particular backup.
|
|
|
e3ffab |
'''
|
|
|
e3ffab |
- fd = open(self.header)
|
|
|
e3ffab |
- config = SafeConfigParser()
|
|
|
e3ffab |
- config.readfp(fd)
|
|
|
e3ffab |
+ with open(self.header) as fd:
|
|
|
e3ffab |
+ config = SafeConfigParser()
|
|
|
e3ffab |
+ config.readfp(fd)
|
|
|
e3ffab |
|
|
|
e3ffab |
self.backup_type = config.get('ipa', 'type')
|
|
|
e3ffab |
self.backup_time = config.get('ipa', 'time')
|
|
|
e3ffab |
--
|
|
|
e3ffab |
2.1.0
|
|
|
e3ffab |
|