]> granicus.if.org Git - php/commitdiff
* actually implement -s/-S options :-)
authorStig Bakken <ssb@php.net>
Sat, 27 Oct 2001 07:52:12 +0000 (07:52 +0000)
committerStig Bakken <ssb@php.net>
Sat, 27 Oct 2001 07:52:12 +0000 (07:52 +0000)
pear/PEAR/Config.php
pear/scripts/pear.in

index 6c36e9b98153a93bb684cde385b0766f4b4cae88..88f6e9bbcf5f44f0d95bcdcf1150ca7d5043b9e1 100644 (file)
@@ -80,9 +80,10 @@ class PEAR_Config extends PEAR
         if (!$fp) {
             return $this->raiseError($php_errormsg);
         }
-        $contents = fread($fp, filesize($file));
+        $size = filesize($file);
+        $contents = fread($fp, $size);
         $data = unserialize($contents);
-        if ($data === false) {
+        if ($data === false && $size > 1) {
             return $this->raiseError("PEAR_Config::readConfigFile: bad data");
         }
         $this->configuration = $data;
@@ -123,10 +124,10 @@ class PEAR_Config extends PEAR
 
     function writeConfigFile($file = null, $what_keys = 'userdefined')
     {
-        print "storing $what_keys keys\n";
         if ($what_keys == 'both') {
             $this->writeConfigFile($file, 'userdefined');
             $this->writeConfigFile($file, 'default');
+            return;
         }
         if ($file === null) {
             if ($what_keys == 'default') {
@@ -150,7 +151,7 @@ class PEAR_Config extends PEAR
         }
         $fp = @fopen($file, "w");
         if (!$fp) {
-            return $this->raiseError("PEAR_Config::writeConfigFile fopen failed");
+            return $this->raiseError("PEAR_Config::writeConfigFile fopen('$file','w') failed");
         }
         if (!@fwrite($fp, serialize($data))) {
             return $this->raiseError("PEAR_Config::writeConfigFile serialize failed");
index ecdfa881025dd69327b5daa32f4539219d8e4c24..5cd2633224d560508e89e1fc5d82f57e6054eb0f 100644 (file)
@@ -24,6 +24,8 @@ require_once 'Console/Getopt.php';
 
 error_reporting(E_ALL ^ E_NOTICE);
 
+PEAR::setErrorHandling(PEAR_ERROR_PRINT, "pear: %s\n");
+
 // {{{ config file and option parsing
 
 $options = Console_Getopt::getopt($argv, "c:C:d:D:h?sS");
@@ -76,6 +78,18 @@ foreach ($opts as $opt) {
     }
 }
 
+if ($store_default_config) {
+    if (@is_writeable($pear_default_config)) {
+        $config->writeConfigFile($pear_default_config, 'default');
+    } else {
+        die("You don't have write access to $pear_default_config, exiting!\n");
+    }
+}
+
+if ($store_user_config) {
+    $config->writeConfigFile($pear_user_config, 'userdefined');
+}
+
 $fallback_config = array(
     'php_dir' => PEAR_INSTALL_DIR,
     'ext_dir' => PEAR_EXTENSION_DIR,
@@ -96,8 +110,6 @@ $doc_dir    = $config->get("doc_dir");
 
 // }}}
 
-PEAR::setErrorHandling(PEAR_ERROR_PRINT, "pear: %s\n");
-
 $command = $options[1][1];
 switch ($command) {
     // {{{ install