Редакция 69 | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
69 | alex-w | 1 | <?php |
2 | /** |
||
3 | * PEAR_Installer_Role_Cfg |
||
4 | * |
||
5 | * PHP versions 4 and 5 |
||
6 | * |
||
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license |
||
8 | * that is available through the world-wide-web at the following URI: |
||
9 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of |
||
10 | * the PHP License and are unable to obtain it through the web, please |
||
11 | * send a note to license@php.net so we can mail you a copy immediately. |
||
12 | * |
||
13 | * @category pear |
||
14 | * @package PEAR |
||
15 | * @author Greg Beaver <cellog@php.net> |
||
16 | * @copyright 2007-2008 The PHP Group |
||
17 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
||
18 | * @version CVS: $Id: Cfg.php,v 1.8 2008/05/14 21:26:30 cellog Exp $ |
||
19 | * @link http://pear.php.net/package/PEAR |
||
20 | * @since File available since Release 1.7.0 |
||
21 | */ |
||
22 | |||
23 | /** |
||
24 | * @category pear |
||
25 | * @package PEAR |
||
26 | * @author Greg Beaver <cellog@php.net> |
||
27 | * @copyright 2007-2008 The PHP Group |
||
28 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
||
29 | * @version Release: 1.7.2 |
||
30 | * @link http://pear.php.net/package/PEAR |
||
31 | * @since Class available since Release 1.7.0 |
||
32 | */ |
||
33 | class PEAR_Installer_Role_Cfg extends PEAR_Installer_Role_Common |
||
34 | { |
||
35 | /** |
||
36 | * @var PEAR_Installer |
||
37 | */ |
||
38 | var $installer; |
||
39 | /** |
||
40 | * the md5 of the original file |
||
41 | * |
||
42 | * @var unknown_type |
||
43 | */ |
||
44 | var $md5 = null; |
||
45 | /** |
||
46 | * Do any unusual setup here |
||
47 | * @param PEAR_Installer |
||
48 | * @param PEAR_PackageFile_v2 |
||
49 | * @param array file attributes |
||
50 | * @param string file name |
||
51 | */ |
||
52 | function setup(&$installer, $pkg, $atts, $file) |
||
53 | { |
||
54 | $this->installer = &$installer; |
||
55 | $reg = &$this->installer->config->getRegistry(); |
||
56 | $package = $reg->getPackage($pkg->getPackage(), $pkg->getChannel()); |
||
57 | if ($package) { |
||
58 | $filelist = $package->getFilelist(); |
||
59 | if (isset($filelist[$file]) && isset($filelist[$file]['md5sum'])) { |
||
60 | $this->md5 = $filelist[$file]['md5sum']; |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | |||
65 | function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null) |
||
66 | { |
||
67 | $test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer); |
||
68 | if (@file_exists($test[2]) && @file_exists($test[3])) { |
||
69 | $md5 = md5_file($test[2]); |
||
70 | // configuration has already been installed, check for mods |
||
71 | if ($md5 !== $this->md5 && $md5 !== md5_file($test[3])) { |
||
72 | // configuration has been modified, so save our version as |
||
73 | // configfile-version |
||
74 | $old = $test[2]; |
||
75 | $test[2] .= '.new-' . $pkg->getVersion(); |
||
76 | // backup original and re-install it |
||
77 | PEAR::pushErrorHandling(PEAR_ERROR_RETURN); |
||
78 | $tmpcfg = $this->config->get('temp_dir'); |
||
79 | $newloc = System::mkdir(array('-p', $tmpcfg)); |
||
80 | if (!$newloc) { |
||
81 | // try temp_dir |
||
82 | $newloc = System::mktemp(array('-d')); |
||
83 | if (!$newloc || PEAR::isError($newloc)) { |
||
84 | PEAR::popErrorHandling(); |
||
85 | return PEAR::raiseError('Could not save existing configuration file '. |
||
86 | $old . ', unable to install. Please set temp_dir ' . |
||
87 | 'configuration variable to a writeable location and try again'); |
||
88 | } |
||
89 | } else { |
||
90 | $newloc = $tmpcfg; |
||
91 | } |
||
92 | $temp_file = $newloc . DIRECTORY_SEPARATOR . uniqid('savefile'); |
||
93 | if (!@copy($old, $temp_file)) { |
||
94 | PEAR::popErrorHandling(); |
||
95 | return PEAR::raiseError('Could not save existing configuration file '. |
||
96 | $old . ', unable to install. Please set temp_dir ' . |
||
97 | 'configuration variable to a writeable location and try again'); |
||
98 | } |
||
99 | PEAR::popErrorHandling(); |
||
100 | $this->installer->log(0, "WARNING: configuration file $old is being installed as $test[2], you should manually merge in changes to the existing configuration file"); |
||
101 | $this->installer->addFileOperation('rename', array($temp_file, $old, false)); |
||
102 | $this->installer->addFileOperation('delete', array($temp_file)); |
||
103 | } |
||
104 | } |
||
105 | return $test; |
||
106 | } |
||
107 | } |
||
108 | ?> |