- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/backup.php
- Класс: CTar
- Вызов: CTar::extractFile
function extractFile()
{
if ($this->header === null)
{
if(($header = $this->readHeader()) === false || $header === 0 || $header === true)
{
if ($header === true && $this->SkipFile() === false)
return false;
return $header;
}
$this->lastPath = $f = $this->path.'/'.$header['filename'];
if ($this->ReadBlockCurrent == 0)
{
if ($header['type']==5) // dir
{
if(!file_exists($f) && !self::xmkdir($f))
return $this->ErrorAndSkip('Can't create folder: '.$f);
//chmod($f, $header['mode']);
}
else // file
{
if (!self::xmkdir($dirname = dirname($f)))
return $this->ErrorAndSkip('Can't create folder: '.$dirname);
elseif (($rs = fopen($f, 'wb'))===false)
return $this->ErrorAndSkip('Can't create file: '.$f);
}
}
else
return $this->Skip($this->ReadBlockCurrent);
}
else // файл уже частично распакован, продолжаем на том же хите
{
$header = $this->header;
$this->lastPath = $f = $this->path.'/'.$header['filename'];
}
if ($header['type'] != 5) // пишем контент в файл
{
if (!$rs)
{
if (($rs = fopen($f, 'ab'))===false)
return $this->ErrorAndSkip('Can't open file: '.$f);
}
$i = 0;
$FileBlockCount = ceil($header['size'] / 512);
while(++$this->ReadBlockCurrent <= $FileBlockCount && ($contents = $this->readBlock()))
{
if ($this->ReadBlockCurrent == $FileBlockCount && ($chunk = $header['size'] % 512))
$contents = substr($contents, 0, $chunk);
fwrite($rs,$contents);
if ($this->ReadBlockMax && ++$i >= $this->ReadBlockMax)
{
fclose($rs);
return true; // Break
}
}
fclose($rs);
if (($s = filesize($f)) != $header['size'])
return $this->Error('File size is wrong: '.$header['filename'].' (real: '.$s.' expected: '.$header['size'].')');
//chmod($f, $header['mode']);
}
if ($this->header['type']==5)
$this->DirCount++;
else
$this->FileCount++;
$this->debug_header = $this->header;
$this->BlockHeader = $this->Block;
$this->ReadBlockCurrent = 0;
$this->header = null;
return true;
}