diff options
author | David Kupka <dkupka@redhat.com> | 2014-11-21 06:30:17 -0500 |
---|---|---|
committer | Tomas Babej <tbabej@redhat.com> | 2014-11-21 15:19:56 +0100 |
commit | 373bbee4e3c25fd6fb41a75b62b09d60da1a5d82 (patch) | |
tree | b5684976a067d950aaa1d5827b0ea9dbbba0276d /ipaserver | |
parent | 71c4d3e979584e9f841bc8565e69b53fc111c8c6 (diff) | |
download | freeipa-373bbee4e3c25fd6fb41a75b62b09d60da1a5d82.tar.gz freeipa-373bbee4e3c25fd6fb41a75b62b09d60da1a5d82.tar.xz freeipa-373bbee4e3c25fd6fb41a75b62b09d60da1a5d82.zip |
ipa-restore: Check if directory is provided + better errors.
https://fedorahosted.org/freeipa/ticket/4683
Reviewed-By: Tomas Babej <tbabej@redhat.com>
Diffstat (limited to 'ipaserver')
-rw-r--r-- | ipaserver/install/ipa_restore.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/ipaserver/install/ipa_restore.py b/ipaserver/install/ipa_restore.py index 6f43321b0..8bd0bce48 100644 --- a/ipaserver/install/ipa_restore.py +++ b/ipaserver/install/ipa_restore.py @@ -151,6 +151,9 @@ class Restore(admintool.AdminTool): else: self.backup_dir = dirname + if not os.path.isdir(dirname): + raise self.option_parser.error("must provide path to backup directory") + if options.gpg_keyring: if (not os.path.exists(options.gpg_keyring + '.pub') or not os.path.exists(options.gpg_keyring + '.sec')): @@ -212,7 +215,10 @@ class Restore(admintool.AdminTool): try: dirsrv = services.knownservices.dirsrv - self.read_header() + try: + self.read_header() + except IOError as e: + raise admintool.ScriptError('Cannot read backup metadata: %s' % e) # These two checks would normally be in the validate method but # we need to know the type of backup we're dealing with. if (self.backup_type != 'FULL' and not options.data_only and @@ -545,9 +551,9 @@ class Restore(admintool.AdminTool): Read the backup file header that contains the meta data about this particular backup. ''' - fd = open(self.header) - config = SafeConfigParser() - config.readfp(fd) + with open(self.header) as fd: + config = SafeConfigParser() + config.readfp(fd) self.backup_type = config.get('ipa', 'type') self.backup_time = config.get('ipa', 'time') |