Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per blog temporary dir for pclzip #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/external/odtPhpLibrary/zip/PclZipProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function open($filename)
$this->close();
}
$this->filename = $filename;
$this->pclzip = new digiPclZip($this->filename);
$this->pclzip = new digiPclZip($this->filename, $this->tmpdir);
$this->openned = true;
return true;
}
Expand Down Expand Up @@ -160,4 +160,4 @@ public function close()
}
}

?>
?>
37 changes: 16 additions & 21 deletions core/external/odtPhpLibrary/zip/pclzip/pclzip.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@
define( 'PCLZIP_ERROR_EXTERNAL', 0 );
}

// ----- Optional static temporary directory
// By default temporary files are generated in the script current
// path.
// If defined :
// - MUST BE terminated by a '/'.
// - MUST be a valid, already created directory
// Samples :
// define( 'PCLZIP_TEMPORARY_DIR', '/temp/' );
// define( 'PCLZIP_TEMPORARY_DIR', 'C:/Temp/' );
if (!defined('PCLZIP_TEMPORARY_DIR')) {
define( 'PCLZIP_TEMPORARY_DIR', '' );
}

// ----- Optional threshold ratio for use of temporary files
// Pclzip sense the size of the file to add/extract and decide to
// use or not temporary file. The algorythm is looking for
Expand Down Expand Up @@ -192,6 +179,9 @@ class digiPclZip
// ----- Filename of the zip file
var $zipname = '';

// ----- Temporary directory
var $tmpdir = './';

// ----- File descriptor of the zip file
var $zip_fd = 0;

Expand All @@ -212,7 +202,7 @@ class digiPclZip
// Note that no real action is taken, if the archive does not exist it is not
// created. Use create() for that.
// --------------------------------------------------------------------------------
function __construct($p_zipname)
function __construct($p_zipname, $p_tmpdir = './')
{

// ----- Tests the zlib
Expand All @@ -223,6 +213,11 @@ function __construct($p_zipname)

// ----- Set the attributes
$this->zipname = $p_zipname;
// support for legacy configuration
$p_tmpdir = ( defined('PCLZIP_TEMPORARY_DIR') ? PCLZIP_TEMPORARY_DIR : $p_tmpdir );
if (substr($p_tmpdir, -1) != '/')
$p_tmpdir .= '/';
$this->tmpdir = $p_tmpdir;
$this->zip_fd = 0;
$this->magic_quotes_status = -1;

Expand Down Expand Up @@ -1243,7 +1238,7 @@ function merge($p_archive_to_add)
{

// ----- Create a temporary archive
$v_object_archive = new digiPclZip($p_archive_to_add);
$v_object_archive = new digiPclZip($p_archive_to_add, $this->tmpdir);

// ----- Merge the archive
$v_result = $this->privMerge($v_object_archive);
Expand Down Expand Up @@ -2198,7 +2193,7 @@ function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
@rewind($this->zip_fd);

// ----- Creates a temporay file
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
$v_zip_temp_name = $this->tmpdir.uniqid('pclzip-').'.tmp';

// ----- Open the temporary file in write mode
if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
Expand Down Expand Up @@ -2811,7 +2806,7 @@ function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
}

// ----- Creates a compressed temporary file
$v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
$v_gzip_temp_name = $this->tmpdir.uniqid('pclzip-').'.gz';
if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
fclose($v_file);
digiPclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
Expand Down Expand Up @@ -3969,7 +3964,7 @@ function privExtractFileUsingTempFile(&$p_entry, &$p_options)
$v_result=1;

// ----- Creates a temporary file
$v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
$v_gzip_temp_name = $this->tmpdir.uniqid('pclzip-').'.gz';
if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
fclose($v_file);
digiPclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
Expand Down Expand Up @@ -4828,10 +4823,10 @@ function privDeleteByRule(&$p_result_list, &$p_options)
if ($v_nb_extracted > 0) {

// ----- Creates a temporay file
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
$v_zip_temp_name = $this->tmpdir.uniqid('pclzip-').'.tmp';

// ----- Creates a temporary zip archive
$v_temp_zip = new digiPclZip($v_zip_temp_name);
$v_temp_zip = new digiPclZip($v_zip_temp_name, $this->tmpdir);

// ----- Open the temporary zip file in write mode
if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
Expand Down Expand Up @@ -5113,7 +5108,7 @@ function privMerge(&$p_archive_to_add)
@rewind($p_archive_to_add->zip_fd);

// ----- Creates a temporay file
$v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
$v_zip_temp_name = $this->tmpdir.uniqid('pclzip-').'.tmp';

// ----- Open the temporary file in write mode
if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
Expand Down