Merge pull request #20164 from Hystepik/develop#3
NEW dol_uncompress() supports extensions (.gz, .bz2, .zstd). Only .zip was supported before.
This commit is contained in:
commit
000ab8ce5f
@ -2083,8 +2083,12 @@ function dol_compress_file($inputfile, $outputfile, $mode = "gz", &$errorstring
|
|||||||
*/
|
*/
|
||||||
function dol_uncompress($inputfile, $outputdir)
|
function dol_uncompress($inputfile, $outputdir)
|
||||||
{
|
{
|
||||||
global $conf, $langs;
|
global $conf, $langs, $db;
|
||||||
|
|
||||||
|
$fileinfo = pathinfo($inputfile);
|
||||||
|
$fileinfo["extension"] = strtolower($fileinfo["extension"]);
|
||||||
|
|
||||||
|
if ($fileinfo["extension"] == "zip") {
|
||||||
if (defined('ODTPHP_PATHTOPCLZIP') && empty($conf->global->MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS)) {
|
if (defined('ODTPHP_PATHTOPCLZIP') && empty($conf->global->MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS)) {
|
||||||
dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.", so we use Pclzip to unzip into ".$outputdir);
|
dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.", so we use Pclzip to unzip into ".$outputdir);
|
||||||
include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
|
include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php';
|
||||||
@ -2142,6 +2146,39 @@ function dol_uncompress($inputfile, $outputdir)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return array('error'=>'ErrNoZipEngine');
|
return array('error'=>'ErrNoZipEngine');
|
||||||
|
} elseif (in_array($fileinfo["extension"], array('gz', 'bz2', 'zst'))) {
|
||||||
|
include_once DOL_DOCUMENT_ROOT."/core/class/utils.class.php";
|
||||||
|
$utils = new Utils($db);
|
||||||
|
|
||||||
|
$extension = strtolower(pathinfo($fileinfo["filename"], PATHINFO_EXTENSION));
|
||||||
|
if ($extension == "tar") {
|
||||||
|
$cmd = 'tar -C '.escapeshellcmd(dol_sanitizePathName($outputdir)).' -xvf '.escapeshellcmd(dol_sanitizePathName($fileinfo["dirname"]).'/'.dol_sanitizeFileName($fileinfo["basename"]));
|
||||||
|
$resarray = $utils->executeCLI($cmd, $outputdir);
|
||||||
|
} else {
|
||||||
|
$program = "";
|
||||||
|
if ($fileinfo["extension"] == "gz") {
|
||||||
|
$program = 'gzip';
|
||||||
|
} elseif ($fileinfo["extension"] == "bz2") {
|
||||||
|
$program = 'bzip2';
|
||||||
|
} elseif ($fileinfo["extension"] == "zst") {
|
||||||
|
$program = 'zstd';
|
||||||
|
} else {
|
||||||
|
return array('error'=>'ErrFileExtension');
|
||||||
|
}
|
||||||
|
$cmd = $program.' -dc '.escapeshellcmd(dol_sanitizePathName($fileinfo["dirname"]).'/'.dol_sanitizeFileName($fileinfo["basename"]));
|
||||||
|
$outputfilename = escapeshellcmd(dol_sanitizePathName($outputdir).'/'.dol_sanitizeFileName($fileinfo["filename"]));
|
||||||
|
$resarray = $utils->executeCLI($cmd, $outputfilename, 0, $outputfilename);
|
||||||
|
if ($resarray["output"] == 2) {
|
||||||
|
$resarray["error"] = "ErrFilePermOrFileNotFound";
|
||||||
|
}
|
||||||
|
if ($resarray["output"] == 1) {
|
||||||
|
$resarray["error"] = "Error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $resarray["output"] != 0 ? $resarray["error"] : array();
|
||||||
|
}
|
||||||
|
|
||||||
|
return array('error'=>'ErrFileExtension');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user