ipa-restore: Check if directory is provided + better errors.

https://fedorahosted.org/freeipa/ticket/4683

Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
David Kupka 2014-11-21 06:30:17 -05:00 committed by Tomas Babej
parent 1b5cd5b227
commit b40cf4b283

View File

@ -152,6 +152,9 @@ class Restore(admintool.AdminTool):
else: else:
self.backup_dir = dirname 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 options.gpg_keyring:
if (not os.path.exists(options.gpg_keyring + '.pub') or if (not os.path.exists(options.gpg_keyring + '.pub') or
not os.path.exists(options.gpg_keyring + '.sec')): not os.path.exists(options.gpg_keyring + '.sec')):
@ -213,7 +216,10 @@ class Restore(admintool.AdminTool):
try: try:
dirsrv = services.knownservices.dirsrv dirsrv = services.knownservices.dirsrv
try:
self.read_header() 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 # These two checks would normally be in the validate method but
# we need to know the type of backup we're dealing with. # we need to know the type of backup we're dealing with.
if (self.backup_type != 'FULL' and not options.data_only and if (self.backup_type != 'FULL' and not options.data_only and
@ -546,7 +552,7 @@ class Restore(admintool.AdminTool):
Read the backup file header that contains the meta data about Read the backup file header that contains the meta data about
this particular backup. this particular backup.
''' '''
fd = open(self.header) with open(self.header) as fd:
config = SafeConfigParser() config = SafeConfigParser()
config.readfp(fd) config.readfp(fd)