]> granicus.if.org Git - php/commitdiff
Now empty directories are removed on uninstall, so uninstallation is complete and...
authorGreg Beaver <cellog@php.net>
Mon, 15 Sep 2003 05:10:51 +0000 (05:10 +0000)
committerGreg Beaver <cellog@php.net>
Mon, 15 Sep 2003 05:10:51 +0000 (05:10 +0000)
pear/PEAR/Installer.php
pear/package-PEAR.xml

index fc2196fc5e4c1179623d976abbe1b31797d36697..c5074c08ccfff8eee3a7e96214766130e3a3430a 100644 (file)
@@ -199,6 +199,7 @@ class PEAR_Installer extends PEAR_Common
             default:
                 return $this->raiseError("Invalid role `$atts[role]' for file $file");
         }
+        $save_destdir = $dest_dir;
         if (!empty($atts['baseinstalldir'])) {
             $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
         }
@@ -315,7 +316,8 @@ class PEAR_Installer extends PEAR_Common
         }
         $this->addFileOperation("rename", array($dest_file, $final_dest_file));
         // Store the full path where the file was installed for easy unistall
-        $this->addFileOperation("installed_as", array($file, $installed_as));
+        $this->addFileOperation("installed_as", array($file, $installed_as,
+                                $save_destdir, dirname(substr($dest_file, strlen($save_destdir)))));
 
         //$this->log(2, "installed: $dest_file");
         return PEAR_INSTALLER_OK;
@@ -410,6 +412,14 @@ class PEAR_Installer extends PEAR_Common
                     break;
                 case 'installed_as':
                     $this->pkginfo['filelist'][$data[0]]['installed_as'] = $data[1];
+                    if (!isset($this->pkginfo['filelist']['dirtree'][dirname($data[1])])) {
+                        $this->pkginfo['filelist']['dirtree'][dirname($data[1])] = true;
+                        while(!empty($data[3]) && $data[3] != '/' && $data[3] != '\\') {
+                            $this->pkginfo['filelist']['dirtree']
+                                [$this->_prependPath($data[3], $data[2])] = true;
+                            $data[3] = dirname($data[3]);
+                        }
+                    }
                     break;
             }
         }
@@ -1052,6 +1062,16 @@ class PEAR_Installer extends PEAR_Common
     // }}}
     // {{{ uninstall()
 
+    /**
+     * 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
+     */
     function uninstall($package, $options = array())
     {
         $php_dir = $this->config->get('php_dir');
@@ -1087,12 +1107,31 @@ class PEAR_Installer extends PEAR_Common
         if (!$this->commitFileTransaction()) {
             $this->rollbackFileTransaction();
             return $this->raiseError("uninstall failed");
+        } else {
+            $this->startFileTransaction();
+            // 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);
     }
 
+    // }}}
+    // {{{ _sortDirs()
+    function _sortDirs($a, $b)
+    {
+        if (strnatcmp($a, $b) == -1) return 1;
+        if (strnatcmp($a, $b) == 1) return -1;
+        return 0;
+    }
+
     // }}}
     // {{{ checkDeps()
 
index b378482af4ef5ecbfbf73d03f9793aeb50b26842..9523931cbc6bd4e7d0599c3817ce6c44c24bb11c 100644 (file)
@@ -66,6 +66,7 @@ use of inadvisable @ in setErrorHandling
 * Fix #25008 - unhelpful error message
 * Fixed optional dependencies in Dependency.php
 * Fix #25322 - bad md5sum should be fatal error
+* Package uninstall now also removes empty directories
     </notes>
     <provides type="class" name="OS_Guess" />
     <provides type="class" name="System" />