PharData class fails when tar contents has relative paths
Asked Answered
A

0

2

I'm having trouble with using Phar to access gzipped tar files.

Here's my test code:

<?php

function r($a) {
  print " has " . count($a) . " files:\n";
  foreach (new RecursiveIteratorIterator($a) as $path => $fileinfo) {
    print "  " . $path . "\n";
  }
}

print  "\n1.tgz";
r(new PharData('1.tgz'));
print  "\n2.tgz";
r(new PharData('2.tgz'));

print  "\norig dir:";
chdir('orig-dir');
r(new RecursiveDirectoryIterator('./'));

Here's the fixture:

mkdir -p orig-dir/subdir; touch orig-dir/{a,b,subdir/c}; cd orig-dir
tar czf ../1.tgz *
tar czf ../2.tgz ./
cd ../
# put the test code file here and run with php test-code.php

Here's the output:

1.tgz has 4 files:
  phar:///tmp/t/1.tgz/a
  phar:///tmp/t/1.tgz/b
  phar:///tmp/t/1.tgz/subdir/c

2.tgz has 5 files:

orig dir: has 1 files:
  ./b
  ./.
  ./subdir/.
  ./subdir/c
  ./subdir/..
  ./..
  ./a

Q. Why is phar having such difficulties with the 2nd tar file? (I'm on php 5.6)

Attemper answered 12/5, 2016 at 14:18 Comment(1)
Sorry you're having these issues... I am too. Looks like I may not be able to use PharData for my particular use case :(Aegis

© 2022 - 2024 — McMap. All rights reserved.