• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/backup.php
  • Класс: CTar
  • Вызов: CTar::openWrite
function openWrite($file)
{
	if (!isset($this->gzip) && (substr($file,-3)=='.gz' || substr($file,-4)=='.tgz'))
		$this->gzip = true;

	$this->BufferSize = 51200;

	if (intval($this->ArchiveSizeLimit) <= 0)
		$this->ArchiveSizeLimit = 1024 * 1024 * 1024; // 1Gb


	$this->Block = 0;
	while(file_exists($file1 = $this->getNextName($file))) // находим последний архив
	{
		$this->Block += ceil($this->ArchiveSizeLimit / 512);
		$file = $file1;
	}

	$size = 0;
	if (file_exists($file) && !$size = $this->getDataSize($file))
	{
		return $this->Error('Can't get data size: '.$file);
	}

	$this->Block += $size / 512;
	if ($size >= $this->ArchiveSizeLimit) // если последний архив полон
	{
		$file = $file1;
		$size = 0;
	}
	$this->ArchiveSizeCurrent = $size;

	$res = $this->open($file, 'a');
	if ($res && $this->Block == 0 && ($key = $this->getEncryptKey())) // запишем служебный заголовок для зашифрованного архива
	{
		$ver = function_exists('openssl_encrypt') ? '1.2' : '1.1';
		$enc = pack("a100a90a10a56",md5(uniqid(rand(), true)), self::BX_SIGNATURE, $ver, "");
		$enc .= $this->encrypt($enc, $key);
		if (!($this->gzip ? gzwrite($this->res, $enc) : fwrite($this->res, $enc)))
		{
			return $this->Error('Error writing to file');
		}
		$this->Block = 1;
		$this->ArchiveSizeCurrent = 512;
	}
	return $res;
}