- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/backup.php
- Класс: CTar
- Вызов: CTar::readHeader
function readHeader($Long = false)
{
$str = '';
while(trim($str) == '')
{
if (!($l = strlen($str = $this->readBlock($bIgnoreOpenNextError = true))))
return 0; // finish
}
if (!$Long)
$this->BlockHeader = $this->Block - 1;
if ($l != 512)
return $this->Error('Wrong block size: '.strlen($str).' (block '.$this->Block.')');
$data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix", $str);
$chk = trim($data['devmajor'].$data['devminor']);
if (!is_numeric(trim($data['checksum'])) || !empty($chk))
{
return $this->Error('Archive is corrupted, wrong block: '.($this->Block-1).', file: '.$this->file.', md5sum: '.md5_file($this->file));
}
$header['filename'] = trim(trim($data['prefix'], "x00").'/'.trim($data['filename'], "x00"),'/');
$header['mode'] = OctDec($data['mode']);
$header['uid'] = OctDec($data['uid']);
$header['gid'] = OctDec($data['gid']);
$header['size'] = OctDec($data['size']);
$header['mtime'] = OctDec($data['mtime']);
$header['type'] = trim($data['type'], "x00");
// $header['link'] = $data['link'];
if (strpos($header['filename'],'./') === 0)
$header['filename'] = substr($header['filename'], 2);
if ($header['type']=='L') // Long header
{
$filename = '';
$n = ceil($header['size']/512);
for ($i = 0; $i < $n; $i++)
$filename .= $this->readBlock();
if (!is_array($header = $this->readHeader($Long = true)))
return $this->Error('Wrong long header, block: '.$this->Block);
$header['filename'] = substr($filename, 0, strpos($filename, chr(0)));
}
if (strpos($header['filename'], '/') === 0) // trailing slash
$header['type'] = 5; // Directory
if ($header['type']=='5')
$header['size'] = '';
if ($header['filename']=='')
return $this->Error('Filename is empty, wrong block: '.($this->Block-1));
if (!$this->checkCRC($str, $data))
return $this->Error('Checksum error on file: '.$header['filename']);
$this->header = $header;
return $header;
}