[fix] Catch IOError on tar creation (backup).

This commit is contained in:
opi 2016-05-06 12:00:24 +02:00
parent 5027ec0468
commit 286ce86993
2 changed files with 20 additions and 19 deletions

View file

@ -185,6 +185,7 @@
"backup_nothings_done" : "There is nothing to save", "backup_nothings_done" : "There is nothing to save",
"backup_cleaning_failed" : "Unable to clean backup temporary directory", "backup_cleaning_failed" : "Unable to clean backup temporary directory",
"backup_complete" : "Backup complete", "backup_complete" : "Backup complete",
"backup_failed" : "Backup failed",
"backup_invalid_archive" : "Invalid backup archive", "backup_invalid_archive" : "Invalid backup archive",
"restore_action_required" : "You must specify something to restore", "restore_action_required" : "You must specify something to restore",
"restore_confirm_yunohost_installed" : "Do you really want to restore an already installed system? [{answers:s}]", "restore_confirm_yunohost_installed" : "Do you really want to restore an already installed system? [{answers:s}]",

View file

@ -265,29 +265,29 @@ def backup_create(name=None, description=None, output_directory=None,
if not no_compress: if not no_compress:
logger.info(m18n.n('backup_creating_archive')) logger.info(m18n.n('backup_creating_archive'))
archive_file = "%s/%s.tar.gz" % (output_directory, name) archive_file = "%s/%s.tar.gz" % (output_directory, name)
try: # Create the archives directory
tar = tarfile.open(archive_file, "w:gz")
except:
tar = None
# Create the archives directory and retry
if not os.path.isdir(archives_path): if not os.path.isdir(archives_path):
os.mkdir(archives_path, 0750) os.mkdir(archives_path, 0750)
# Open archive file for writing
try: try:
tar = tarfile.open(archive_file, "w:gz") tar = tarfile.open(archive_file, "w:gz")
except: except:
logger.debug("unable to open '%s' for writing", logger.debug("unable to open '%s' for writing",
archive_file, exc_info=1) archive_file, exc_info=1)
tar = None
else:
logger.debug("unable to open '%s' for writing",
archive_file, exc_info=1)
if tar is None:
_clean_tmp_dir(2) _clean_tmp_dir(2)
raise MoulinetteError(errno.EIO, raise MoulinetteError(errno.EIO,
m18n.n('backup_archive_open_failed')) m18n.n('backup_archive_open_failed'))
# Write into archive
try:
tar.add(tmp_dir, arcname='') tar.add(tmp_dir, arcname='')
tar.close() tar.close()
except IOError as e:
logger.error(m18n.n('backup_archive_writing_error'), exc_info=1)
_clean_tmp_dir(3)
raise MoulinetteError(errno.EIO, m18n.n('backup_failed'))
# Move info file # Move info file
os.rename(tmp_dir + '/info.json', os.rename(tmp_dir + '/info.json',