本文整理汇总了PHP中System::mkDir方法的典型用法代码示例。如果您正苦于以下问题:PHP System::mkDir方法的具体用法?PHP System::mkDir怎么用?PHP System::mkDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System::mkDir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeConfigFile
/**
* 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;
}
示例2: build
/**
* 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 = 'defaultuser';
}
$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);
//.........这里部分代码省略.........
示例3: build
/**
* 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 = 'defaultuser';
}
$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}");
//.........这里部分代码省略.........
示例4: writeConfigFile
/**
* 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;
}
示例5: build
/**
* 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 = 'defaultuser';
}
$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");
}
}
//.........这里部分代码省略.........
示例6: toPackageFile
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;
}
示例7: mkDirHier
/**
* 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));
}
示例8: postProcessConfigVars
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");
}
}
}
}
示例9: sprintf
$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':
示例10: mkDirHier
/**
* 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));
}
示例11: build
//.........这里部分代码省略.........
// 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 = 'defaultuser';
}
$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;
}
示例12: mktemp
/**
* 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;
}
示例13: mkDirHier
/**
* 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}");
}
示例14: isset
/**
* 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;
}
示例15: mkDirHier
/**
* 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));
}