Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../includes
File: class-zip.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if (!defined('ABSPATH')) die('No direct access allowed');
[2] Fix | Delete
[3] Fix | Delete
if (class_exists('ZipArchive')) :
[4] Fix | Delete
/**
[5] Fix | Delete
* We just add a last_error variable for comaptibility with our UpdraftPlus_PclZip object
[6] Fix | Delete
*/
[7] Fix | Delete
class UpdraftPlus_ZipArchive extends ZipArchive {
[8] Fix | Delete
[9] Fix | Delete
public $last_error = 'Unknown: ZipArchive does not return error messages';
[10] Fix | Delete
}
[11] Fix | Delete
endif;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* A ZipArchive compatibility layer, with behaviour sufficient for our usage of ZipArchive
[15] Fix | Delete
*/
[16] Fix | Delete
class UpdraftPlus_PclZip {
[17] Fix | Delete
[18] Fix | Delete
protected $pclzip;
[19] Fix | Delete
[20] Fix | Delete
protected $path;
[21] Fix | Delete
[22] Fix | Delete
protected $addfiles;
[23] Fix | Delete
[24] Fix | Delete
protected $adddirs;
[25] Fix | Delete
[26] Fix | Delete
private $statindex;
[27] Fix | Delete
[28] Fix | Delete
private $include_mtime = false;
[29] Fix | Delete
[30] Fix | Delete
public $last_error;
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Constructor
[34] Fix | Delete
*/
[35] Fix | Delete
public function __construct() {
[36] Fix | Delete
$this->addfiles = array();
[37] Fix | Delete
$this->adddirs = array();
[38] Fix | Delete
// Put this in a non-backed-up, writeable location, to make sure that huge temporary files aren't created and then added to the backup - and that we have somewhere writable
[39] Fix | Delete
global $updraftplus;
[40] Fix | Delete
if (!defined('PCLZIP_TEMPORARY_DIR')) define('PCLZIP_TEMPORARY_DIR', trailingslashit($updraftplus->backups_dir_location()));
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Used to include mtime in statindex (by default, not done - to save memory; probably a bit paranoid)
[45] Fix | Delete
*
[46] Fix | Delete
* @return null
[47] Fix | Delete
*/
[48] Fix | Delete
public function ud_include_mtime() {
[49] Fix | Delete
if (empty($this->include_mtime)) $this->statindex = null;
[50] Fix | Delete
$this->include_mtime = true;
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Magic function for getting an otherwise-undefined class variable
[55] Fix | Delete
*
[56] Fix | Delete
* @param String $name
[57] Fix | Delete
*
[58] Fix | Delete
* @return Boolean|Null|Integer - the value, or null if an unknown variable, or false if something goes wrong
[59] Fix | Delete
*/
[60] Fix | Delete
public function __get($name) {
[61] Fix | Delete
[62] Fix | Delete
if ('numFiles' == $name) {
[63] Fix | Delete
[64] Fix | Delete
if (empty($this->pclzip)) return false;
[65] Fix | Delete
[66] Fix | Delete
if (!empty($this->statindex)) return count($this->statindex);
[67] Fix | Delete
[68] Fix | Delete
$statindex = $this->pclzip->listContent();
[69] Fix | Delete
[70] Fix | Delete
if (empty($statindex)) {
[71] Fix | Delete
$this->statindex = array();
[72] Fix | Delete
// We return a value that is == 0, but allowing a PclZip error to be detected (PclZip returns 0 in the case of an error).
[73] Fix | Delete
if (0 === $statindex) $this->last_error = $this->pclzip->errorInfo(true);
[74] Fix | Delete
return (0 === $statindex) ? false : 0;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
// We used to exclude folders in the case of numFiles (and implemented a private alternative, numAll, that included them), because we had no use for them (we ran a loop over $statindex to build a result that excluded the folders); but that is no longer the case (Dec 2018)
[78] Fix | Delete
$this->statindex = $statindex;
[79] Fix | Delete
[80] Fix | Delete
return count($this->statindex);
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
return null;
[84] Fix | Delete
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Get stat info for a file
[89] Fix | Delete
*
[90] Fix | Delete
* @param Integer $i The index of the file
[91] Fix | Delete
*
[92] Fix | Delete
* @return Array - the stat info
[93] Fix | Delete
*/
[94] Fix | Delete
public function statIndex($i) {
[95] Fix | Delete
if (empty($this->statindex[$i])) return array('name' => null, 'size' => 0);
[96] Fix | Delete
$v = array('name' => $this->statindex[$i]['filename'], 'size' => $this->statindex[$i]['size']);
[97] Fix | Delete
if ($this->include_mtime) $v['mtime'] = $this->statindex[$i]['mtime'];
[98] Fix | Delete
return $v;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Compatibility function for WP < 3.7; taken from WP 5.2.2
[103] Fix | Delete
*
[104] Fix | Delete
* @staticvar array $encodings
[105] Fix | Delete
* @staticvar bool $overloaded
[106] Fix | Delete
*
[107] Fix | Delete
* @param bool $reset - Whether to reset the encoding back to a previously-set encoding.
[108] Fix | Delete
*/
[109] Fix | Delete
private function mbstring_binary_safe_encoding($reset = false) {
[110] Fix | Delete
[111] Fix | Delete
if (function_exists('mbstring_binary_safe_encoding')) return mbstring_binary_safe_encoding($reset);
[112] Fix | Delete
[113] Fix | Delete
static $encodings = array();
[114] Fix | Delete
static $overloaded = null;
[115] Fix | Delete
[116] Fix | Delete
if (is_null($overloaded)) {
[117] Fix | Delete
$overloaded = function_exists('mb_internal_encoding') && (ini_get('mbstring.func_overload') & 2); // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
if (false === $overloaded) {
[121] Fix | Delete
return;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
if (!$reset) {
[125] Fix | Delete
$encoding = mb_internal_encoding();
[126] Fix | Delete
array_push($encodings, $encoding);
[127] Fix | Delete
mb_internal_encoding('ISO-8859-1');
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
if ($reset && $encodings) {
[131] Fix | Delete
$encoding = array_pop($encodings);
[132] Fix | Delete
mb_internal_encoding($encoding);
[133] Fix | Delete
}
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Compatibility function for WP < 3.7
[138] Fix | Delete
*/
[139] Fix | Delete
private function reset_mbstring_encoding() {
[140] Fix | Delete
return function_exists('reset_mbstring_encoding') ? reset_mbstring_encoding() : $this->mbstring_binary_safe_encoding(true);
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* Returns the entry contents using its index. This is used only in PclZip, to get better performance (i.e. no such method exists on other zip objects, so don't call it on them). The caller must be careful not to request more than will fit into available memory.
[145] Fix | Delete
*
[146] Fix | Delete
* @see https://php.net/manual/en/ziparchive.getfromindex.php
[147] Fix | Delete
*
[148] Fix | Delete
* @param Array $indexes - List of indexes for entries
[149] Fix | Delete
*
[150] Fix | Delete
* @return Boolean|Array - Returns a keyed list (keys matching $indexes) of contents of the entry on success or FALSE on failure.
[151] Fix | Delete
*/
[152] Fix | Delete
public function updraftplus_getFromIndexBulk($indexes) {
[153] Fix | Delete
[154] Fix | Delete
$results = array();
[155] Fix | Delete
[156] Fix | Delete
// This is just for crazy people with mbstring.func_overload enabled (deprecated from PHP 7.2)
[157] Fix | Delete
$this->mbstring_binary_safe_encoding();
[158] Fix | Delete
[159] Fix | Delete
$contents = $this->pclzip->extract(PCLZIP_OPT_BY_INDEX, $indexes, PCLZIP_OPT_EXTRACT_AS_STRING);
[160] Fix | Delete
[161] Fix | Delete
$this->reset_mbstring_encoding();
[162] Fix | Delete
[163] Fix | Delete
if (0 === $contents) {
[164] Fix | Delete
$this->last_error = $this->pclzip->errorInfo(true);
[165] Fix | Delete
return false;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if (!is_array($contents)) {
[169] Fix | Delete
$this->last_error = 'PclZip::extract() did not return the expected information (1)';
[170] Fix | Delete
return false;
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
foreach ($contents as $item) {
[174] Fix | Delete
$index = $item['index'];
[175] Fix | Delete
$content = isset($item['content']) ? $item['content'] : '';
[176] Fix | Delete
$results[$index] = $content;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
return $results;
[180] Fix | Delete
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
/**
[184] Fix | Delete
* Returns the entry contents using its index
[185] Fix | Delete
*
[186] Fix | Delete
* @see https://php.net/manual/en/ziparchive.getfromindex.php
[187] Fix | Delete
*
[188] Fix | Delete
* @param Integer $index - Index of the entry
[189] Fix | Delete
* @param Integer $length - The length to be read from the entry. If 0, then the entire entry is read.
[190] Fix | Delete
* @param Integer $flags - The flags to use to open the archive.
[191] Fix | Delete
*
[192] Fix | Delete
* @return String|Boolean - Returns the contents of the entry on success or FALSE on failure.
[193] Fix | Delete
*/
[194] Fix | Delete
public function getFromIndex($index, $length = 0, $flags = 0) {
[195] Fix | Delete
[196] Fix | Delete
$contents = $this->pclzip->extract(PCLZIP_OPT_BY_INDEX, array($index), PCLZIP_OPT_EXTRACT_AS_STRING);
[197] Fix | Delete
[198] Fix | Delete
if (0 === $contents) {
[199] Fix | Delete
$this->last_error = $this->pclzip->errorInfo(true);
[200] Fix | Delete
return false;
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
// This also prevents CI complaining about an unused parameter
[204] Fix | Delete
if ($flags) {
[205] Fix | Delete
error_log("A call to UpdraftPlus_PclZip::getFromIndex() set flags=$flags, but this is not implemented");
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
if (!is_array($contents)) {
[209] Fix | Delete
$this->last_error = 'PclZip::extract() did not return the expected information (1)';
[210] Fix | Delete
return false;
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
$content = array_pop($contents);
[214] Fix | Delete
[215] Fix | Delete
if (!isset($content['content'])) {
[216] Fix | Delete
$this->last_error = 'PclZip::extract() did not return the expected information (2)';
[217] Fix | Delete
return false;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
$results = $content['content'];
[221] Fix | Delete
[222] Fix | Delete
return $length ? substr($results, 0, $length) : $results;
[223] Fix | Delete
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
/**
[227] Fix | Delete
* Open a zip file
[228] Fix | Delete
*
[229] Fix | Delete
* @param String $path - the filesystem path to the zip file
[230] Fix | Delete
* @param Integer $flags - flags for the open operation (see ZipArchive::open() - N.B. may not all be implemented)
[231] Fix | Delete
*
[232] Fix | Delete
* @return Boolean - success or failure. Failure will set self::last_error
[233] Fix | Delete
*/
[234] Fix | Delete
public function open($path, $flags = 0) {
[235] Fix | Delete
[236] Fix | Delete
if (!class_exists('PclZip')) include_once(ABSPATH.'/wp-admin/includes/class-pclzip.php');
[237] Fix | Delete
if (!class_exists('PclZip')) {
[238] Fix | Delete
$this->last_error = "No PclZip class was found";
[239] Fix | Delete
return false;
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
// Route around PHP bug (exact version with the problem not known)
[243] Fix | Delete
$ziparchive_create_match = (version_compare(PHP_VERSION, '5.2.12', '>') && defined('ZIPARCHIVE::CREATE')) ? ZIPARCHIVE::CREATE : 1;
[244] Fix | Delete
[245] Fix | Delete
if ($flags == $ziparchive_create_match && file_exists($path)) @unlink($path);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[246] Fix | Delete
[247] Fix | Delete
$this->pclzip = new PclZip($path);
[248] Fix | Delete
[249] Fix | Delete
if (empty($this->pclzip)) {
[250] Fix | Delete
$this->last_error = 'Could not get a PclZip object';
[251] Fix | Delete
return false;
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
// Make the empty directory we need to implement add_empty_dir()
[255] Fix | Delete
global $updraftplus;
[256] Fix | Delete
$updraft_dir = $updraftplus->backups_dir_location();
[257] Fix | Delete
if (!is_dir($updraft_dir.'/emptydir') && !mkdir($updraft_dir.'/emptydir')) {
[258] Fix | Delete
$this->last_error = "Could not create empty directory ($updraft_dir/emptydir)";
[259] Fix | Delete
return false;
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
$this->path = $path;
[263] Fix | Delete
[264] Fix | Delete
return true;
[265] Fix | Delete
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
/**
[269] Fix | Delete
* Do the actual write-out - it is assumed that close() is where this is done. Needs to return true/false
[270] Fix | Delete
*
[271] Fix | Delete
* @return boolean
[272] Fix | Delete
*/
[273] Fix | Delete
public function close() {
[274] Fix | Delete
[275] Fix | Delete
if (empty($this->pclzip)) {
[276] Fix | Delete
$this->last_error = 'Zip file was not opened';
[277] Fix | Delete
return false;
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
global $updraftplus;
[281] Fix | Delete
$updraft_dir = $updraftplus->backups_dir_location();
[282] Fix | Delete
[283] Fix | Delete
$activity = false;
[284] Fix | Delete
[285] Fix | Delete
// Add the empty directories
[286] Fix | Delete
foreach ($this->adddirs as $dir) {
[287] Fix | Delete
if (false == $this->pclzip->add($updraft_dir.'/emptydir', PCLZIP_OPT_REMOVE_PATH, $updraft_dir.'/emptydir', PCLZIP_OPT_ADD_PATH, $dir)) {
[288] Fix | Delete
$this->last_error = $this->pclzip->errorInfo(true);
[289] Fix | Delete
return false;
[290] Fix | Delete
}
[291] Fix | Delete
$activity = true;
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
foreach ($this->addfiles as $rdirname => $adirnames) {
[295] Fix | Delete
foreach ($adirnames as $adirname => $files) {
[296] Fix | Delete
if (false == $this->pclzip->add($files, PCLZIP_OPT_REMOVE_PATH, $rdirname, PCLZIP_OPT_ADD_PATH, $adirname)) {
[297] Fix | Delete
$this->last_error = $this->pclzip->errorInfo(true);
[298] Fix | Delete
return false;
[299] Fix | Delete
}
[300] Fix | Delete
$activity = true;
[301] Fix | Delete
}
[302] Fix | Delete
unset($this->addfiles[$rdirname]);
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
$this->pclzip = false;
[306] Fix | Delete
$this->addfiles = array();
[307] Fix | Delete
$this->adddirs = array();
[308] Fix | Delete
[309] Fix | Delete
clearstatcache();
[310] Fix | Delete
[311] Fix | Delete
if ($activity && filesize($this->path) < 50) {
[312] Fix | Delete
$this->last_error = "Write failed - unknown cause (check your file permissions)";
[313] Fix | Delete
return false;
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
return true;
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
/**
[320] Fix | Delete
* Note: basename($add_as) is irrelevant; that is, it is actually basename($file) that will be used. But these are always identical in our usage.
[321] Fix | Delete
*
[322] Fix | Delete
* @param string $file Specific file to add
[323] Fix | Delete
* @param string $add_as This is the name of the file that it is added as but it is usually the same as $file
[324] Fix | Delete
*/
[325] Fix | Delete
public function addFile($file, $add_as) {
[326] Fix | Delete
// Add the files. PclZip appears to do the whole (copy zip to temporary file, add file, move file) cycle for each file - so batch them as much as possible. We have to batch by dirname(). On a test with 1000 files of 25KB each in the same directory, this reduced the time needed on that directory from 120s to 15s (or 5s with primed caches).
[327] Fix | Delete
$rdirname = dirname($file);
[328] Fix | Delete
$adirname = dirname($add_as);
[329] Fix | Delete
$this->addfiles[$rdirname][$adirname][] = $file;
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
/**
[333] Fix | Delete
* PclZip doesn't have a direct way to do this
[334] Fix | Delete
*
[335] Fix | Delete
* @param string $dir Specific Directory to empty
[336] Fix | Delete
*/
[337] Fix | Delete
public function addEmptyDir($dir) {
[338] Fix | Delete
$this->adddirs[] = $dir;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Extract a path
[343] Fix | Delete
*
[344] Fix | Delete
* @param String $path_to_extract
[345] Fix | Delete
* @param String $path
[346] Fix | Delete
*
[347] Fix | Delete
* @see http://www.phpconcept.net/pclzip/user-guide/55
[348] Fix | Delete
*
[349] Fix | Delete
* @return Array|Integer - either an array with the extracted files or an error. N.B. "If one file extraction fail, the full extraction does not fail. The method does not return an error, but the file status is set with the error reason."
[350] Fix | Delete
*/
[351] Fix | Delete
public function extract($path_to_extract, $path) {
[352] Fix | Delete
return $this->pclzip->extract(PCLZIP_OPT_PATH, $path_to_extract, PCLZIP_OPT_BY_NAME, $path);
[353] Fix | Delete
}
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
class UpdraftPlus_BinZip extends UpdraftPlus_PclZip {
[357] Fix | Delete
[358] Fix | Delete
private $binzip;
[359] Fix | Delete
[360] Fix | Delete
/**
[361] Fix | Delete
* Class constructor
[362] Fix | Delete
*/
[363] Fix | Delete
public function __construct() {
[364] Fix | Delete
global $updraftplus_backup;
[365] Fix | Delete
$this->binzip = $updraftplus_backup->binzip;
[366] Fix | Delete
if (!is_string($this->binzip)) {
[367] Fix | Delete
$this->last_error = "No binary zip was found";
[368] Fix | Delete
return false;
[369] Fix | Delete
}
[370] Fix | Delete
return parent::__construct();
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
public function addFile($file, $add_as) {
[374] Fix | Delete
[375] Fix | Delete
global $updraftplus;
[376] Fix | Delete
// Get the directory that $add_as is relative to
[377] Fix | Delete
$base = UpdraftPlus_Manipulation_Functions::str_lreplace($add_as, '', $file);
[378] Fix | Delete
[379] Fix | Delete
if ($file == $base) {
[380] Fix | Delete
// Shouldn't happen; but see: https://bugs.php.net/bug.php?id=62119
[381] Fix | Delete
$updraftplus->log("File skipped due to unexpected name mismatch (locale: ".setlocale(LC_CTYPE, "0")."): file=$file add_as=$add_as", 'notice', false, true);
[382] Fix | Delete
} else {
[383] Fix | Delete
$rdirname = untrailingslashit($base);
[384] Fix | Delete
// Note: $file equals $rdirname/$add_as
[385] Fix | Delete
$this->addfiles[$rdirname][] = $add_as;
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
/**
[391] Fix | Delete
* The standard zip binary cannot list; so we use PclZip for that
[392] Fix | Delete
* Do the actual write-out - it is assumed that close() is where this is done. Needs to return true/false
[393] Fix | Delete
*
[394] Fix | Delete
* @return Boolean - success or failure state
[395] Fix | Delete
*/
[396] Fix | Delete
public function close() {
[397] Fix | Delete
[398] Fix | Delete
if (empty($this->pclzip)) {
[399] Fix | Delete
$this->last_error = 'Zip file was not opened';
[400] Fix | Delete
return false;
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
global $updraftplus, $updraftplus_backup;
[404] Fix | Delete
[405] Fix | Delete
// BinZip does not like zero-sized zip files
[406] Fix | Delete
if (file_exists($this->path) && 0 == filesize($this->path)) @unlink($this->path);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[407] Fix | Delete
[408] Fix | Delete
$descriptorspec = array(
[409] Fix | Delete
0 => array('pipe', 'r'),
[410] Fix | Delete
1 => array('pipe', 'w'),
[411] Fix | Delete
2 => array('pipe', 'w')
[412] Fix | Delete
);
[413] Fix | Delete
$exec = $this->binzip;
[414] Fix | Delete
if (defined('UPDRAFTPLUS_BINZIP_OPTS') && UPDRAFTPLUS_BINZIP_OPTS) $exec .= ' '.UPDRAFTPLUS_BINZIP_OPTS;
[415] Fix | Delete
$exec .= " -v -@ ".escapeshellarg($this->path);
[416] Fix | Delete
[417] Fix | Delete
$last_recorded_alive = time();
[418] Fix | Delete
$something_useful_happened = $updraftplus->something_useful_happened;
[419] Fix | Delete
$orig_size = file_exists($this->path) ? filesize($this->path) : 0;
[420] Fix | Delete
$last_size = $orig_size;
[421] Fix | Delete
clearstatcache();
[422] Fix | Delete
[423] Fix | Delete
$added_dirs_yet = false;
[424] Fix | Delete
[425] Fix | Delete
// If there are no files to add, but there are empty directories, then we need to make sure the directories actually get added
[426] Fix | Delete
if (0 == count($this->addfiles) && 0 < count($this->adddirs)) {
[427] Fix | Delete
$dir = realpath($updraftplus_backup->make_zipfile_source);
[428] Fix | Delete
$this->addfiles[$dir] = '././.';
[429] Fix | Delete
}
[430] Fix | Delete
// Loop over each destination directory name
[431] Fix | Delete
foreach ($this->addfiles as $rdirname => $files) {
[432] Fix | Delete
[433] Fix | Delete
$process = function_exists('proc_open') ? proc_open($exec, $descriptorspec, $pipes, $rdirname) : false;
[434] Fix | Delete
[435] Fix | Delete
if (!is_resource($process)) {
[436] Fix | Delete
$updraftplus->log('BinZip error: proc_open failed');
[437] Fix | Delete
$this->last_error = 'BinZip error: proc_open failed';
[438] Fix | Delete
return false;
[439] Fix | Delete
}
[440] Fix | Delete
[441] Fix | Delete
if (!$added_dirs_yet) {
[442] Fix | Delete
// Add the directories - (in fact, with binzip, non-empty directories automatically have their entries added; but it doesn't hurt to add them explicitly)
[443] Fix | Delete
foreach ($this->adddirs as $dir) {
[444] Fix | Delete
fwrite($pipes[0], $dir."/\n");
[445] Fix | Delete
}
[446] Fix | Delete
$added_dirs_yet = true;
[447] Fix | Delete
}
[448] Fix | Delete
[449] Fix | Delete
$read = array($pipes[1], $pipes[2]);
[450] Fix | Delete
$except = null;
[451] Fix | Delete
[452] Fix | Delete
if (!is_array($files) || 0 == count($files)) {
[453] Fix | Delete
fclose($pipes[0]);
[454] Fix | Delete
$write = array();
[455] Fix | Delete
} else {
[456] Fix | Delete
$write = array($pipes[0]);
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
while ((!feof($pipes[1]) || !feof($pipes[2]) || (is_array($files) && count($files)>0)) && false !== ($changes = @stream_select($read, $write, $except, 0, 200000))) {// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
[460] Fix | Delete
[461] Fix | Delete
if (is_array($write) && in_array($pipes[0], $write) && is_array($files) && count($files)>0) {
[462] Fix | Delete
$file = array_pop($files);
[463] Fix | Delete
// Send the list of files on stdin
[464] Fix | Delete
fwrite($pipes[0], $file."\n");
[465] Fix | Delete
if (0 == count($files)) fclose($pipes[0]);
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
if (is_array($read) && in_array($pipes[1], $read)) {
[469] Fix | Delete
$w = fgets($pipes[1]);
[470] Fix | Delete
// Logging all this really slows things down; use debug to mitigate
[471] Fix | Delete
if ($w && $updraftplus_backup->debug) $updraftplus->log("Output from zip: ".trim($w), 'debug');
[472] Fix | Delete
if (time() > $last_recorded_alive + 5) {
[473] Fix | Delete
UpdraftPlus_Job_Scheduler::record_still_alive();
[474] Fix | Delete
$last_recorded_alive = time();
[475] Fix | Delete
}
[476] Fix | Delete
if (file_exists($this->path)) {
[477] Fix | Delete
$new_size = @filesize($this->path);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[478] Fix | Delete
if (!$something_useful_happened && $new_size > $orig_size + 20) {
[479] Fix | Delete
UpdraftPlus_Job_Scheduler::something_useful_happened();
[480] Fix | Delete
$something_useful_happened = true;
[481] Fix | Delete
}
[482] Fix | Delete
clearstatcache();
[483] Fix | Delete
// Log when 20% bigger or at least every 50MB
[484] Fix | Delete
if ($new_size > $last_size*1.2 || $new_size > $last_size + 52428800) {
[485] Fix | Delete
$updraftplus->log(basename($this->path).sprintf(": size is now: %.2f MB", round($new_size/1048576, 1)));
[486] Fix | Delete
$last_size = $new_size;
[487] Fix | Delete
}
[488] Fix | Delete
}
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
if (is_array($read) && in_array($pipes[2], $read)) {
[492] Fix | Delete
$last_error = fgets($pipes[2]);
[493] Fix | Delete
if (!empty($last_error)) $this->last_error = rtrim($last_error);
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
// Re-set
[497] Fix | Delete
$read = array($pipes[1], $pipes[2]);
[498] Fix | Delete
$write = (is_array($files) && count($files) >0) ? array($pipes[0]) : array();
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function