cvs: php4 /pear/PEAR Installer.php

From: Date: Sun, 10 Nov 2002 03:13:31 +0000
Subject: cvs: php4 /pear/PEAR Installer.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-7338@lists.php.net to get a copy of this message
ssb Sat Nov 9 22:13:31 2002 EDT Modified files: /php4/pear/PEAR Installer.php Log: * implement transactions for uninstall * change "revert" to "rollback" Index: php4/pear/PEAR/Installer.php diff -u php4/pear/PEAR/Installer.php:1.80 php4/pear/PEAR/Installer.php:1.81 --- php4/pear/PEAR/Installer.php:1.80 Sat Nov 9 22:03:20 2002 +++ php4/pear/PEAR/Installer.php Sat Nov 9 22:13:31 2002 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: Installer.php,v 1.80 2002/11/10 03:03:20 ssb Exp $ +// $Id: Installer.php,v 1.81 2002/11/10 03:13:31 ssb Exp $ require_once 'PEAR/Common.php'; require_once 'PEAR/Registry.php'; @@ -145,15 +145,7 @@ continue; } $path = $this->_prependPath($props['installed_as'], $this->installroot); - if (!@unlink($path)) { - $this->log(2, "unable to delete: $path"); - } else { - $this->log(2, "deleted file $path"); - // Delete package directory if it's empty - if (@rmdir(dirname($path))) { - $this->log(3, "+ rmdir $path"); - } - } + $this->addFileOperation('delete', array($path)); } return true; } @@ -320,10 +312,10 @@ // }}} // {{{ startFileTransaction() - function startFileTransaction($revert_in_case = false) + function startFileTransaction($rollback_in_case = false) { - if (count($this->file_operations) && $revert_in_case) { - $this->revertFileTransaction(); + if (count($this->file_operations) && $rollback_in_case) { + $this->rollbackFileTransaction(); } $this->file_operations = array(); } @@ -374,12 +366,19 @@ switch ($type) { case 'rename': @rename($data[0], $data[1]); + $this->log(3, "+ mv $data[0] $data[1]"); break; case 'chmod': @chmod($data[0], $data[1]); + $this->log(3, "+ chmod $data[0] $data[1]"); break; case 'delete': @unlink($data[0]); + $this->log(3, "+ rm $data[0]"); + break; + case 'rmdir': + @rmdir($data[0]); + $this->log(3, "+ rmdir $data[0]"); break; } } @@ -389,12 +388,12 @@ } // }}} - // {{{ revertFileTransaction() + // {{{ rollbackFileTransaction() - function revertFileTransaction() + function rollbackFileTransaction() { $n = count($this->file_operations); - $this->log(2, "reverting $n file operations"); + $this->log(2, "rolling back $n file operations"); foreach ($this->file_operations as $tr) { list($type, $data) = $tr; switch ($type) { @@ -437,7 +436,7 @@ function mkDirHier($dir) { - $this->addFileOperation('mkdir', $dir); + $this->addFileOperation('mkdir', array($dir)); return parent::mkDirHier($dir); } @@ -681,7 +680,7 @@ $this->popExpect(); if (PEAR::isError($res)) { if (empty($options['force'])) { - $this->revertFileTransaction(); + $this->rollbackFileTransaction(); return $this->raiseError($res); } else { $this->log(0, "Warning: " . $res->getMessage()); @@ -699,7 +698,7 @@ $bob->debug = $this->debug; $built = $bob->build($descfile, array(&$this, '_buildCallback')); if (PEAR::isError($built)) { - $this->revertFileTransaction(); + $this->rollbackFileTransaction(); return $built; } foreach ($built as $ext) { @@ -709,7 +708,7 @@ $this->log(3, "+ cp $ext[file] ext_dir"); $copyto = $this->_prependPath($dest, $this->installroot); if (!@copy($ext['file'], $copyto)) { - $this->revertFileTransaction(); + $this->rollbackFileTransaction(); return $this->raiseError("failed to copy $bn to $copyto"); } $pkginfo['filelist'][$bn] = array( @@ -724,7 +723,7 @@ } if (!$this->commitFileTransaction()) { - $this->revertFileTransaction(); + $this->rollbackFileTransaction(); return $this->raiseError("commit failed", PEAR_INSTALLER_FAILED); } @@ -763,7 +762,12 @@ // Delete the files if (PEAR::isError($err = $this->_deletePackageFiles($package))) { + $this->rollbackFileTransaction(); return $this->raiseError($err); + } + if (!$this->commitFileTransaction()) { + $this->rollbackFileTransaction(); + return $this->raiseError("uninstall failed"); } // Register that the package is no longer installed

« previous php.pear.cvs (#7338) next »