--- /dev/null
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 4 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2003 The PHP Group |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 3.0 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available through the world-wide-web at the following url: |
+ | http://www.php.net/license/3_0.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | license@php.net so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: |
+ +----------------------------------------------------------------------+
+
+ $Id$
+*/
+
+#ifndef PHPMIMEMAGIC_H
+#define PHPMIMEMAGIC_H
+
+#define MIME_MAGIC_DEBUG 0
+
+#define MIME_BINARY_UNKNOWN "application/octet-stream"
+#define MIME_TEXT_UNKNOWN "text/plain"
+
+#define MAXMIMESTRING 256
+
+#define MIME_MAGIC_OK 0
+#define MIME_MAGIC_DECLINED -1
+#define MIME_MAGIC_DONE -2
+#define MIME_MAGIC_ERROR -3
+
+#define DIR_MAGIC_TYPE "httpd/unix-directory"
+
+/* HOWMANY must be at least 4096 to make gzip -dcq work */
+#define HOWMANY 4096
+/* SMALL_HOWMANY limits how much work we do to figure out text files */
+#define SMALL_HOWMANY 1024
+#define MAXDESC 50 /* max leng of text description */
+#define MAXstring 64 /* max leng of "string" types */
+
+struct magic {
+ struct magic *next; /* link to next entry */
+ int lineno; /* line number from magic file */
+
+ short flag;
+#define INDIR 1 /* if '>(...)' appears, */
+#define UNSIGNED 2 /* comparison is unsigned */
+ short cont_level; /* level of ">" */
+ struct {
+ char type; /* byte short long */
+ long offset; /* offset from indirection */
+ } in;
+ long offset; /* offset to magic number */
+ unsigned char reln; /* relation (0=eq, '>'=gt, etc) */
+ char type; /* int, short, long or string. */
+ char vallen; /* length of string value, if any */
+ union VALUETYPE {
+ unsigned char b;
+ unsigned short h;
+ unsigned long l;
+ char s[MAXstring];
+ unsigned char hs[2]; /* 2 bytes of a fixed-endian "short" */
+ unsigned char hl[4]; /* 2 bytes of a fixed-endian "long" */
+ } value; /* either number or string */
+ unsigned long mask; /* mask before comparison with value */
+ char nospflag; /* supress space character */
+
+ /* NOTE: this string is suspected of overrunning - find it! */
+ char desc[MAXDESC]; /* description */
+};
+
+/*
+ * data structures for tar file recognition
+ * --------------------------------------------------------------------------
+ * Header file for public domain tar (tape archive) program.
+ *
+ * @(#)tar.h 1.20 86/10/29 Public Domain. Created 25 August 1985 by John
+ * Gilmore, ihnp4!hoptoad!gnu.
+ *
+ * Header block on tape.
+ *
+ * I'm going to use traditional DP naming conventions here. A "block" is a big
+ * chunk of stuff that we do I/O on. A "record" is a piece of info that we
+ * care about. Typically many "record"s fit into a "block".
+ */
+#define RECORDSIZE 512
+#define NAMSIZ 100
+#define TUNMLEN 32
+#define TGNMLEN 32
+
+union record {
+ char charptr[RECORDSIZE];
+ struct header {
+ char name[NAMSIZ];
+ char mode[8];
+ char uid[8];
+ char gid[8];
+ char size[12];
+ char mtime[12];
+ char chksum[8];
+ char linkflag;
+ char linkname[NAMSIZ];
+ char magic[8];
+ char uname[TUNMLEN];
+ char gname[TGNMLEN];
+ char devmajor[8];
+ char devminor[8];
+ } header;
+};
+
+/* The magic field is filled with this if uname and gname are valid. */
+#define TMAGIC "ustar " /* 7 chars and a null */
+
+/*
+ * file-function prototypes
+ */
+/*TODO*/
+#define request_rec void
+#define server_rec void
+#define pool void
+#define cmd_parms void
+
+/*
+ * includes for ASCII substring recognition formerly "names.h" in file
+ * command
+ *
+ * Original notes: names and types used by ascmagic in file(1). These tokens are
+ * here because they can appear anywhere in the first HOWMANY bytes, while
+ * tokens in /etc/magic must appear at fixed offsets into the file. Don't
+ * make HOWMANY too high unless you have a very fast CPU.
+ */
+
+/* these types are used to index the table 'types': keep em in sync! */
+/* HTML inserted in first because this is a web server module now */
+#define L_HTML 0 /* HTML */
+#define L_C 1 /* first and foremost on UNIX */
+#define L_FORT 2 /* the oldest one */
+#define L_MAKE 3 /* Makefiles */
+#define L_PLI 4 /* PL/1 */
+#define L_MACH 5 /* some kinda assembler */
+#define L_ENG 6 /* English */
+#define L_PAS 7 /* Pascal */
+#define L_MAIL 8 /* Electronic mail */
+#define L_NEWS 9 /* Usenet Netnews */
+
+static char *types[] =
+ {
+ "text/html", /* HTML */
+ "text/plain", /* "c program text", */
+ "text/plain", /* "fortran program text", */
+ "text/plain", /* "make commands text", */
+ "text/plain", /* "pl/1 program text", */
+ "text/plain", /* "assembler program text", */
+ "text/plain", /* "English text", */
+ "text/plain", /* "pascal program text", */
+ "message/rfc822", /* "mail text", */
+ "message/news", /* "news text", */
+ "application/binary", /* "can't happen error on names.h/types", */
+ 0
+ };
+
+static struct names {
+ char *name;
+ short type;
+} names[] = {
+
+ /* These must be sorted by eye for optimal hit rate */
+ /* Add to this list only after substantial meditation */
+ {
+ "<html>", L_HTML
+ },
+ {
+ "<HTML>", L_HTML
+ },
+ {
+ "<head>", L_HTML
+ },
+ {
+ "<HEAD>", L_HTML
+ },
+ {
+ "<title>", L_HTML
+ },
+ {
+ "<TITLE>", L_HTML
+ },
+ {
+ "<h1>", L_HTML
+ },
+ {
+ "<H1>", L_HTML
+ },
+ {
+ "<!--", L_HTML
+ },
+ {
+ "<!DOCTYPE HTML", L_HTML
+ },
+ {
+ "/*", L_C
+ }, /* must precede "The", "the", etc. */
+ {
+ "#include", L_C
+ },
+ {
+ "char", L_C
+ },
+ {
+ "The", L_ENG
+ },
+ {
+ "the", L_ENG
+ },
+ {
+ "double", L_C
+ },
+ {
+ "extern", L_C
+ },
+ {
+ "float", L_C
+ },
+ {
+ "real", L_C
+ },
+ {
+ "struct", L_C
+ },
+ {
+ "union", L_C
+ },
+ {
+ "CFLAGS", L_MAKE
+ },
+ {
+ "LDFLAGS", L_MAKE
+ },
+ {
+ "all:", L_MAKE
+ },
+ {
+ ".PRECIOUS", L_MAKE
+ },
+ /*
+ * Too many files of text have these words in them. Find another way to
+ * recognize Fortrash.
+ */
+#ifdef NOTDEF
+ {
+ "subroutine", L_FORT
+ },
+ {
+ "function", L_FORT
+ },
+ {
+ "block", L_FORT
+ },
+ {
+ "common", L_FORT
+ },
+ {
+ "dimension", L_FORT
+ },
+ {
+ "integer", L_FORT
+ },
+ {
+ "data", L_FORT
+ },
+#endif /* NOTDEF */
+ {
+ ".ascii", L_MACH
+ },
+ {
+ ".asciiz", L_MACH
+ },
+ {
+ ".byte", L_MACH
+ },
+ {
+ ".even", L_MACH
+ },
+ {
+ ".globl", L_MACH
+ },
+ {
+ "clr", L_MACH
+ },
+ {
+ "(input,", L_PAS
+ },
+ {
+ "dcl", L_PLI
+ },
+ {
+ "Received:", L_MAIL
+ },
+ {
+ ">From", L_MAIL
+ },
+ {
+ "Return-Path:", L_MAIL
+ },
+ {
+ "Cc:", L_MAIL
+ },
+ {
+ "Newsgroups:", L_NEWS
+ },
+ {
+ "Path:", L_NEWS
+ },
+ {
+ "Organization:", L_NEWS
+ },
+ {
+ NULL, 0
+ }
+};
+
+#define NNAMES ((sizeof(names)/sizeof(struct names)) - 1)
+
+/*
+ * Result String List (RSL)
+ *
+ * The file(1) command prints its output. Instead, we store the various
+ * "printed" strings in a list (allocating memory as we go) and concatenate
+ * them at the end when we finally know how much space they'll need.
+ */
+
+typedef struct magic_rsl_s {
+ char *str; /* string, possibly a fragment */
+ struct magic_rsl_s *next; /* pointer to next fragment */
+} magic_rsl;
+
+/*
+ * Apache module configuration structures
+ */
+
+/* per-server info */
+typedef struct {
+ char *magicfile; /* where magic be found */
+ struct magic *magic; /* head of magic config list */
+ struct magic *last;
+} magic_server_config_rec;
+
+/* per-request info */
+typedef struct {
+ magic_rsl *head; /* result string list */
+ magic_rsl *tail;
+ unsigned suf_recursion; /* recursion depth in suffix check */
+} magic_req_rec;
+
+
+/* Globals */
+ZEND_BEGIN_MODULE_GLOBALS(mime_magic)
+ char *magicfile;
+ magic_req_rec *req_dat;
+ int debug; /* shall magic file parser errors be shown? */
+ char *status; /* status message for phpinfo() */
+ZEND_END_MODULE_GLOBALS(mime_magic)
+
+#ifdef ZTS
+#define MIME_MAGIC_G(v) TSRMG(mime_magic_globals_id, zend_mime_magic_globals *, v)
+#else
+#define MIME_MAGIC_G(v) (mime_magic_globals.v)
+#endif
+
+#endif /* PHPMIMEMAGIC_H */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ */
--- /dev/null
+--TEST--
+PEAR_Installer test #1
+--SKIPIF--
+<?php
+if (!getenv('PHP_PEAR_RUNTESTS')) {
+ echo 'skip';
+}
+?>
+--FILE--
+<?php
+
+require_once "PEAR/Installer.php";
+
+$temp_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testinstallertemp';
+if (!is_dir($temp_path)) {
+ mkdir($temp_path);
+}
+touch($temp_path . DIRECTORY_SEPARATOR . 'user.conf');
+// no UI is needed for these tests
+$ui = false;
+$installer = new PEAR_Installer($ui);
+echo "test extractDownloadFileName:\n";
+echo 'existing file: ';
+echo ($temp_path . DIRECTORY_SEPARATOR . 'user.conf' ==
+ $installer->extractDownloadFileName($temp_path . DIRECTORY_SEPARATOR . 'user.conf',
+ $ui)) ? "yes\n" : "no\n";
+var_dump($ui);
+echo 'invalid match: ';
+echo $installer->extractDownloadFileName('27',
+ $ui);
+echo "\n";
+var_dump($ui);
+echo 'valid match, no version: ';
+echo $installer->extractDownloadFileName('Testpackage', $ui);
+echo "\n";
+var_dump($ui);
+echo 'invalid match, has invalid version: ';
+echo $installer->extractDownloadFileName('Testpackage-##', $ui);
+echo "\n";
+var_dump($ui);
+echo 'valid match, has version: ';
+echo $installer->extractDownloadFileName('Testpackage-1.2', $ui);
+echo "\n";
+var_dump($ui);
+
+echo "\ntest checkDeps 1:\n";
+$fakerel = array('release_deps' =>
+array(
+ array(
+ 'type' => 'pkg',
+ 'rel '=> 'has',
+ 'name' => 'foo',
+ 'optional' => 'yes'
+ ),
+ array(
+ 'type' => 'pkg',
+ 'rel '=> 'ge',
+ 'version' => '1.6',
+ 'name' => 'bar',
+ ),
+));
+$res = '';
+var_dump($installer->checkDeps($fakerel, $res));
+var_dump($res);
+$fakerel = array('release_deps' =>
+array(
+ array(
+ 'type' => 'pkg',
+ 'rel '=> 'has',
+ 'name' => 'foo',
+ 'optional' => 'yes'
+ ),
+));
+echo "\ntest checkDeps 2:\n";
+$res = '';
+var_dump($installer->checkDeps($fakerel, $res));
+var_dump($res);
+unlink($temp_path . DIRECTORY_SEPARATOR . 'user.conf');
+rmdir($temp_path);
+?>
+--GET--
+--POST--
+--EXPECT--
+test extractDownloadFileName:
+existing file: yes
+bool(false)
+invalid match: 27
+NULL
+valid match, no version: Testpackage
+NULL
+invalid match, has invalid version: Testpackage-##
+NULL
+valid match, has version: Testpackage
+string(3) "1.2"
+
+test checkDeps 1:
+bool(true)
+string(23) "
+requires package `bar'"
+
+test checkDeps 2:
+bool(false)
+string(77) "Optional dependencies:
+package `foo' is recommended to utilize some features."
--- /dev/null
+--TEST--
+PEAR_Installer test #2
+--SKIPIF--
+<?php
+if (!getenv('PHP_PEAR_RUNTESTS')) {
+ echo 'skip';
+}
+?>
+--FILE--
+<?php
+$temp_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testinstallertemp';
+if (!is_dir($temp_path)) {
+ mkdir($temp_path);
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'php')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'php');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'data')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'data');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'doc')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'doc');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'test')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'test');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'ext')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'ext');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'script')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'script');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'tmp')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'tmp');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'bin')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'bin');
+}
+// make the fake configuration - we'll use one of these and it should work
+$config = serialize(array('master_server' => 'pear.php.net',
+ 'php_dir' => $temp_path . DIRECTORY_SEPARATOR . 'php',
+ 'ext_dir' => $temp_path . DIRECTORY_SEPARATOR . 'ext',
+ 'data_dir' => $temp_path . DIRECTORY_SEPARATOR . 'data',
+ 'doc_dir' => $temp_path . DIRECTORY_SEPARATOR . 'doc',
+ 'test_dir' => $temp_path . DIRECTORY_SEPARATOR . 'test',
+ 'bin_dir' => $temp_path . DIRECTORY_SEPARATOR . 'bin',));
+touch($temp_path . DIRECTORY_SEPARATOR . 'pear.conf');
+$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'pear.conf', 'w');
+fwrite($fp, $config);
+fclose($fp);
+touch($temp_path . DIRECTORY_SEPARATOR . 'pear.ini');
+$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'pear.ini', 'w');
+fwrite($fp, $config);
+fclose($fp);
+
+putenv('PHP_PEAR_SYSCONF_DIR='.$temp_path);
+$home = getenv('HOME');
+if (!empty($home)) {
+ // for PEAR_Config initialization
+ putenv('HOME="'.$temp_path);
+}
+require_once "PEAR/Installer.php";
+
+// no UI is needed for these tests
+$ui = false;
+$installer = new PEAR_Installer($ui);
+$curdir = getcwd();
+chdir(dirname(__FILE__));
+
+echo "test _installFile():\n";
+$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installer2.phpt.testfile.php', 'w');
+fwrite($fp, 'a');
+fclose($fp);
+// pretend we just parsed a package.xml
+$installer->pkginfo = array('package' => 'Foo');
+
+echo "install as role=\"php\":\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'php'),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo 'file ext/.tmpinstaller2.phpt.testfile.php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'php' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php') ? "yes\n" : "no\n");
+
+echo "install as role=\"ext\":\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'ext'),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo 'file php/.tmpinstaller2.phpt.testfile.php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'ext' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php') ? "yes\n" : "no\n");
+
+echo "install as role=\"data\":\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'data'),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo 'file data/.tmpinstaller2.phpt.testfile.php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR .
+ 'Foo' . DIRECTORY_SEPARATOR . '.tmpinstaller2.phpt.testfile.php') ? "yes\n" : "no\n");
+
+echo "install as role=\"doc\":\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'doc'),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo 'file doc/.tmpinstaller2.phpt.testfile.php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'doc' . DIRECTORY_SEPARATOR .
+ 'Foo' . DIRECTORY_SEPARATOR . '.tmpinstaller2.phpt.testfile.php') ? "yes\n" : "no\n");
+
+echo "install as role=\"test\":\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'test'),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo 'file test/.tmpinstaller2.phpt.testfile.php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR .
+ 'Foo' . DIRECTORY_SEPARATOR . '.tmpinstaller2.phpt.testfile.php') ? "yes\n" : "no\n");
+
+echo "install as role=\"script\":\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script'),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo 'file bin/.tmpinstaller2.phpt.testfile.php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php') ? "yes\n" : "no\n");
+
+$installer->rollbackFileTransaction();
+
+echo "install as invalid role=\"klingon\":\n";
+$err = $installer->_installFile('installer2.phpt.testfile.php', array('role' => 'klingon'),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array());
+echo 'returned PEAR_Error: ' . (get_class($err) == 'pear_error' ? "yes\n" : "no\n");
+if (is_object($err)) {
+ echo 'message: ' . $err->getMessage() . "\n\n";
+}
+echo 'file bin/.tmpinstaller2.phpt.testfile.php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php') ? "yes\n" : "no\n");
+
+echo "install non-existent file:\n";
+$err = $installer->_installFile('....php', array('role' => 'php'),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array());
+echo 'returned PEAR_Error: ' . (get_class($err) == 'pear_error' ? "yes\n" : "no\n");
+if (is_object($err)) {
+ echo 'message: ' . $err->getMessage() . "\n";
+}
+echo 'file bin/.tmp....php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmp....php') ? "yes\n" : "no\n");
+
+$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installer2.phpt.testfile.php', 'w');
+fwrite($fp, '@TEST@ stuff');
+fclose($fp);
+
+echo "\ntest valid md5sum:\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script', 'md5sum' => md5('@TEST@ stuff')),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo 'file bin/.tmpinstaller2.phpt.testfile.php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php') ? "yes\n" : "no\n");
+
+$installer->rollbackFileTransaction();
+
+echo "test invalid md5sum:\n";
+$err = $installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script', 'md5sum' => md5('oops stuff')),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array());
+echo 'returned PEAR_Error: ' . (get_class($err) == 'pear_error' ? "yes\n" : "no\n");
+if (is_object($err)) {
+ echo 'message: ' . ($err->getMessage() == 'bad md5sum for file ' . $temp_path . DIRECTORY_SEPARATOR . 'bin' .
+ DIRECTORY_SEPARATOR . 'installer2.phpt.testfile.php' ? 'match' : 'no match') . "\n";
+}
+echo 'file bin/.tmpinstaller2.phpt.testfile.php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php') ? "yes\n" : "no\n");
+
+echo "test invalid md5sum with --force:\n";
+ob_start();
+$err = $installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script', 'md5sum' => md5('oops stuff')),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array('force' => true));
+$warning = ob_get_contents();
+ob_end_clean();
+echo 'warning : ';
+echo ($warning == 'warning : bad md5sum for file ' . $temp_path . DIRECTORY_SEPARATOR . 'bin' .
+ DIRECTORY_SEPARATOR . "installer2.phpt.testfile.php\n" ? "match\n" : "no match\n");
+echo 'returned PEAR_Error: ' . (get_class($err) == 'pear_error' ? "yes\n" : "no\n");
+if (is_object($err)) {
+ echo 'message: ' . ($err->getMessage() == 'bad md5sum for file ' . $temp_path . DIRECTORY_SEPARATOR . 'bin' .
+ DIRECTORY_SEPARATOR . 'installer2.phpt.testfile.php' ? 'match' : 'no match') . "\n";
+}
+echo 'file bin/.tmpinstaller2.phpt.testfile.php exists? => ';
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php') ? "yes\n" : "no\n");
+
+define('PEARINSTALLERTEST2_FAKE_FOO_CONST', 'good');
+echo "\ntest replacements:\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script',
+ 'replacements' => array(array('type' => 'php-const', 'from' => '@TEST@', 'to' => 'PEARINSTALLERTEST2_FAKE_FOO_CONST'))),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo "==>test php-const replacement: equals 'good stuff'? => ";
+if (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'))
+{
+ $a = implode(file($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'), '');
+ echo "$a\n";
+} else {
+ echo "no! file installation failed\n";
+}
+$installer->rollbackFileTransaction();
+
+echo "==>test invalid php-const replacement:\n";
+$err = $installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script',
+ 'replacements' => array(array('type' => 'php-const', 'from' => '@TEST@', 'to' => '%PEARINSTALLERTEST2_FAKE_FOO_CONST'))),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array());
+if (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'))
+{
+ $a = implode(file($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'), '');
+ echo "$a\n";
+} else {
+ echo "no! file installation failed\n";
+}
+
+$installer->rollbackFileTransaction();
+
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script',
+ 'replacements' => array(array('type' => 'pear-config', 'from' => '@TEST@', 'to' => 'master_server'))),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo "==>test pear-config replacement: equals 'pear.php.net stuff'? => ";
+if (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'))
+{
+ $a = implode(file($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'), '');
+ echo "$a\n";
+} else {
+ echo "no! file installation failed\n";
+}
+$installer->rollbackFileTransaction();
+
+echo "==>test invalid pear-config replacement\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script',
+ 'replacements' => array(array('type' => 'pear-config', 'from' => '@TEST@', 'to' => 'blahblahblah'))),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+if (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'))
+{
+ $a = implode(file($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'), '');
+ echo "$a\n";
+} else {
+ echo "no! file installation failed\n";
+}
+$installer->rollbackFileTransaction();
+
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script',
+ 'replacements' => array(array('type' => 'package-info', 'from' => '@TEST@', 'to' => 'package'))),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo "==>test package-info replacement: equals 'Foo stuff'? => ";
+if (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'))
+{
+ $a = implode(file($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'), '');
+ echo "$a\n";
+} else {
+ echo "no! file installation failed\n";
+}
+$installer->rollbackFileTransaction();
+
+echo "==>test invalid package-info replacement:\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script',
+ 'replacements' => array(array('type' => 'package-info', 'from' => '@TEST@', 'to' => 'gronk'))),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+if (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'))
+{
+ $a = implode(file($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpinstaller2.phpt.testfile.php'), '');
+ echo "$a\n";
+} else {
+ echo "no! file installation failed\n";
+}
+$installer->rollbackFileTransaction();
+
+echo "\ntest install-as:\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script',
+ 'install-as' => 'foobar.php'),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo "==>test install as 'foobar.php'. file exists? ";
+if (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ '.tmpfoobar.php'))
+{
+ echo "yes\n";
+} else {
+ echo "no\n";
+}
+$installer->rollbackFileTransaction();
+
+echo "\ntest baseinstalldir:\n";
+var_dump($installer->_installFile('installer2.phpt.testfile.php', array('role' => 'script',
+ 'baseinstalldir' => 'Foo/Mine'),
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp', array()));
+echo "==>test baseinstalldir = 'Foo/Mine'. file exists? ";
+if (file_exists($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ 'Foo' . DIRECTORY_SEPARATOR . 'Mine' . DIRECTORY_SEPARATOR . '.tmpinstaller2.phpt.testfile.php'))
+{
+ echo "yes\n";
+} else {
+ echo "no\n";
+}
+$installer->rollbackFileTransaction();
+
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ 'Foo' . DIRECTORY_SEPARATOR . 'Mine');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR .
+ 'Foo');
+unlink($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installer2.phpt.testfile.php');
+//cleanup
+chdir($curdir);
+unlink ($temp_path . DIRECTORY_SEPARATOR . 'pear.conf');
+unlink ($temp_path . DIRECTORY_SEPARATOR . 'pear.ini');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'php');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'Foo');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'data');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'doc' . DIRECTORY_SEPARATOR . 'Foo');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'doc');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'Foo');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'test');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'script');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'ext');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'tmp');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'bin');
+rmdir($temp_path);
+?>
+--GET--
+--POST--
+--EXPECT--
+test _installFile():
+install as role="php":
+int(1)
+file ext/.tmpinstaller2.phpt.testfile.php exists? => yes
+install as role="ext":
+int(1)
+file php/.tmpinstaller2.phpt.testfile.php exists? => yes
+install as role="data":
+int(1)
+file data/.tmpinstaller2.phpt.testfile.php exists? => yes
+install as role="doc":
+int(1)
+file doc/.tmpinstaller2.phpt.testfile.php exists? => yes
+install as role="test":
+int(1)
+file test/.tmpinstaller2.phpt.testfile.php exists? => yes
+install as role="script":
+int(1)
+file bin/.tmpinstaller2.phpt.testfile.php exists? => yes
+install as invalid role="klingon":
+returned PEAR_Error: yes
+message: Invalid role `klingon' for file installer2.phpt.testfile.php
+
+file bin/.tmpinstaller2.phpt.testfile.php exists? => no
+install non-existent file:
+returned PEAR_Error: yes
+message: file does not exist
+file bin/.tmp....php exists? => no
+
+test valid md5sum:
+int(1)
+file bin/.tmpinstaller2.phpt.testfile.php exists? => yes
+test invalid md5sum:
+returned PEAR_Error: yes
+message: match
+file bin/.tmpinstaller2.phpt.testfile.php exists? => no
+test invalid md5sum with --force:
+warning : match
+returned PEAR_Error: no
+file bin/.tmpinstaller2.phpt.testfile.php exists? => yes
+
+test replacements:
+int(1)
+==>test php-const replacement: equals 'good stuff'? => good stuff
+==>test invalid php-const replacement:
+invalid php-const replacement: %PEARINSTALLERTEST2_FAKE_FOO_CONST
+@TEST@ stuff
+int(1)
+==>test pear-config replacement: equals 'pear.php.net stuff'? => pear.php.net stuff
+==>test invalid pear-config replacement
+invalid pear-config replacement: blahblahblah
+int(1)
+@TEST@ stuff
+int(1)
+==>test package-info replacement: equals 'Foo stuff'? => Foo stuff
+==>test invalid package-info replacement:
+invalid package-info replacement: gronk
+int(1)
+@TEST@ stuff
+
+test install-as:
+int(1)
+==>test install as 'foobar.php'. file exists? yes
+
+test baseinstalldir:
+int(1)
+==>test baseinstalldir = 'Foo/Mine'. file exists? yes
+
--- /dev/null
+--TEST--
+PEAR_Installer test #3 File Transactions
+--SKIPIF--
+<?php
+if (!getenv('PHP_PEAR_RUNTESTS')) {
+ echo 'skip';
+}
+?>
+--FILE--
+<?php
+$temp_path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'testinstallertemp';
+if (!is_dir($temp_path)) {
+ mkdir($temp_path);
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'php')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'php');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'data')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'data');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'doc')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'doc');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'test')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'test');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'ext')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'ext');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'script')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'script');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'tmp')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'tmp');
+}
+if (!is_dir($temp_path . DIRECTORY_SEPARATOR . 'bin')) {
+ mkdir($temp_path . DIRECTORY_SEPARATOR . 'bin');
+}
+// make the fake configuration - we'll use one of these and it should work
+$config = serialize(array('master_server' => 'pear.php.net',
+ 'php_dir' => $temp_path . DIRECTORY_SEPARATOR . 'php',
+ 'ext_dir' => $temp_path . DIRECTORY_SEPARATOR . 'ext',
+ 'data_dir' => $temp_path . DIRECTORY_SEPARATOR . 'data',
+ 'doc_dir' => $temp_path . DIRECTORY_SEPARATOR . 'doc',
+ 'test_dir' => $temp_path . DIRECTORY_SEPARATOR . 'test',
+ 'bin_dir' => $temp_path . DIRECTORY_SEPARATOR . 'bin',));
+touch($temp_path . DIRECTORY_SEPARATOR . 'pear.conf');
+$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'pear.conf', 'w');
+fwrite($fp, $config);
+fclose($fp);
+touch($temp_path . DIRECTORY_SEPARATOR . 'pear.ini');
+$fp = fopen($temp_path . DIRECTORY_SEPARATOR . 'pear.ini', 'w');
+fwrite($fp, $config);
+fclose($fp);
+
+putenv('PHP_PEAR_SYSCONF_DIR='.$temp_path);
+$home = getenv('HOME');
+if (!empty($home)) {
+ // for PEAR_Config initialization
+ putenv('HOME="'.$temp_path);
+}
+require_once "PEAR/Installer.php";
+
+// no UI is needed for these tests
+$ui = false;
+$installer = new PEAR_Installer($ui);
+$installer->debug = 2; // hack debugging in
+$curdir = getcwd();
+chdir(dirname(__FILE__));
+
+echo "test addFileOperation():\n";
+echo "invalid input to addFileOperation():\n";
+$err = $installer->addFileOperation('rename', 2);
+echo 'Returned PEAR_Error?';
+echo (get_class($err) == 'pear_error' ? " yes\n" : " no\n");
+if (get_class($err) == 'pear_error') {
+ echo $err->getMessage() . "\n";
+}
+echo 'count($installer->file_operations) = ';
+var_dump(count($installer->file_operations));
+echo "Do valid addFileOperation() delete\n";
+touch($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt');
+$installer->addFileOperation('delete', array($temp_path . DIRECTORY_SEPARATOR .
+ 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt'));
+echo 'count($installer->file_operations) = ';
+var_dump(count($installer->file_operations));
+
+echo "test valid commitFileTransaction():\n";
+if ($installer->commitFileTransaction()) {
+ echo "worked\n";
+} else {
+ echo "didn't work!\n";
+}
+
+echo "Do valid addFileOperation() rename\n";
+touch($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt');
+$installer->addFileOperation('rename', array($temp_path . DIRECTORY_SEPARATOR .
+ 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt', $temp_path .
+ DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'renamed.phpt'));
+
+echo 'file renamed.phpt exists?';
+clearstatcache();
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR
+ . 'renamed.phpt') ? " yes\n" : " no\n");
+echo "test valid commitFileTransaction():\n";
+if ($installer->commitFileTransaction()) {
+ echo "worked\n";
+} else {
+ echo "didn't work!\n";
+}
+echo 'file renamed.phpt exists?';
+clearstatcache();
+echo (file_exists($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR
+ . 'renamed.phpt') ? " yes\n" : " no\n");
+unlink($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR
+ . 'renamed.phpt');
+
+echo "Do valid addFileOperation() chmod\n";
+touch($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt');
+clearstatcache();
+$perms = fileperms($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt');
+// check to see if chmod works on this OS
+chmod($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt', 0776);
+clearstatcache();
+if (fileperms($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt')
+ == $perms && substr(PHP_OS, 0, 3) == 'WIN') {
+ // we are on windows, so skip this test, but simulate success
+echo <<<EOF
+file permissions are: 776
+test valid commitFileTransaction():
+about to commit 1 file operations
+successfully committed 1 file operations
+worked
+file permissions are: 640
+
+EOF;
+} else {
+ $installer->addFileOperation('chmod', array(0640, $temp_path . DIRECTORY_SEPARATOR .
+ 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt'));
+
+ echo 'file permissions are: ' . decoct(fileperms($temp_path . DIRECTORY_SEPARATOR .
+ 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt')) . "\n";
+ echo "test valid commitFileTransaction():\n";
+ if ($installer->commitFileTransaction()) {
+ echo "worked\n";
+ } else {
+ echo "didn't work!\n";
+ }
+ echo 'file permissions are: ' . decoct(fileperms($temp_path . DIRECTORY_SEPARATOR .
+ 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah.phpt')) . "\n";
+}
+unlink($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR
+ . 'installertestfooblah.phpt');
+
+mkdir($temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR
+ . 'installertestfooblah');
+echo "Do valid addFileOperation() rmdir\n";
+echo 'directory exists?';
+clearstatcache();
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR .
+ 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah') ? " yes\n" : " no\n");
+$installer->addFileOperation('rmdir', array($temp_path . DIRECTORY_SEPARATOR .
+ 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah'));
+
+echo "test valid commitFileTransaction():\n";
+if ($installer->commitFileTransaction()) {
+ echo "worked\n";
+} else {
+ echo "didn't work!\n";
+}
+echo 'directory exists?';
+
+clearstatcache();
+echo (is_dir($temp_path . DIRECTORY_SEPARATOR .
+ 'tmp' . DIRECTORY_SEPARATOR . 'installertestfooblah') ? " yes\n" : " no\n");
+
+echo "Do valid addFileOperation() installed_as\n";
+$installer->addFileOperation('installed_as', array('test.php',
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
+ 'glomp' . DIRECTORY_SEPARATOR . 'fromp' . DIRECTORY_SEPARATOR
+ . 'installertestfooblah.phpt',
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
+ 'glomp' . DIRECTORY_SEPARATOR . 'fromp'));
+echo "test valid commitFileTransaction():\n";
+if ($installer->commitFileTransaction()) {
+ echo "worked\n";
+} else {
+ echo "didn't work!\n";
+}
+if (isset($installer->pkginfo['filelist'])) {
+ echo "filelist created\n";
+} else {
+ echo "filelist not created!\n";
+}
+if (isset($installer->pkginfo['filelist']['test.php'])) {
+ echo "filelist test.php created\n";
+} else {
+ echo "filelist test.php not created!\n";
+}
+if (isset($installer->pkginfo['filelist']['test.php']['installed_as'])) {
+ echo "filelist test.php installed_as created\n";
+} else {
+ echo "filelist test.php installed_as not created!\n";
+}
+$p = $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
+ 'glomp' . DIRECTORY_SEPARATOR . 'fromp' . DIRECTORY_SEPARATOR
+ . 'installertestfooblah.phpt';
+if (@$installer->pkginfo['filelist']['test.php']['installed_as'] == $p) {
+ echo "filelist test.php installed_as is correct\n";
+} else {
+ echo "filelist test.php installed_as is not correct!\n";
+}
+if (isset($installer->pkginfo['filelist']['dirtree'])) {
+ echo "filelist dirtree created\n";
+} else {
+ echo "filelist dirtree not created!\n";
+}
+$p = $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
+ 'glomp';
+if (isset($installer->pkginfo['filelist']['dirtree'][$p])) {
+ echo "filelist dirtree glomp created\n";
+} else {
+ echo "filelist dirtree glomp not created!\n";
+}
+$p .= DIRECTORY_SEPARATOR . 'fromp';
+if (isset($installer->pkginfo['filelist']['dirtree'][$p])) {
+ echo "filelist dirtree fromp created\n";
+} else {
+ echo "filelist dirtree fromp not created!\n";
+}
+
+echo "Do valid addFileOperation() installed_as\n";
+$installer->addFileOperation('installed_as', array('test.php',
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
+ 'glomp' . DIRECTORY_SEPARATOR . 'fromp' . DIRECTORY_SEPARATOR
+ . 'installertestfooblah.phpt',
+ $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR,
+ 'glomp' . DIRECTORY_SEPARATOR . 'fromp'));
+echo "test valid rollbackFileTransaction():\n";
+$installer->rollbackFileTransaction();
+if (isset($installer->pkginfo['filelist'])) {
+ echo "filelist created\n";
+} else {
+ echo "filelist not created!\n";
+}
+if (isset($installer->pkginfo['filelist']['test.php'])) {
+ echo "filelist test.php created\n";
+} else {
+ echo "filelist test.php not created!\n";
+}
+if (isset($installer->pkginfo['filelist']['test.php']['installed_as'])) {
+ echo "filelist test.php installed_as created\n";
+} else {
+ echo "filelist test.php installed_as not created!\n";
+}
+$p = $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
+ 'glomp' . DIRECTORY_SEPARATOR . 'fromp' . DIRECTORY_SEPARATOR
+ . 'installertestfooblah.phpt';
+if (@$installer->pkginfo['filelist']['test.php']['installed_as'] == $p) {
+ echo "filelist test.php installed_as is correct\n";
+} else {
+ echo "filelist test.php installed_as is not correct!\n";
+}
+if (isset($installer->pkginfo['filelist']['dirtree'])) {
+ echo "filelist dirtree created\n";
+} else {
+ echo "filelist dirtree not created!\n";
+}
+$p = $temp_path . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR .
+ 'glomp';
+if (isset($installer->pkginfo['filelist']['dirtree'][$p])) {
+ echo "filelist dirtree glomp created\n";
+} else {
+ echo "filelist dirtree glomp not created!\n";
+}
+$p .= DIRECTORY_SEPARATOR . 'fromp';
+if (isset($installer->pkginfo['filelist']['dirtree'][$p])) {
+ echo "filelist dirtree fromp created\n";
+} else {
+ echo "filelist dirtree fromp not created!\n";
+}
+
+// invalid tests
+echo "\n==>Invalid tests\n";
+echo "Do valid addFileOperation() delete with non-existing file\n";
+$installer->addFileOperation('delete', array('gloober62456.phpt'));
+echo 'count($installer->file_operations) = ';
+var_dump(count($installer->file_operations));
+
+echo "test invalid commitFileTransaction():\n";
+if ($installer->commitFileTransaction()) {
+ echo "worked\n";
+} else {
+ echo "didn't work!\n";
+ $installer->rollbackFileTransaction();
+}
+
+echo "Do valid addFileOperation() rename with non-existing file\n";
+$installer->addFileOperation('rename', array('gloober62456.phpt', 'faber.com'));
+echo 'count($installer->file_operations) = ';
+var_dump(count($installer->file_operations));
+
+echo "test invalid commitFileTransaction():\n";
+if ($installer->commitFileTransaction()) {
+ echo "worked\n";
+} else {
+ echo "didn't work!\n";
+ $installer->rollbackFileTransaction();
+}
+
+echo "Do valid addFileOperation() chmod with non-existing file\n";
+$installer->addFileOperation('chmod', array(0640, 'faber.com'));
+echo 'count($installer->file_operations) = ';
+var_dump(count($installer->file_operations));
+
+echo "test invalid commitFileTransaction():\n";
+if ($installer->commitFileTransaction()) {
+ echo "worked\n";
+} else {
+ echo "didn't work!\n";
+ $installer->rollbackFileTransaction();
+}
+
+//cleanup
+chdir($curdir);
+unlink ($temp_path . DIRECTORY_SEPARATOR . 'pear.conf');
+unlink ($temp_path . DIRECTORY_SEPARATOR . 'pear.ini');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'php');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'data');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'doc');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'test');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'script');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'ext');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'tmp');
+rmdir($temp_path . DIRECTORY_SEPARATOR . 'bin');
+rmdir($temp_path);
+?>
+--GET--
+--POST--
+--EXPECT--
+test addFileOperation():
+invalid input to addFileOperation():
+Returned PEAR_Error? yes
+Internal Error: $data in addFileOperation must be an array, was integer
+count($installer->file_operations) = int(0)
+Do valid addFileOperation() delete
+count($installer->file_operations) = int(1)
+test valid commitFileTransaction():
+about to commit 1 file operations
+successfully committed 1 file operations
+worked
+Do valid addFileOperation() rename
+file renamed.phpt exists? no
+test valid commitFileTransaction():
+about to commit 1 file operations
+successfully committed 1 file operations
+worked
+file renamed.phpt exists? yes
+Do valid addFileOperation() chmod
+file permissions are: 776
+test valid commitFileTransaction():
+about to commit 1 file operations
+successfully committed 1 file operations
+worked
+file permissions are: 640
+Do valid addFileOperation() rmdir
+directory exists? yes
+test valid commitFileTransaction():
+about to commit 1 file operations
+successfully committed 1 file operations
+worked
+directory exists? no
+Do valid addFileOperation() installed_as
+test valid commitFileTransaction():
+about to commit 1 file operations
+successfully committed 1 file operations
+worked
+filelist created
+filelist test.php created
+filelist test.php installed_as created
+filelist test.php installed_as is correct
+filelist dirtree created
+filelist dirtree glomp created
+filelist dirtree fromp created
+Do valid addFileOperation() installed_as
+test valid rollbackFileTransaction():
+rolling back 1 file operations
+filelist created
+filelist test.php created
+filelist test.php installed_as not created!
+filelist test.php installed_as is not correct!
+filelist dirtree not created!
+filelist dirtree glomp not created!
+filelist dirtree fromp not created!
+
+==>Invalid tests
+Do valid addFileOperation() delete with non-existing file
+count($installer->file_operations) = int(1)
+test invalid commitFileTransaction():
+about to commit 1 file operations
+warning: file gloober62456.phpt doesn't exist, can't be deleted
+successfully committed 1 file operations
+worked
+Do valid addFileOperation() rename with non-existing file
+count($installer->file_operations) = int(1)
+test invalid commitFileTransaction():
+about to commit 1 file operations
+cannot rename file gloober62456.phpt, doesn't exist
+didn't work!
+rolling back 1 file operations
+Do valid addFileOperation() chmod with non-existing file
+count($installer->file_operations) = int(1)
+test invalid commitFileTransaction():
+about to commit 1 file operations
+permission denied (chmod): faber.com 640
+didn't work!
+rolling back 1 file operations