Bearsampp 2026.9.23
Loading...
Searching...
No Matches
Cfg.php
Go to the documentation of this file.
1<?php
15
27{
32
38 var $md5 = null;
39
47 function setup(&$installer, $pkg, $atts, $file)
48 {
49 $this->installer = &$installer;
50 $reg = &$this->installer->config->getRegistry();
51 $package = $reg->getPackage($pkg->getPackage(), $pkg->getChannel());
52 if ($package) {
53 $filelist = $package->getFilelist();
54 if (isset($filelist[$file]) && isset($filelist[$file]['md5sum'])) {
55 $this->md5 = $filelist[$file]['md5sum'];
56 }
57 }
58 }
59
60 function processInstallation($pkg, $atts, $file, $tmp_path, $layer = null)
61 {
62 $test = parent::processInstallation($pkg, $atts, $file, $tmp_path, $layer);
63 if (@file_exists($test[2]) && @file_exists($test[3])) {
64 $md5 = md5_file($test[2]);
65 // configuration has already been installed, check for mods
66 if ($md5 !== $this->md5 && $md5 !== md5_file($test[3])) {
67 // configuration has been modified, so save our version as
68 // configfile-version
69 $old = $test[2];
70 $test[2] .= '.new-' . $pkg->getVersion();
71 // backup original and re-install it
72 PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
73 $tmpcfg = $this->config->get('temp_dir');
74 $newloc = System::mkdir(array('-p', $tmpcfg));
75 if (!$newloc) {
76 // try temp_dir
77 $newloc = System::mktemp(array('-d'));
78 if (!$newloc || PEAR::isError($newloc)) {
79 PEAR::popErrorHandling();
80 return PEAR::raiseError('Could not save existing configuration file '.
81 $old . ', unable to install. Please set temp_dir ' .
82 'configuration variable to a writeable location and try again');
83 }
84 } else {
85 $newloc = $tmpcfg;
86 }
87
88 $temp_file = $newloc . DIRECTORY_SEPARATOR . uniqid('savefile');
89 if (!@copy($old, $temp_file)) {
90 PEAR::popErrorHandling();
91 return PEAR::raiseError('Could not save existing configuration file '.
92 $old . ', unable to install. Please set temp_dir ' .
93 'configuration variable to a writeable location and try again');
94 }
95
96 PEAR::popErrorHandling();
97 $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");
98 $this->installer->addFileOperation('rename', array($temp_file, $old, false));
99 $this->installer->addFileOperation('delete', array($temp_file));
100 }
101 }
102
103 return $test;
104 }
105}
const PEAR_ERROR_RETURN
Definition PEAR.php:24
processInstallation($pkg, $atts, $file, $tmp_path, $layer=null)
Definition Cfg.php:60
setup(&$installer, $pkg, $atts, $file)
Definition Cfg.php:47