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