From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 25 Jul 2006 22:36:15 -0000 Subject: [Cluster-devel] conga/luci/utils luci_admin Message-ID: <20060725223615.15012.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: conga Changes by: rmccabe at sourceware.org 2006-07-25 22:36:15 Modified files: luci/utils : luci_admin Log message: restore uid/gid and permissions if backup or restore fails Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/utils/luci_admin.diff?cvsroot=cluster&r1=1.28&r2=1.29 --- conga/luci/utils/luci_admin 2006/07/24 20:17:02 1.28 +++ conga/luci/utils/luci_admin 2006/07/25 22:36:14 1.29 @@ -895,16 +895,25 @@ luci = pwd.getpwnam(LUCI_USER)[2:4] except: sys.stderr.write('Cannot find the \"' + LUCI_USER + '\" user.\n') - return -1 + sys.exit(1) doc = luci_backup(argv[2:]) try: os.chown(LUCI_DB_PATH, luci[0], luci[1]) os.chmod(LUCI_DB_PATH, 0600) + for i in [ '.tmp', '.old', '.index', '.lock' ]: + try: + os.chown(LUCI_DB_PATH + i, luci[0], luci[1]) + os.chmod(LUCI_DB_PATH + i, 0600) + except: pass except: sys.stderr.write('Unable to change ownership of the Luci database back to user \"' + LUCI_USER + '\"\n') + if not doc: + sys.stderr.write('The Luci backup failed.\n') + sys.exit(1) + try: # The LUCI_BACKUP_DIR must not be world-writable # as the code below is obviously not safe against @@ -930,7 +939,7 @@ f = file(LUCI_BACKUP_PATH, 'wb+') except: sys.stderr.write('Unable to open \"' + LUCI_BACKUP_PATH + '\" to write backup.\n') - return -1 + sys.exit(1) try: os.chmod(LUCI_BACKUP_PATH, 0600) @@ -938,16 +947,12 @@ print "An error occurred while making",LUCI_BACKUP_PATH,"read-only:",e print "Please check that this file is not world-readable." - if not doc: - sys.stderr.write('The Luci backup failed.\n') - return -1 - try: f.write(doc.toprettyxml()) f.close() except: sys.stderr.write('The Luci backup failed.\n') - return -1 + sys.exit(1) print 'Luci backup was successful.\nThe backup data is contained in the file \"' + LUCI_BACKUP_PATH + '\"' @@ -958,9 +963,10 @@ except: pass if luci_restore(argv[2:]): + retCode = False print 'The Luci restore failed. Try reinstalling Luci, then restoring again.' - return False else: + retCode = True print 'Restore was successful.' restart_message() @@ -977,7 +983,7 @@ sys.stderr.write('Unable to change ownership of the Luci database back to user \"' + LUCI_USER + '\"\n') return False - return True + return retCode def luci_help(argv):