Пример #1
0
 /**
  * Uninstall a package
  *
  * This method removes all files installed by the application, and then
  * removes any empty directories.
  * @param string package name
  * @param array Command-line options.  Possibilities include:
  *
  *              - installroot: base installation dir, if not the default
  *              - nodeps: do not process dependencies of other packages to ensure
  *                        uninstallation does not break things
  */
 function uninstall($package, $options = array())
 {
     $php_dir = $this->config->get('php_dir');
     if (isset($options['installroot'])) {
         if (substr($options['installroot'], -1) == DIRECTORY_SEPARATOR) {
             $options['installroot'] = substr($options['installroot'], 0, -1);
         }
         $this->installroot = $options['installroot'];
         $php_dir = $this->_prependPath($php_dir, $this->installroot);
     } else {
         $this->installroot = '';
     }
     $this->registry = new PEAR_Registry($php_dir);
     $filelist = $this->registry->packageInfo($package, 'filelist');
     if ($filelist == null) {
         return $this->raiseError("{$package} not installed");
     }
     if (empty($options['nodeps'])) {
         $depchecker = new PEAR_Dependency($this->registry);
         $error = $depchecker->checkPackageUninstall($errors, $warning, $package);
         if ($error) {
             return $this->raiseError($errors . 'uninstall failed');
         }
         if ($warning) {
             $this->log(0, $warning);
         }
     }
     // {{{ Delete the files
     $this->startFileTransaction();
     if (PEAR::isError($err = $this->_deletePackageFiles($package))) {
         $this->rollbackFileTransaction();
         return $this->raiseError($err);
     }
     if (!$this->commitFileTransaction()) {
         $this->rollbackFileTransaction();
         return $this->raiseError("uninstall failed");
     } else {
         $this->startFileTransaction();
         if (!isset($filelist['dirtree']) || !count($filelist['dirtree'])) {
             return $this->registry->deletePackage($package);
         }
         // attempt to delete empty directories
         uksort($filelist['dirtree'], array($this, '_sortDirs'));
         foreach ($filelist['dirtree'] as $dir => $notused) {
             $this->addFileOperation('rmdir', array($dir));
         }
         if (!$this->commitFileTransaction()) {
             $this->rollbackFileTransaction();
         }
     }
     // }}}
     // Register that the package is no longer installed
     return $this->registry->deletePackage($package);
 }