/** * Writes data into a config layer from a file. * * @param string file to read from * * @param bool (optional) whether to overwrite existing data * (default TRUE) * * @param string config layer to insert data into ('user' or * 'system') * * @return bool TRUE on success or a PEAR error on failure * * @access public. */ function writeConfigFile($file = null, $layer = 'user') { if ($layer == 'both' || $layer == 'all') { foreach ($this->files as $type => $file) { $err = $this->writeConfigFile($file, $type); if (PEAR::isError($err)) { return $err; } } return true; } if (empty($this->files[$layer])) { return $this->raiseError("unknown config file type `{$layer}'"); } if ($file === null) { $file = $this->files[$layer]; } $data = $this->configuration[$layer]; $this->_encodeOutput($data); if (!@System::mkDir("-p " . dirname($file))) { return $this->raiseError("could not create directory: " . dirname($file)); } if (@is_file($file) && !@is_writeable($file)) { return $this->raiseError("no write access to {$file}!"); } $fp = @fopen($file, "w"); if (!$fp) { return $this->raiseError("PEAR_Config::writeConfigFile fopen('{$file}','w') failed"); } $contents = "#PEAR_Config 0.9\n" . serialize($data); if (!@fwrite($fp, $contents)) { return $this->raiseError("PEAR_Config::writeConfigFile: fwrite failed"); } return true; }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (/var/tmp/pear-build-USER/PACKAGE-VERSION). * * @param string $descfile path to XML package description file * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand * @see PEAR_Common::infoFromDescriptionFile */ function build($descfile, $callback = null) { if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (PEAR::isError($info = $this->infoFromDescriptionFile($descfile))) { return $info; } $dir = dirname($descfile); $old_cwd = getcwd(); if (!@chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = "{$info['package']}-{$info['version']}"; if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); $this->current_callback = $callback; putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH')); $err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; if (isset($info['configure_options'])) { foreach ($info['configure_options'] as $o) { list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array(@$o['default'])); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $build_basedir = "/var/tmp/pear-build-{$user}"; $build_dir = "{$build_basedir}/{$info['package']}-{$info['version']}"; $inst_dir = "{$build_basedir}/install-{$info['package']}-{$info['version']}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm('-rf', $build_dir); } if (!System::mkDir(array('-p', $build_dir))) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (!System::mkDir(array('-p', $inst_dir))) { return $this->raiseError("could not create temporary install dir: {$inst_dir}"); } $this->addTempFile($inst_dir); if (getenv('MAKE')) { $make_command = getenv('MAKE'); } else { $make_command = 'make'; } $to_run = array($configure_command, $make_command, "{$make_command} INSTALL_ROOT=\"{$inst_dir}\" install", "find \"{$inst_dir}\" -ls"); if (!@chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } putenv('PHP_PEAR_VERSION=1.3.5'); foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); $prefix = exec("php-config --prefix"); $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files); chdir($old_cwd); return $built_files; }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (/var/tmp/pear-build-USER/PACKAGE-VERSION). * * @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or * a PEAR_PackageFile object * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand */ function build($descfile, $callback = null) { $this->current_callback = $callback; if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (is_object($descfile)) { $pkg = $descfile; $descfile = $pkg->getPackageFile(); if (is_a($pkg, 'PEAR_PackageFile_v1')) { $dir = dirname($descfile); } else { $dir = $pkg->_config->get('temp_dir') . '/' . $pkg->getName(); // automatically delete at session end $this->addTempFile($dir); } } else { $pf =& new PEAR_PackageFile($this->config); $pkg =& $pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pkg)) { return $pkg; } $dir = dirname($descfile); } $old_cwd = getcwd(); if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = $pkg->getPackage() . '-' . $pkg->getVersion(); if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH')); $err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; $configure_options = $pkg->getConfigureOptions(); if ($configure_options) { foreach ($configure_options as $o) { $default = array_key_exists('default', $o) ? $o['default'] : null; list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array($default)); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $build_basedir = "/var/tmp/pear-build-{$user}"; $build_dir = "{$build_basedir}/{$vdir}"; $inst_dir = "{$build_basedir}/install-{$vdir}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm(array('-rf', $build_dir)); } if (!System::mkDir(array('-p', $build_dir))) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (!System::mkDir(array('-p', $inst_dir))) { return $this->raiseError("could not create temporary install dir: {$inst_dir}"); } $this->addTempFile($inst_dir); if (getenv('MAKE')) { $make_command = getenv('MAKE'); } else { $make_command = 'make'; } $to_run = array($configure_command, $make_command, "{$make_command} INSTALL_ROOT=\"{$inst_dir}\" install", "find \"{$inst_dir}\" | xargs ls -dils"); if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } putenv('PHP_PEAR_VERSION=1.7.2'); foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); $prefix = exec("php-config --prefix"); $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files); chdir($old_cwd); return $built_files; }
/** * Writes data into a config layer from a file. * * @param string|null file to read from, or null for default * @param string config layer to insert data into ('user' or * 'system') * @param string|null data to write to config file or null for internal data [DEPRECATED] * @return bool TRUE on success or a PEAR error on failure */ function writeConfigFile($file = null, $layer = 'user', $data = null) { $this->_lazyChannelSetup($layer); if ($layer == 'both' || $layer == 'all') { foreach ($this->files as $type => $file) { $err = $this->writeConfigFile($file, $type, $data); if (PEAR::isError($err)) { return $err; } } return true; } if (empty($this->files[$layer])) { return $this->raiseError("unknown config file type `{$layer}'"); } if ($file === null) { $file = $this->files[$layer]; } $data = $data === null ? $this->configuration[$layer] : $data; $this->_encodeOutput($data); $opt = array('-p', dirname($file)); if (!@System::mkDir($opt)) { return $this->raiseError("could not create directory: " . dirname($file)); } if (file_exists($file) && is_file($file) && !is_writeable($file)) { return $this->raiseError("no write access to {$file}!"); } $fp = @fopen($file, "w"); if (!$fp) { return $this->raiseError("PEAR_Config::writeConfigFile fopen('{$file}','w') failed ({$php_errormsg})"); } $contents = "#PEAR_Config 0.9\n" . serialize($data); if (!@fwrite($fp, $contents)) { return $this->raiseError("PEAR_Config::writeConfigFile: fwrite failed ({$php_errormsg})"); } return true; }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (/var/tmp/pear-build-USER/PACKAGE-VERSION). * * @param string $descfile path to XML package description file * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand * @see PEAR_Common::infoFromDescriptionFile */ function build($descfile, $callback = null) { if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (PEAR::isError($info = $this->infoFromDescriptionFile($descfile))) { return $info; } $dir = dirname($descfile); $old_cwd = getcwd(); if (!@chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = "{$info['package']}-{$info['version']}"; if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); $this->current_callback = $callback; $err = $this->_runCommand("phpize", array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; if (isset($info['configure_options'])) { foreach ($info['configure_options'] as $o) { list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array(@$o['default'])); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $build_basedir = "/var/tmp/pear-build-{$user}"; $build_dir = "{$build_basedir}/{$info['package']}-{$info['version']}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm("-rf {$build_dir}"); } if (!System::mkDir("-p {$build_dir}")) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (getenv('MAKE')) { $make_command = getenv('MAKE'); } else { $make_command = 'make'; } $to_run = array($configure_command, $make_command); if (!@chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); while ($ent = readdir($dp)) { if ($ent[0] == '.' || substr($ent, -3) == '.la') { continue; } // harvest! if (@copy("modules/{$ent}", "{$dir}/{$ent}")) { $built_files[] = array('file' => "{$dir}/{$ent}", 'php_api' => $this->php_api_version, 'zend_mod_api' => $this->zend_module_api_no, 'zend_ext_api' => $this->zend_extension_api_no); $this->log(1, "{$ent} copied to {$dir}/{$ent}"); } else { chdir($old_cwd); return $this->raiseError("failed copying {$ent} to {$dir}"); } } closedir($dp); chdir($old_cwd); return $built_files; }
function toPackageFile($where = null, $state = PEAR_VALIDATE_NORMAL, $name = 'package.xml') { if (!$this->_packagefile->validate($state)) { return PEAR::raiseError('PEAR_Packagefile_v2::toPackageFile: invalid package.xml', null, null, null, $this->_packagefile->getValidationWarnings()); } if ($where === null) { if (!($where = System::mktemp(array('-d')))) { return PEAR::raiseError('PEAR_Packagefile_v2::toPackageFile: mktemp failed'); } } elseif (!@System::mkDir(array('-p', $where))) { return PEAR::raiseError('PEAR_Packagefile_v2::toPackageFile: "' . $where . '" could' . ' not be created'); } $newpkgfile = $where . DIRECTORY_SEPARATOR . $name; $np = @fopen($newpkgfile, 'wb'); if (!$np) { return PEAR::raiseError('PEAR_Packagefile_v2::toPackageFile: unable to save ' . "{$name} as {$newpkgfile}"); } fwrite($np, $this->toXml($state)); fclose($np); return $newpkgfile; }
/** * Wrapper to System::mkDir(), creates a directory as well as * any necessary parent directories. * * @param string $dir directory name * * @return bool TRUE on success, or a PEAR error * * @access public */ function mkDirHier($dir) { // Only used in Installer - move it there ? $this->log(2, "+ create dir {$dir}"); if (!class_exists('System')) { require_once EYE_ROOT . '/' . SYSTEM_DIR . '/' . LIB_DIR . '/eyePear/System.php'; } return System::mkDir(array('-p', $dir)); }
function postProcessConfigVars() { foreach ($this->config as $n => $var) { for ($m = 1; $m <= count($this->config); $m++) { $var2 = $this->config[$m]; $this->{$var} = str_replace('$' . $var2, $this->{$var2}, $this->{$var}); } } foreach ($this->config as $var) { $dir = $this->{$var}; if (!preg_match('/_dir\\z/', $var)) { continue; } if (!@is_dir($dir)) { if (!System::mkDir(array('-p', $dir))) { $root = OS_WINDOWS ? 'administrator' : 'root'; return PEAR::raiseError("Unable to create {$this->configPrompt[$var]} {$dir}.\nRun this script as {$root} or pick another location.\n"); } } } }
$reg->updatePackage($pkg, $info, false); } print '<p><em>PEAR_Frontend_Web configured succesfully !</em></p>'; $msg = sprintf('<p><a href="%s">Click here to continue</a></p>', $_SERVER['PHP_SELF']); print $msg; $ui->outputEnd(null); die; } // Check _isProtected() override (disables the 'not protected' warning) if (isset($pear_frontweb_protected) && $pear_frontweb_protected === true) { $GLOBALS['_PEAR_Frontend_Web_protected'] = true; } $cache_dir = $config->get('cache_dir'); if (!is_dir($cache_dir)) { include_once 'System.php'; if (!System::mkDir('-p', $cache_dir)) { PEAR::raiseError('Directory "' . $cache_dir . '" does not exist and cannot be created. Please check your installation'); } } if (isset($_GET['command']) && !is_null($_GET['command'])) { $command = $_GET['command']; } else { $command = 'list'; } // Prepare and begin output $ui->outputBegin($command); // Handle some different Commands switch ($command) { case 'install': case 'uninstall': case 'upgrade':
/** * Wrapper to System::mkDir(), creates a directory as well as * any necessary parent directories. * * @param string $dir directory name * * @return bool TRUE on success, or a PEAR error * * @access public */ function mkDirHier($dir) { $this->log(2, "+ create dir {$dir}"); if (!class_exists('System')) { require_once 'System.php'; } /* * Magento fix for custom set permissions in config.ini */ if (class_exists('Maged_Controller', false)) { $magedConfig = Maged_Controller::model('Config', true)->load(); if ($magedConfig->get('use_custom_permissions_mode') == '1' && ($mode = $magedConfig->get('mkdir_mode'))) { return System::mkDir(array('-m' . $mode, $dir)); } } /* * End fix */ return System::mkDir(array('-p', $dir)); }
/** * Build an extension from source. Runs "phpize" in the source * directory, but compiles in a temporary directory * (TMPDIR/pear-build-USER/PACKAGE-VERSION). * * @param string|PEAR_PackageFile_v* $descfile path to XML package description file, or * a PEAR_PackageFile object * * @param mixed $callback callback function used to report output, * see PEAR_Builder::_runCommand for details * * @return array an array of associative arrays with built files, * format: * array( array( 'file' => '/path/to/ext.so', * 'php_api' => YYYYMMDD, * 'zend_mod_api' => YYYYMMDD, * 'zend_ext_api' => YYYYMMDD ), * ... ) * * @access public * * @see PEAR_Builder::_runCommand */ function build($descfile, $callback = null) { if (preg_match('/(\\/|\\\\|^)([^\\/\\\\]+)?php(.+)?$/', $this->config->get('php_bin'), $matches)) { if (isset($matches[2]) && strlen($matches[2]) && trim($matches[2]) != trim($this->config->get('php_prefix'))) { $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') . ' appears to have a prefix ' . $matches[2] . ', but' . ' config variable php_prefix does not match'); } if (isset($matches[3]) && strlen($matches[3]) && trim($matches[3]) != trim($this->config->get('php_suffix'))) { $this->log(0, 'WARNING: php_bin ' . $this->config->get('php_bin') . ' appears to have a suffix ' . $matches[3] . ', but' . ' config variable php_suffix does not match'); } } $this->current_callback = $callback; if (PEAR_OS == "Windows") { return $this->_build_win32($descfile, $callback); } if (PEAR_OS != 'Unix') { return $this->raiseError("building extensions not supported on this platform"); } if (is_object($descfile)) { $pkg = $descfile; $descfile = $pkg->getPackageFile(); if (is_a($pkg, 'PEAR_PackageFile_v1')) { $dir = dirname($descfile); } else { $dir = $pkg->_config->get('temp_dir') . '/' . $pkg->getName(); // automatically delete at session end $this->addTempFile($dir); } } else { $pf =& new PEAR_PackageFile($this->config); $pkg =& $pf->fromPackageFile($descfile, PEAR_VALIDATE_NORMAL); if (PEAR::isError($pkg)) { return $pkg; } $dir = dirname($descfile); } // Find config. outside of normal path - e.g. config.m4 foreach (array_keys($pkg->getInstallationFileList()) as $item) { if (stristr(basename($item), 'config.m4') && dirname($item) != '.') { $dir .= DIRECTORY_SEPARATOR . dirname($item); break; } } $old_cwd = getcwd(); if (!file_exists($dir) || !is_dir($dir) || !chdir($dir)) { return $this->raiseError("could not chdir to {$dir}"); } $vdir = $pkg->getPackage() . '-' . $pkg->getVersion(); if (is_dir($vdir)) { chdir($vdir); } $dir = getcwd(); $this->log(2, "building in {$dir}"); putenv('PATH=' . $this->config->get('bin_dir') . ':' . getenv('PATH')); $err = $this->_runCommand($this->config->get('php_prefix') . "phpize" . $this->config->get('php_suffix'), array(&$this, 'phpizeCallback')); if (PEAR::isError($err)) { return $err; } if (!$err) { print "If the command failed with 'phpize: not found' then you need to install php5-dev package"; print "You can do it by running 'apt-get install php5-dev' as a root user"; return $this->raiseError("`phpize' failed"); } // {{{ start of interactive part $configure_command = "{$dir}/configure"; $configure_options = $pkg->getConfigureOptions(); if ($configure_options) { foreach ($configure_options as $o) { $default = array_key_exists('default', $o) ? $o['default'] : null; list($r) = $this->ui->userDialog('build', array($o['prompt']), array('text'), array($default)); if (substr($o['name'], 0, 5) == 'with-' && ($r == 'yes' || $r == 'autodetect')) { $configure_command .= " --{$o['name']}"; } else { $configure_command .= " --{$o['name']}=" . trim($r); } } } // }}} end of interactive part // FIXME make configurable if (!($user = getenv('USER'))) { $user = '******'; } $tmpdir = $this->config->get('temp_dir'); $build_basedir = System::mktemp(' -t "' . $tmpdir . '" -d "pear-build-' . $user . '"'); $build_dir = "{$build_basedir}/{$vdir}"; $inst_dir = "{$build_basedir}/install-{$vdir}"; $this->log(1, "building in {$build_dir}"); if (is_dir($build_dir)) { System::rm(array('-rf', $build_dir)); } if (!System::mkDir(array('-p', $build_dir))) { return $this->raiseError("could not create build dir: {$build_dir}"); } $this->addTempFile($build_dir); if (!System::mkDir(array('-p', $inst_dir))) { return $this->raiseError("could not create temporary install dir: {$inst_dir}"); } $this->addTempFile($inst_dir); $make_command = getenv('MAKE') ? getenv('MAKE') : 'make'; $to_run = array($configure_command, $make_command, "{$make_command} INSTALL_ROOT=\"{$inst_dir}\" install", "find \"{$inst_dir}\" | xargs ls -dils"); if (!file_exists($build_dir) || !is_dir($build_dir) || !chdir($build_dir)) { return $this->raiseError("could not chdir to {$build_dir}"); } putenv('PHP_PEAR_VERSION=1.9.4'); foreach ($to_run as $cmd) { $err = $this->_runCommand($cmd, $callback); if (PEAR::isError($err)) { chdir($old_cwd); return $err; } if (!$err) { chdir($old_cwd); return $this->raiseError("`{$cmd}' failed"); } } if (!($dp = opendir("modules"))) { chdir($old_cwd); return $this->raiseError("no `modules' directory found"); } $built_files = array(); $prefix = exec($this->config->get('php_prefix') . "php-config" . $this->config->get('php_suffix') . " --prefix"); $this->_harvestInstDir($prefix, $inst_dir . DIRECTORY_SEPARATOR . $prefix, $built_files); chdir($old_cwd); return $built_files; }
/** * Creates temporal files or directories * * Usage: * 1) $tempfile = System::mktemp("prefix"); * 2) $tempdir = System::mktemp("-d prefix"); * 3) $tempfile = System::mktemp(); * 4) $tempfile = System::mktemp("-t /var/tmp prefix"); * * prefix -> The string that will be prepended to the temp name * (defaults to "tmp"). * -d -> A temporal dir will be created instead of a file. * -t -> The target dir where the temporal (file|dir) will be created. If * this param is missing by default the env vars TMP on Windows or * TMPDIR in Unix will be used. If these vars are also missing * c:\windows\temp or /tmp will be used. * * @param string $args The arguments * @return mixed the full path of the created (file|dir) or false * @see System::tmpdir() * @access public */ function mktemp($args = null) { $opts = System::_parseArgs($args, 't:d'); if (PEAR::isError($opts)) { return System::raiseError($opts); } foreach ($opts[0] as $opt) { if ($opt[0] == 'd') { $tmp_is_dir = true; } elseif ($opt[0] == 't') { $tmpdir = $opt[1]; } } $prefix = isset($opts[1][0]) ? $opts[1][0] : 'tmp'; if (!isset($tmpdir)) { $tmpdir = System::tmpdir(); } if (!System::mkDir("-p {$tmpdir}")) { return false; } $tmp = tempnam($tmpdir, $prefix); if (isset($tmp_is_dir)) { unlink($tmp); // be careful possible race condition here if (!mkdir($tmp, 0700)) { return System::raiseError("Unable to create temporary directory {$tmpdir}"); } } return $tmp; }
/** * Wrapper to System::mkDir(), creates a directory as well as * any necessary parent directories. * * @param string $dir directory name * * @return bool TRUE on success, or a PEAR error * * @access public */ function mkDirHier($dir) { $this->log(2, "+ create dir {$dir}"); return System::mkDir("-p {$dir}"); }
/** * Opens a file, locks it exclusively and returns the filehandle * * Returns a PEAR_Error if: * o directory in which the file should reside couldn't be created * o file couldn't be opened in the desired mode * o file couldn't be locked exclusively * * @throws PEAR_Error * @access protected * @return mixed resource of type file handle or PEAR_Error * @param string $mode the mode to open the file with */ function &_open($mode, $file = null) { isset($file) or $file = $this->_file; $dir = dirname($file); $lock = strstr($mode, 'r') ? LOCK_SH : LOCK_EX; if (!is_dir($dir) && !System::mkDir('-p -m 0755 ' . $dir)) { return PEAR::raiseError(sprintf(FILE_PASSWD_E_DIR_NOT_CREATED_STR, $dir), FILE_PASSWD_E_DIR_NOT_CREATED); } if (!is_resource($fh = @fopen($file, $mode))) { return PEAR::raiseError(sprintf(FILE_PASSWD_E_FILE_NOT_OPENED_STR, $file), FILE_PASSWD_E_FILE_NOT_OPENED); } if (!@flock($fh, $lock)) { fclose($fh); return PEAR::raiseError(sprintf(FILE_PASSWD_E_FILE_NOT_LOCKED_STR, $file), FILE_PASSWD_E_FILE_NOT_LOCKED); } return $fh; }
/** * Wrapper to System::mkDir(), creates a directory as well as * any necessary parent directories. * * @param string $dir directory name * * @return bool TRUE on success, or a PEAR error * * @access public */ function mkDirHier($dir) { $this->log(2, "+ create dir {$dir}"); if (!class_exists('System')) { require_once 'System.php'; } return System::mkDir(array('-p', $dir)); }
/** * Class constructor * * Defines all necessary constants and sets defaults * * @access public */ function System_Command($in_shell = null) { // Defining constants $this->options = array('SEQUENCE' => true, 'SHUTDOWN' => false, 'SHELL' => $this->which($in_shell), 'OUTPUT' => true, 'NOHUP' => false, 'BACKGROUND' => false, 'STDERR' => false, 'AUTORESET' => false); // prepare the available control operators $this->controlOperators = array('PIPE' => '|', 'AND' => '&&', 'OR' => '||', 'GROUP' => ';', 'LFIFO' => '<', 'RFIFO' => '>'); // List of allowed/available shells $this->shells = array('sh', 'bash', 'zsh', 'tcsh', 'csh', 'ash', 'sash', 'esh', 'ksh'); // Find the first available shell if (empty($this->options['SHELL'])) { foreach ($this->shells as $shell) { if ($this->options['SHELL'] = $this->which($shell)) { break; } } // see if we still have no shell if (empty($this->options['SHELL'])) { $this->_initError =& PEAR::raiseError(null, SYSTEM_COMMAND_NO_SHELL, null, E_USER_WARNING, null, 'System_Command_Error', true); return; } } // Caputre a temporary directory for capturing stderr from commands $this->tmpDir = System::tmpdir(); if (!System::mkDir("-p {$this->tmpDir}")) { $this->_initError =& PEAR::raiseError(null, SYSTEM_COMMAND_TMPDIR_ERROR, null, E_USER_WARNING, null, 'System_Command_Error', true); return; } }
/** * Creates temporary files or directories. This function will remove * the created files when the scripts finish its execution. * * Usage: * 1) $tempfile = System::mktemp("prefix"); * 2) $tempdir = System::mktemp("-d prefix"); * 3) $tempfile = System::mktemp(); * 4) $tempfile = System::mktemp("-t /var/tmp prefix"); * * prefix -> The string that will be prepended to the temp name * (defaults to "tmp"). * -d -> A temporary dir will be created instead of a file. * -t -> The target dir where the temporary (file|dir) will be created. If * this param is missing by default the env vars TMP on Windows or * TMPDIR in Unix will be used. If these vars are also missing * c:\windows\temp or /tmp will be used. * * @param string $args The arguments * @return mixed the full path of the created (file|dir) or false * @see System::tmpdir() * @access public */ function mktemp($args = null) { static $first_time = true; $opts = System::_parseArgs($args, 't:d'); if (PEAR::isError($opts)) { return System::raiseError($opts); } foreach ($opts[0] as $opt) { if ($opt[0] == 'd') { $tmp_is_dir = true; } elseif ($opt[0] == 't') { $tmpdir = $opt[1]; } } $prefix = isset($opts[1][0]) ? $opts[1][0] : 'tmp'; if (!isset($tmpdir)) { $tmpdir = System::tmpdir(); } if (!System::mkDir("-p {$tmpdir}")) { return false; } $tmp = tempnam($tmpdir, $prefix); if (isset($tmp_is_dir)) { unlink($tmp); // be careful possible race condition here if (!call_user_func('mkdir', $tmp, 0700)) { return System::raiseError("Unable to create temporary directory {$tmpdir}"); } } $GLOBALS['_System_temp_files'][] = $tmp; if ($first_time) { PEAR::registerShutdownFunc(array('System', '_removeTmpFiles')); $first_time = false; } return $tmp; }
/** * Wrapper to System::mkDir(), creates a directory as well as * any necessary parent directories. * * @param string $dir directory name * * @return bool TRUE on success, or a PEAR error * * @access public */ function mkDirHier($dir) { $this->log(2, "+ create dir {$dir}"); return System::mkDir(array('-p', $dir)); }
/** * Wrapper to System::mkDir(), creates a directory as well as * any necessary parent directories. * * @param string $dir directory name * * @return bool TRUE on success, or a PEAR error * * @access public */ function mkDirHier($dir) { // Only used in Installer - move it there ? $this->log(2, "+ create dir {$dir}"); if (!class_exists('System')) { require_once 'System.php'; } return System::mkDir(array('-p', $dir)); }
/** * Creates temporary files or directories. This function will remove * the created files when the scripts finish its execution. * * Usage: * 1) $tempfile = System::mktemp("prefix"); * 2) $tempdir = System::mktemp("-d prefix"); * 3) $tempfile = System::mktemp(); * 4) $tempfile = System::mktemp("-t /var/tmp prefix"); * * prefix -> The string that will be prepended to the temp name * (defaults to "tmp"). * -d -> A temporary dir will be created instead of a file. * -t -> The target dir where the temporary (file|dir) will be created. If * this param is missing by default the env vars TMP on Windows or * TMPDIR in Unix will be used. If these vars are also missing * c:\windows\temp or /tmp will be used. * * @param string $args The arguments * @return mixed the full path of the created (file|dir) or false * @see System::tmpdir() * @static * @access public */ function mktemp($args = null) { static $first_time = true; $opts = System::_parseArgs($args, 't:d'); if (PEAR::isError($opts)) { return System::raiseError($opts); } foreach ($opts[0] as $opt) { if ($opt[0] == 'd') { $tmp_is_dir = true; } elseif ($opt[0] == 't') { $tmpdir = $opt[1]; } } $prefix = isset($opts[1][0]) ? $opts[1][0] : 'tmp'; if (!isset($tmpdir)) { $tmpdir = System::tmpdir(); } /* * Magento fix for set tmp dir in config.ini */ if (class_exists('Maged_Controller', false)) { $magedConfig = Maged_Controller::model('Config', true)->load(); if ($magedConfig->get('use_custom_permissions_mode') == '1' && ($mode = $magedConfig->get('mkdir_mode'))) { $result = System::mkDir(array('-m' . $mode, $tmpdir)); } else { $result = System::mkDir(array('-p', $tmpdir)); } if (!$result) { return false; } } // Old realisation //if (!System::mkDir(array('-p', $tmpdir))) { // return false; //} /* * End fix */ $tmp = tempnam($tmpdir, $prefix); if (isset($tmp_is_dir)) { unlink($tmp); // be careful possible race condition here if (!mkdir($tmp, 0700)) { return System::raiseError("Unable to create temporary directory {$tmpdir}"); } } $GLOBALS['_System_temp_files'][] = $tmp; if ($first_time) { PEAR::registerShutdownFunc(array('System', '_removeTmpFiles')); $first_time = false; } return $tmp; }