- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/tar_gz.php
- Класс: CArchiver
- Вызов: CArchiver::_addFile
private function _addFile($strFilename, $strAddPath, $strRemovePath)
{
if (!$this->_dFile)
{
$this->_arErrors[] = ["ERR_DFILE", GetMessage("MAIN_ARCHIVE_ERR_DFILE")];
return false;
}
if ($strFilename == '')
{
$this->_arErrors[] = ["NO_FILENAME", GetMessage("MAIN_ARCHIVE_NO_FILENAME")];
return false;
}
$strFilename = str_replace("\", "/", $strFilename);
$strFilename_stored = $strFilename;
if (strcmp($strFilename, $strRemovePath) == 0)
{
return true;
}
if ($strRemovePath <> '')
{
if (mb_substr($strRemovePath, -1) != '/')
{
$strRemovePath .= '/';
}
if (mb_substr($strFilename, 0, mb_strlen($strRemovePath)) == $strRemovePath)
{
$strFilename_stored = mb_substr($strFilename, mb_strlen($strRemovePath));
}
}
if ($strAddPath <> '')
{
if (mb_substr($strAddPath, -1) == '/')
{
$strFilename_stored = $strAddPath . $strFilename_stored;
}
else
{
$strFilename_stored = $strAddPath . '/' . $strFilename_stored;
}
}
$strFilename_stored = $this->_normalizePath($strFilename_stored);
if (is_file($strFilename))
{
if (($dfile = @fopen($strFilename, "rb")) == 0)
{
$this->_arErrors[] = ["ERR_OPEN", str_replace("#FILE_NAME#", removeDocRoot($strFilename), GetMessage("MAIN_ARCHIVE_ERR_OPEN"))];
return true;
}
$istime = ((microtime(true) - $this->start_time) < round($this->max_exec_time)) || !$this->stepped;
if ($istime)
{
if (($this->file_pos == 0))
{
if (!$this->_writeHeader($strFilename, $strFilename_stored))
{
return false;
}
}
if (($this->file_pos > 0) && $this->stepped)
{
if ($this->_bCompress)
{
@gzseek($dfile, $this->file_pos);
}
else
{
@fseek($dfile, $this->file_pos);
}
}
while ($istime && ($v_buffer = fread($dfile, 512)) != '')
{
$v_binary_data = pack("a512", "$v_buffer");
$this->_writeBlock($v_binary_data);
$istime = ((microtime(true) - $this->start_time) < round($this->max_exec_time)) || !$this->stepped;
}
}
if ($istime && $this->stepped)
{
$this->file_pos = 0;
}
elseif ($this->stepped)
{
if ($this->_bCompress)
{
$this->file_pos = @gztell($dfile);
}
else
{
$this->file_pos = @ftell($dfile);
}
}
fclose($dfile);
}
elseif (!$this->_writeHeader($strFilename, $strFilename_stored))
{
return false;
}
return true;
}