[*] BO: More detailled errors when using Archive tar tool
This commit is contained in:
@@ -719,32 +719,36 @@ class AdminTranslationsControllerCore extends AdminController
|
|||||||
@stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 5)))))
|
@stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 5)))))
|
||||||
{
|
{
|
||||||
$file = _PS_TRANSLATIONS_DIR_.$arr_import_lang[0].'.gzip';
|
$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);
|
$gz = new Archive_Tar($file, true);
|
||||||
$files_list = $gz->listContent();
|
$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);
|
if (is_object($error) && !empty($error->message))
|
||||||
$tab_errors = AdminTranslationsController::addNewTabs($arr_import_lang[0], $files_list);
|
$this->errors[] = Tools::displayError('The archive cannot be extracted.'). ' '.$error->message;
|
||||||
if (count($tab_errors))
|
|
||||||
$this->errors += $tab_errors;
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!Language::checkAndAddLanguage($arr_import_lang[0]))
|
AdminTranslationsController::checkAndAddMailsFiles($arr_import_lang[0], $files_list);
|
||||||
$conf = 20;
|
$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.');
|
elseif (!unlink($file))
|
||||||
if (!unlink($file))
|
$this->errors[] = sprintf(Tools::displayError('Cannot delete the archive %s.'), $file);
|
||||||
$this->errors[] = Tools::displayError('Cannot delete the archive.');
|
|
||||||
}
|
}
|
||||||
else
|
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
|
else
|
||||||
$this->errors[] = Tools::displayError('Language not found.');
|
$this->errors[] = Tools::displayError('Language not found.');
|
||||||
|
|||||||
+11
-12
@@ -441,7 +441,6 @@ class Archive_Tar extends PEAR
|
|||||||
"complete", 0, $p_remove_path, $check_base_dir);
|
"complete", 0, $p_remove_path, $check_base_dir);
|
||||||
$this->_close();
|
$this->_close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $v_result;
|
return $v_result;
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
@@ -568,7 +567,7 @@ class Archive_Tar extends PEAR
|
|||||||
function _error($p_message)
|
function _error($p_message)
|
||||||
{
|
{
|
||||||
// ----- To be completed
|
// ----- To be completed
|
||||||
$this->raiseError($p_message);
|
return $this->raiseError($p_message);
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
@@ -576,7 +575,7 @@ class Archive_Tar extends PEAR
|
|||||||
function _warning($p_message)
|
function _warning($p_message)
|
||||||
{
|
{
|
||||||
// ----- To be completed
|
// ----- To be completed
|
||||||
$this->raiseError($p_message);
|
return $this->raiseError($p_message);
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
@@ -1327,7 +1326,7 @@ class Archive_Tar extends PEAR
|
|||||||
|
|
||||||
if ($v_header['filename'] == $p_filename) {
|
if ($v_header['filename'] == $p_filename) {
|
||||||
if ($v_header['typeflag'] == "5") {
|
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'].'}');
|
.'entry {'.$v_header['filename'].'}');
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
@@ -1386,7 +1385,7 @@ class Archive_Tar extends PEAR
|
|||||||
$v_listing = TRUE;
|
$v_listing = TRUE;
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
$this->_error('Invalid extract mode ('.$p_mode.')');
|
return $this->_error('Invalid extract mode ('.$p_mode.')');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1456,20 +1455,20 @@ class Archive_Tar extends PEAR
|
|||||||
if (file_exists($v_header['filename'])) {
|
if (file_exists($v_header['filename'])) {
|
||||||
if ( (@is_dir($v_header['filename']))
|
if ( (@is_dir($v_header['filename']))
|
||||||
&& ($v_header['typeflag'] == '')) {
|
&& ($v_header['typeflag'] == '')) {
|
||||||
$this->_error('File '.$v_header['filename']
|
return $this->_error('File '.$v_header['filename']
|
||||||
.' already exists as a directory');
|
.' already exists as a directory');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( ($this->_isArchive($v_header['filename']))
|
if ( ($this->_isArchive($v_header['filename']))
|
||||||
&& ($v_header['typeflag'] == "5")) {
|
&& ($v_header['typeflag'] == "5")) {
|
||||||
$this->_error('Directory '.$v_header['filename']
|
return $this->_error('Directory '.$v_header['filename']
|
||||||
.' already exists as a file');
|
.' already exists as a file');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($check_base_dir OR _PS_ROOT_DIR_ != realpath($v_header['filename']))
|
if ($check_base_dir OR _PS_ROOT_DIR_ != realpath($v_header['filename']))
|
||||||
{
|
{
|
||||||
if (!is_writeable($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');
|
.' already exists and is write protected');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1484,7 +1483,7 @@ class Archive_Tar extends PEAR
|
|||||||
= $this->_dirCheck(($v_header['typeflag'] == "5"
|
= $this->_dirCheck(($v_header['typeflag'] == "5"
|
||||||
?$v_header['filename']
|
?$v_header['filename']
|
||||||
:dirname($v_header['filename'])))) != 1) {
|
: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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1492,14 +1491,14 @@ class Archive_Tar extends PEAR
|
|||||||
if ($v_header['typeflag'] == "5") {
|
if ($v_header['typeflag'] == "5") {
|
||||||
if (!@file_exists($v_header['filename'])) {
|
if (!@file_exists($v_header['filename'])) {
|
||||||
if (!@mkdir($v_header['filename'], 0777)) {
|
if (!@mkdir($v_header['filename'], 0777)) {
|
||||||
$this->_error('Unable to create directory {'
|
return $this->_error('Unable to create directory {'
|
||||||
.$v_header['filename'].'}');
|
.$v_header['filename'].'}');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) {
|
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');
|
.'} in write binary mode');
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -1524,7 +1523,7 @@ class Archive_Tar extends PEAR
|
|||||||
// ----- Check the file size
|
// ----- Check the file size
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
if (filesize($v_header['filename']) != $v_header['size']) {
|
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 \''
|
.' does not have the correct file size \''
|
||||||
.filesize($v_header['filename'])
|
.filesize($v_header['filename'])
|
||||||
.'\' ('.$v_header['size']
|
.'\' ('.$v_header['size']
|
||||||
|
|||||||
Reference in New Issue
Block a user