- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/backup.php
- Класс: CTar
- Вызов: CTar::addFile
function addFile($f)
{
$f = str_replace('\', '/', $f);
$path = $this->prefix.substr($f, strlen($this->path) + 1);
if ($path == '')
return true;
if (strlen($path) > 512)
return $this->Error('Path is too long: '.$path);
if (is_link($f) && !file_exists($f)) // broken link
return true;
if (!$ar = $this->getFileInfo($f))
return false;
if ($this->ReadBlockCurrent == 0) // read from start
{
$this->ReadFileSize = $ar['size'];
if (strlen($path) > 100) // Long header
{
$ar0 = $ar;
$ar0['type'] = 'L';
$ar0['filename'] = '././@LongLink';
$ar0['size'] = strlen($path);
if (!$this->writeHeader($ar0))
return $this->Error('Can't write header to file: '.$this->file);
if (!$this->writeBlock(pack("a512",$path)))
return $this->Error('Can't write to file: '.$this->file);
$ar['filename'] = substr($path,0,100);
}
if (!$this->writeHeader($ar))
return $this->Error('Can't write header to file: '.$this->file);
}
if ($ar['type'] == 0 && $ar['size'] > 0) // File
{
if (!($rs = fopen($f, 'rb')))
return $this->Error('Error opening file: '.$f);
if ($this->ReadBlockCurrent)
fseek($rs, $this->ReadBlockCurrent * 512);
$i = 0;
while(!feof($rs) && ('' !== $str = fread($rs,512)))
{
if ($this->ReadFileSize && $this->ReadBlockCurrent * 512 > $this->ReadFileSize)
return $this->Error('File has changed while reading: '.$f);
$this->ReadBlockCurrent++;
if (feof($rs))
$str = pack("a512", $str);
elseif (strlen($str) != 512)
return $this->Error('Error reading from file: '.$f);
if (!$this->writeBlock($str))
{
fclose($rs);
return $this->Error('Error processing file: '.$f);
}
if ($this->ReadBlockMax && ++$i >= $this->ReadBlockMax)
{
fclose($rs);
return true;
}
}
fclose($rs);
$this->ReadBlockCurrent = 0;
}
return true;
}