Skip to content

PAX Extract file fix Pull#2 #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions src/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ public static function fromPath($path, $as = '')
}

/**
* @return int
* @return int the filesize. always 0 for directories
*/
public function getSize()
{
if($this->isdir) return 0;
return $this->size;
}

Expand Down Expand Up @@ -340,4 +341,4 @@ public function match($include = '', $exclude = '')

class FileInfoException extends \Exception
{
}
}
9 changes: 8 additions & 1 deletion src/Tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,19 @@ protected function parseHeader($block)
// Handle Long-Link entries from GNU Tar
if ($return['typeflag'] == 'L') {
// following data block(s) is the filename
$filename = trim($this->readbytes(ceil($header['size'] / 512) * 512));
$filename = trim($this->readbytes(ceil($return['size'] / 512) * 512));
// next block is the real header
$block = $this->readbytes(512);
$return = $this->parseHeader($block);

// overwrite the filename
$return['filename'] = $filename;
}elseif ($return['typeflag'] == 'x') {
// following data block(s) is the filename
$filename = trim($this->readbytes(ceil($return['size'] / 512) * 512));
// next block is the real header
$block = $this->readbytes(512);
$return = $this->parseHeader($block);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. You are not using the data read from x header. $filename is never used. You basically just read and ignore the x header.

Since your tests work, I assume the original header already contains the proper UTF-8 filename? Would a very long UTF-8 filename have an x and an L header?

}

return $return;
Expand Down
31 changes: 31 additions & 0 deletions tests/tar.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,38 @@ public function test_dogfood()
unlink($archive);
}
}

/**
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation seem wrong again. please make sure you use 4 spaces for indentation. not tabs!

* Extract the prebuilt tar files with PAX headers
*/
public function test_tarpaxextract()
{
$dir = dirname(__FILE__).'/tar';
$out = sys_get_temp_dir().'/dwtartest'.md5(time());

foreach ($this->extensions as $ext) {
$tar = new Tar();
$file = "$dir/pax_test.$ext";

$tar->open($file);
$list = $tar->extract($out);

clearstatcache();

$this->assertFileExists($out.'/4слайд-1.jpg', "Extracted $file");
$this->assertEquals(15251, filesize($out.'/4слайд-1.jpg'), "Extracted $file");

$this->assertFileExists($out.'/4слайд-2.jpg', "Extracted $file");
$this->assertEquals(16671, filesize($out.'/4слайд-2.jpg'), "Extracted $file");

$this->assertFileExists($out.'/4слайд.jpg', "Extracted $file");
$this->assertEquals(214949, filesize($out.'/4слайд.jpg'), "Extracted $file");


self::rdelete($out);
}
}

/**
* Extract the prebuilt tar files
*/
Expand Down
Binary file added tests/tar/pax_test.tar
Binary file not shown.
Binary file added tests/tar/pax_test.tar.bz2
Binary file not shown.
Binary file added tests/tar/pax_test.tar.gz
Binary file not shown.
Binary file added tests/tar/pax_test.tbz
Binary file not shown.
Binary file added tests/tar/pax_test.tgz
Binary file not shown.