Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Tar.php

function Archive_Tar::_pathReduction

Compress path by changing for example "/dir/foo/../bar" to "/dir/bar", rand emove double slashes.

Parameters

string $p_dir path to reduce:

Return value

string reduced path

3 calls to Archive_Tar::_pathReduction()
Archive_Tar::_addFile in vendor/pear/archive_tar/Archive/Tar.php
Archive_Tar::_writeHeader in vendor/pear/archive_tar/Archive/Tar.php
Archive_Tar::_writeHeaderBlock in vendor/pear/archive_tar/Archive/Tar.php

File

vendor/pear/archive_tar/Archive/Tar.php, line 2467

Class

Archive_Tar
Creates a (compressed) Tar archive

Code

private function _pathReduction($p_dir) {
    $v_result = '';
    // ----- Look for not empty path
    if ($p_dir != '') {
        // ----- Explode path by directory names
        $v_list = explode('/', $p_dir);
        // ----- Study directories from last to first
        for ($i = sizeof($v_list) - 1; $i >= 0; $i--) {
            // ----- Look for current path
            if ($v_list[$i] == ".") {
                // ----- Ignore this directory
                // Should be the first $i=0, but no check is done
            }
            else {
                if ($v_list[$i] == "..") {
                    // ----- Ignore it and ignore the $i-1
                    $i--;
                }
                else {
                    if ($v_list[$i] == '' && $i != sizeof($v_list) - 1 && $i != 0) {
                        // ----- Ignore only the double '//' in path,
                        // but not the first and last /
                    }
                    else {
                        $v_result = $v_list[$i] . ($i != sizeof($v_list) - 1 ? '/' . $v_result : '');
                    }
                }
            }
        }
    }
    if (defined('OS_WINDOWS') && OS_WINDOWS) {
        $v_result = strtr($v_result, '\\', '/');
    }
    return $v_result;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal