]> granicus.if.org Git - php/commitdiff
* use System::mktemp
authorStig Bakken <ssb@php.net>
Sun, 7 Jul 2002 21:10:29 +0000 (21:10 +0000)
committerStig Bakken <ssb@php.net>
Sun, 7 Jul 2002 21:10:29 +0000 (21:10 +0000)
* check if an install is about to overwrite existing files belonging
  to other packages, bail out if not in "force" mode

pear/PEAR/Installer.php

index f1351c9473f698b4bcf208827b382b4c1bfb7b8c..c37eddf40c06e6575ae6a484813460d687965387 100644 (file)
@@ -22,6 +22,7 @@
 require_once 'PEAR/Common.php';
 require_once 'PEAR/Registry.php';
 require_once 'PEAR/Dependency.php';
+require_once 'System.php';
 
 define('PEAR_INSTALLER_OK',       1);
 define('PEAR_INSTALLER_FAILED',   0);
@@ -332,7 +333,7 @@ class PEAR_Installer extends PEAR_Common
         if ($need_download) {
             $downloaddir = $this->config->get('download_dir');
             if (empty($downloaddir)) {
-                if (PEAR::isError($downloaddir = $this->mkTempDir())) {
+                if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
                     return $downloaddir;
                 }
                 $this->log(2, '+ tmp dir created at ' . $downloaddir);
@@ -357,7 +358,7 @@ class PEAR_Installer extends PEAR_Common
                 chdir($oldcwd);
             }
 
-            if (PEAR::isError($tmpdir = $this->mkTempDir())) {
+            if (PEAR::isError($tmpdir = System::mktemp('-d'))) {
                 return $tmpdir;
             }
             $this->log(2, '+ tmp dir created at ' . $tmpdir);
@@ -415,6 +416,28 @@ class PEAR_Installer extends PEAR_Common
             }
         }
 
+        if (empty($options['force'])) {
+            // checks to do when not in "force" mode
+            $test = $this->registry->checkFileMap($pkginfo);
+            if (sizeof($test)) {
+                $tmp = $test;
+                foreach ($tmp as $file => $pkg) {
+                    if ($pkg == $pkgname) {
+                        unset($test[$file]);
+                    }
+                }
+                if (sizeof($test)) {
+                    $msg = "$pkgname: conflicting files found:\n";
+                    $longest = max(array_map("strlen", array_keys($test)));
+                    $fmt = "%${longest}s (%s)\n";
+                    foreach ($test as $file => $pkg) {
+                        $msg .= sprintf($fmt, $file, $pkg);
+                    }
+                    return $this->raiseError($msg);
+                }
+            }
+        }
+
         if (empty($options['upgrade'])) {
             // checks to do only when installing new packages
             if (empty($options['force']) && $this->registry->packageExists($pkgname)) {