You are here

public function ArchiveTar::_addFile in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Archiver/ArchiveTar.php \Drupal\Core\Archiver\ArchiveTar::_addFile()

Parameters

string $p_filename:

mixed $p_header:

string $p_add_dir:

string $p_remove_dir:

null $v_stored_filename:

Return value

bool

1 call to ArchiveTar::_addFile()
ArchiveTar::_addList in core/lib/Drupal/Core/Archiver/ArchiveTar.php

File

core/lib/Drupal/Core/Archiver/ArchiveTar.php, line 1258

Class

ArchiveTar

Namespace

Drupal\Core\Archiver

Code

public function _addFile($p_filename, &$p_header, $p_add_dir, $p_remove_dir, $v_stored_filename = null) {
  if (!$this->_file) {
    $this
      ->_error('Invalid file descriptor');
    return false;
  }
  if ($p_filename == '') {
    $this
      ->_error('Invalid file name');
    return false;
  }
  if (is_null($v_stored_filename)) {

    // ----- Calculate the stored filename
    $p_filename = $this
      ->_translateWinPath($p_filename, false);
    $v_stored_filename = $p_filename;
    if (strcmp($p_filename, $p_remove_dir) == 0) {
      return true;
    }
    if ($p_remove_dir != '') {
      if (substr($p_remove_dir, -1) != '/') {
        $p_remove_dir .= '/';
      }
      if (substr($p_filename, 0, strlen($p_remove_dir)) == $p_remove_dir) {
        $v_stored_filename = substr($p_filename, strlen($p_remove_dir));
      }
    }
    $v_stored_filename = $this
      ->_translateWinPath($v_stored_filename);
    if ($p_add_dir != '') {
      if (substr($p_add_dir, -1) == '/') {
        $v_stored_filename = $p_add_dir . $v_stored_filename;
      }
      else {
        $v_stored_filename = $p_add_dir . '/' . $v_stored_filename;
      }
    }
    $v_stored_filename = $this
      ->_pathReduction($v_stored_filename);
  }
  if ($this
    ->_isArchive($p_filename)) {
    if (($v_file = @fopen($p_filename, "rb")) == 0) {
      $this
        ->_warning("Unable to open file '" . $p_filename . "' in binary read mode");
      return true;
    }
    if (!$this
      ->_writeHeader($p_filename, $v_stored_filename)) {
      return false;
    }
    while (($v_buffer = fread($v_file, 512)) != '') {
      $v_binary_data = pack("a512", "{$v_buffer}");
      $this
        ->_writeBlock($v_binary_data);
    }
    fclose($v_file);
  }
  else {

    // ----- Only header for dir
    if (!$this
      ->_writeHeader($p_filename, $v_stored_filename)) {
      return false;
    }
  }
  return true;
}