diff options
| author | Stig Bakken <ssb@php.net> | 2002-12-27 19:31:37 +0000 |
|---|---|---|
| committer | Stig Bakken <ssb@php.net> | 2002-12-27 19:31:37 +0000 |
| commit | 25684764cc2f1a6575f9d83220f184a2a71057c5 (patch) | |
| tree | ff8c3c4566bfa2f9d1a0766321d40ef592480b4f /pear/PEAR/Command/Remote.php | |
| parent | 1d42e34c1b41e061a8fc1f98fbe974469f1ad6d0 (diff) | |
| download | php-git-25684764cc2f1a6575f9d83220f184a2a71057c5.tar.gz | |
* added "clear-cache" command
Diffstat (limited to 'pear/PEAR/Command/Remote.php')
| -rw-r--r-- | pear/PEAR/Command/Remote.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pear/PEAR/Command/Remote.php b/pear/PEAR/Command/Remote.php index ac4c17f216..265dc4cab6 100644 --- a/pear/PEAR/Command/Remote.php +++ b/pear/PEAR/Command/Remote.php @@ -88,6 +88,16 @@ Download a package tarball. The file will be named as suggested by the server, for example if you download the DB package and the latest stable version of DB is 1.2, the downloaded file will be DB-1.2.tgz.', ), + 'clear-cache' => array( + 'summary' => 'Clear XML-RPC Cache', + 'function' => 'doClearCache', + 'shortcut' => 'cc', + 'options' => array(), + 'doc' => ' +Clear the XML-RPC cache. See also the cache_ttl configuration +parameter. +', + ), ); // }}} @@ -355,6 +365,43 @@ version of DB is 1.2, the downloaded file will be DB-1.2.tgz.', } // }}} + // {{{ doClearCache() + + function doClearCache($command, $options, $params) + { + $cache_dir = $this->config->get('cache_dir'); + $verbose = $this->config->get('verbose'); + $output = ''; + if (!($dp = @opendir($cache_dir))) { + return $this->raiseError("opendir($cache_dir) failed: $php_errormsg"); + } + if ($verbose >= 1) { + $output .= "reading directory $cache_dir\n"; + } + $num = 0; + while ($ent = readdir($dp)) { + if (preg_match('/^xmlrpc_cache_[a-z0-9]{32}$/', $ent)) { + $path = $cache_dir . DIRECTORY_SEPARATOR . $ent; + $ok = @unlink($path); + if ($ok) { + if ($verbose >= 2) { + $output .= "deleted $path\n"; + } + $num++; + } elseif ($verbose >= 1) { + $output .= "failed to delete $path\n"; + } + } + } + closedir($dp); + if ($verbose >= 1) { + $output .= "$num cache entries cleared\n"; + } + $this->ui->outputData(rtrim($output), $command); + return $num; + } + + // }}} } ?> |
