Permalink
Browse files

[*] BO: More detailled errors when using Archive tar tool

  • Loading branch information...
1 parent c7bdca0 commit 1ee78f5cad9a7e005f0922c57fafbae78a109514 @gRoussac gRoussac committed Mar 25, 2013
Showing with 31 additions and 28 deletions.
  1. +20 −16 controllers/admin/AdminTranslationsController.php
  2. +11 −12 tools/tar/Archive_Tar.php
@@ -719,32 +719,36 @@ public function submitAddLang()
@stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 5)))))
{
$file = _PS_TRANSLATIONS_DIR_.$arr_import_lang[0].'.gzip';
- if (file_put_contents($file, $content))
+ if (is_writable(dirname($file)) && (bool)file_put_contents($file, $content))
{
$gz = new Archive_Tar($file, true);
$files_list = $gz->listContent();
- if ($gz->extract(_PS_TRANSLATIONS_DIR_.'../', false))
+ if ($error = $gz->extract(_PS_TRANSLATIONS_DIR_.'../', false))
{
- AdminTranslationsController::checkAndAddMailsFiles($arr_import_lang[0], $files_list);
- $tab_errors = AdminTranslationsController::addNewTabs($arr_import_lang[0], $files_list);
- if (count($tab_errors))
- $this->errors += $tab_errors;
+ if (is_object($error) && !empty($error->message))
+ $this->errors[] = Tools::displayError('The archive cannot be extracted.'). ' '.$error->message;
else
{
- if (!Language::checkAndAddLanguage($arr_import_lang[0]))
- $conf = 20;
+ AdminTranslationsController::checkAndAddMailsFiles($arr_import_lang[0], $files_list);
+ $tab_errors = AdminTranslationsController::addNewTabs($arr_import_lang[0], $files_list);
+ if (count($tab_errors))
+ $this->errors += $tab_errors;
+ else
+ {
+ if (!Language::checkAndAddLanguage($arr_import_lang[0]))
+ $conf = 20;
+ }
+ if (!unlink($file))
+ $this->errors[] = sprintf(Tools::displayError('Cannot delete the archive %s.'), $file);
+
+ $this->redirect(false, (isset($conf) ? $conf : '15'));
}
- if (!unlink($file))
- $this->errors[] = Tools::displayError('Cannot delete the archive.');
-
- $this->redirect(false, (isset($conf) ? $conf : '15'));
}
- $this->errors[] = Tools::displayError('The archive cannot be extracted.');
- if (!unlink($file))
- $this->errors[] = Tools::displayError('Cannot delete the archive.');
+ elseif (!unlink($file))
+ $this->errors[] = sprintf(Tools::displayError('Cannot delete the archive %s.'), $file);
}
else
- $this->errors[] = Tools::displayError('The server does not have permissions for writing.');
+ $this->errors[] = Tools::displayError('The server does not have permissions for writing.'. ' '.sprintf(Tools::displayError('Please check rights for %s'), dirname($file)));
}
else
$this->errors[] = Tools::displayError('Language not found.');
View
@@ -441,7 +441,6 @@ function extractModify($p_path, $p_remove_path, $check_base_dir = true)
"complete", 0, $p_remove_path, $check_base_dir);
$this->_close();
}
-
return $v_result;
}
// }}}
@@ -568,15 +567,15 @@ function setAttribute()
function _error($p_message)
{
// ----- To be completed
- $this->raiseError($p_message);
+ return $this->raiseError($p_message);
}
// }}}
// {{{ _warning()
function _warning($p_message)
{
// ----- To be completed
- $this->raiseError($p_message);
+ return $this->raiseError($p_message);
}
// }}}
@@ -1327,7 +1326,7 @@ function _extractInString($p_filename)
if ($v_header['filename'] == $p_filename) {
if ($v_header['typeflag'] == "5") {
- $this->_error('Unable to extract in string a directory '
+ return $this->_error('Unable to extract in string a directory '
.'entry {'.$v_header['filename'].'}');
return NULL;
} else {
@@ -1386,7 +1385,7 @@ function _extractList($p_path, &$p_list_detail, $p_mode,
$v_listing = TRUE;
break;
default :
- $this->_error('Invalid extract mode ('.$p_mode.')');
+ return $this->_error('Invalid extract mode ('.$p_mode.')');
return false;
}
@@ -1456,20 +1455,20 @@ function _extractList($p_path, &$p_list_detail, $p_mode,
if (file_exists($v_header['filename'])) {
if ( (@is_dir($v_header['filename']))
&& ($v_header['typeflag'] == '')) {
- $this->_error('File '.$v_header['filename']
+ return $this->_error('File '.$v_header['filename']
.' already exists as a directory');
return false;
}
if ( ($this->_isArchive($v_header['filename']))
&& ($v_header['typeflag'] == "5")) {
- $this->_error('Directory '.$v_header['filename']
+ return $this->_error('Directory '.$v_header['filename']
.' already exists as a file');
return false;
}
if ($check_base_dir OR _PS_ROOT_DIR_ != realpath($v_header['filename']))
{
if (!is_writeable($v_header['filename'])) {
- $this->_error('File '.$v_header['filename']
+ return $this->_error('File '.$v_header['filename']
.' already exists and is write protected');
return false;
}
@@ -1484,22 +1483,22 @@ function _extractList($p_path, &$p_list_detail, $p_mode,
= $this->_dirCheck(($v_header['typeflag'] == "5"
?$v_header['filename']
:dirname($v_header['filename'])))) != 1) {
- $this->_error('Unable to create path for '.$v_header['filename']);
+ return $this->_error('Unable to create path for '.$v_header['filename']);
return false;
}
if ($v_extract_file) {
if ($v_header['typeflag'] == "5") {
if (!@file_exists($v_header['filename'])) {
if (!@mkdir($v_header['filename'], 0777)) {
- $this->_error('Unable to create directory {'
+ return $this->_error('Unable to create directory {'
.$v_header['filename'].'}');
return false;
}
}
} else {
if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) {
- $this->_error('Error while opening {'.$v_header['filename']
+ return $this->_error('Error while opening {'.$v_header['filename']
.'} in write binary mode');
return false;
} else {
@@ -1524,7 +1523,7 @@ function _extractList($p_path, &$p_list_detail, $p_mode,
// ----- Check the file size
clearstatcache();
if (filesize($v_header['filename']) != $v_header['size']) {
- $this->_error('Extracted file '.$v_header['filename']
+ return $this->_error('Extracted file '.$v_header['filename']
.' does not have the correct file size \''
.filesize($v_header['filename'])
.'\' ('.$v_header['size']

0 comments on commit 1ee78f5

Please sign in to comment.