public function ArchiveTar::_writeHeader in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Archiver/ArchiveTar.php \Drupal\Core\Archiver\ArchiveTar::_writeHeader()
Parameters
string $p_filename:
string $p_stored_filename:
Return value
bool
1 call to ArchiveTar::_writeHeader()
- ArchiveTar::_addFile in core/
lib/ Drupal/ Core/ Archiver/ ArchiveTar.php
File
- core/
lib/ Drupal/ Core/ Archiver/ ArchiveTar.php, line 1389
Class
Namespace
Drupal\Core\ArchiverCode
public function _writeHeader($p_filename, $p_stored_filename) {
if ($p_stored_filename == '') {
$p_stored_filename = $p_filename;
}
$v_reduce_filename = $this
->_pathReduction($p_stored_filename);
if (strlen($v_reduce_filename) > 99) {
if (!$this
->_writeLongHeader($v_reduce_filename)) {
return false;
}
}
$v_info = lstat($p_filename);
$v_uid = sprintf("%07s", DecOct($v_info[4]));
$v_gid = sprintf("%07s", DecOct($v_info[5]));
$v_perms = sprintf("%07s", DecOct($v_info['mode'] & 0777));
$v_mtime = sprintf("%011s", DecOct($v_info['mtime']));
$v_linkname = '';
if (@is_link($p_filename)) {
$v_typeflag = '2';
$v_linkname = readlink($p_filename);
$v_size = sprintf("%011s", DecOct(0));
}
elseif (@is_dir($p_filename)) {
$v_typeflag = "5";
$v_size = sprintf("%011s", DecOct(0));
}
else {
$v_typeflag = '0';
clearstatcache();
$v_size = sprintf("%011s", DecOct($v_info['size']));
}
$v_magic = 'ustar ';
$v_version = ' ';
if (function_exists('posix_getpwuid')) {
$userinfo = posix_getpwuid($v_info[4]);
$groupinfo = posix_getgrgid($v_info[5]);
$v_uname = $userinfo['name'];
$v_gname = $groupinfo['name'];
}
else {
$v_uname = '';
$v_gname = '';
}
$v_devmajor = '';
$v_devminor = '';
$v_prefix = '';
$v_binary_data_first = pack("a100a8a8a8a12a12", $v_reduce_filename, $v_perms, $v_uid, $v_gid, $v_size, $v_mtime);
$v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", $v_typeflag, $v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix, '');
// ----- Calculate the checksum
$v_checksum = 0;
// ..... First part of the header
for ($i = 0; $i < 148; $i++) {
$v_checksum += ord(substr($v_binary_data_first, $i, 1));
}
// ..... Ignore the checksum value and replace it by ' ' (space)
for ($i = 148; $i < 156; $i++) {
$v_checksum += ord(' ');
}
// ..... Last part of the header
for ($i = 156, $j = 0; $i < 512; $i++, $j++) {
$v_checksum += ord(substr($v_binary_data_last, $j, 1));
}
// ----- Write the first 148 bytes of the header in the archive
$this
->_writeBlock($v_binary_data_first, 148);
// ----- Write the calculated checksum
$v_checksum = sprintf("%06s ", DecOct($v_checksum));
$v_binary_data = pack("a8", $v_checksum);
$this
->_writeBlock($v_binary_data, 8);
// ----- Write the last 356 bytes of the header in the archive
$this
->_writeBlock($v_binary_data_last, 356);
return true;
}