You are here

function TarArchiveWriter::writeLongHeader in Backup and Migrate 8.4

Parameters

$new_path:

Return value

bool

1 call to TarArchiveWriter::writeLongHeader()
TarArchiveWriter::writeHeader in lib/backup_migrate_core/src/Service/TarArchiveWriter.php

File

lib/backup_migrate_core/src/Service/TarArchiveWriter.php, line 135

Class

TarArchiveWriter
Class TarArchiver.

Namespace

BackupMigrate\Core\Service

Code

function writeLongHeader($new_path) {
  $v_size = sprintf("%11s ", decoct(strlen($new_path)));
  $v_typeflag = 'L';
  $v_linkname = '';
  $v_magic = '';
  $v_version = '';
  $v_uname = '';
  $v_gname = '';
  $v_devmajor = '';
  $v_devminor = '';
  $v_prefix = '';
  $v_binary_data_first = pack("a100a8a8a8a12A12", '././@LongLink', 0, 0, 0, $v_size, 0);
  $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->archive
    ->write($v_binary_data_first, 148);

  // ----- Write the calculated checksum.
  $v_checksum = sprintf("%6s ", decoct($v_checksum));
  $v_binary_data = pack("a8", $v_checksum);
  $this->archive
    ->write($v_binary_data, 8);

  // ----- Write the last 356 bytes of the header in the archive.
  $this->archive
    ->write($v_binary_data_last, 356);

  // ----- Write the filename as content of the block.
  $i = 0;
  while (($v_buffer = substr($new_path, $i++ * 512, 512)) != '') {
    $v_binary_data = pack("a512", "{$v_buffer}");
    $this->archive
      ->write($v_binary_data);
  }
}