--- /dev/null
+--TEST--
+Phar: tar-based phar, valid 1
+--SKIPIF--
+<?php if (!extension_loaded('phar')) die('skip'); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+include dirname(__FILE__) . '/tarmaker.php.inc';
+$fname = dirname(__FILE__) . '/tar_003.phar';
+$pname = 'phar://' . $fname;
+
+$a = new tarmaker($fname, 'none');
+$a->init();
+$a->addFile('tar_003.phpt', $g = fopen(__FILE__, 'r'));
+$a->addFile('internal/file/here', "hi there!\n");
+$a->mkDir('internal/dir');
+$a->mkDir('dir');
+$a->close();
+fclose($g);
+
+echo file_get_contents($pname . '/internal/file/here');
+$a = opendir($pname . '/');
+while (false !== ($v = readdir($a))) {
+ echo (is_file($pname . $v) ? "file\n" : "dir\n");
+ echo $v . "\n";
+}
+closedir($a);
+
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tar_003.phar');
+?>
+--EXPECT--
+hi there!
+dir
+dir
+dir
+internal
+file
+tar_003.phpt
+===DONE===
\ No newline at end of file
* @param string relative path within the package
* @param string|resource file contents or open file handle
*/
- function addFile($path, $fileOrStream)
+ function addFile($path, $fileOrStream, $stat = null)
{
clearstatcache();
- if (is_resource($fileOrStream)) {
- $stat = fstat($fileOrStream);
- } else {
- $stat = array(
- 'mode' => 0x8000 + 0644,
- 'uid' => 0,
- 'gid' => 0,
- 'size' => strlen($fileOrStream),
- 'mtime' => time(),
- );
+ if ($stat === null) {
+ if (is_resource($fileOrStream)) {
+ $stat = fstat($fileOrStream);
+ } else {
+ $stat = array(
+ 'mode' => 0x8000 + 0644,
+ 'uid' => 0,
+ 'gid' => 0,
+ 'size' => strlen($fileOrStream),
+ 'mtime' => time(),
+ );
+ }
}
$link = null;
/**
* Create an internal directory, creating parent directories as needed
*
- * This is a no-op for the tar creator
* @param string $dir
*/
function mkdir($dir)
{
+ $this->addFile($dir, "", array(
+ 'mode' => 0x4000 + 0644,
+ 'uid' => 0,
+ 'gid' => 0,
+ 'size' => 0,
+ 'mtime' => time(),
+ ));
}
/**