Project

General

Profile

« Previous | Next » 

Revision 8059acb5

Added by Phil Davis over 13 years ago

Handle mixed-case package names like squidGuard.
Check that conf files in PBI folders exist before unlink.
Pass correct package names 1 at a time from uninstalll_package to delete_package.
log_error if the PBI package name can't be found in remove_freebsd_package - this means that the PBI files will not get cleaned up. Usually this is caused because the system has been rebooted since the package was installed and the PBI db in /var/db/pbi has gone (e.g. on nanobsd /var is created from scratch at boot)

View differences:

etc/inc/pkg-utils.inc
99 99
 *   
100 100
 ******/
101 101
function remove_freebsd_package($packagestring) {
102
	// The packagestring passed in must be the full PBI package name, 
103
	// as displayed by the pbi_info utility. e.g. "package-1.2.3_4-i386" 
104
	// It must NOT have ".pbi" on the end.
102 105
	exec("/usr/local/sbin/pbi_info {$packagestring} | /usr/bin/awk '/Prefix/ {print $2}'",$pbidir);
103 106
	$pbidir = $pbidir[0];
104
	$linkdirs = array('bin','sbin');
105
	foreach($linkdirs as $dir) {
106
		if(is_dir("{$pbidir}/{$dir}")) {
107
			$files = scandir("{$pbidir}/{$dir}");
108
			foreach($files as $f) {
109
				if($f != '.' && $f != '..') {
110
					unlink("/usr/local/{$dir}/{$f}");
107
	if ($pbidir == "") {
108
		log_error("PBI dir for {$packagestring} was not found - cannot cleanup PBI files");
109
	}
110
	else {
111
		$linkdirs = array('bin','sbin');
112
		foreach($linkdirs as $dir) {
113
			if(is_dir("{$pbidir}/{$dir}")) {
114
				$files = scandir("{$pbidir}/{$dir}");
115
				foreach($files as $f) {
116
					if($f != '.' && $f != '..') {
117
						unlink("/usr/local/{$dir}/{$f}");
118
					}
111 119
				}
112 120
			}
113 121
		}
114
	}
115 122

  
116
	exec("/usr/local/sbin/pbi_delete {$packagestring} 2>>/tmp/pbi_delete_errors.txt");
123
		exec("/usr/local/sbin/pbi_delete {$packagestring} 2>>/tmp/pbi_delete_errors.txt");
124
	}
117 125
}
118 126

  
119 127
/****f* pkg-utils/is_package_installed
......
352 360
			foreach ($pkg_depends as $pkg_depend)
353 361
				delete_package($pkg_depend);
354 362
		} else {
355
			delete_package($pkg_depends);
363
			// The packages (1 or more) are all in one long string.
364
			// We need to pass them 1 at a time to delete_package.
365
			// Compress any multiple whitespace (sp, tab, cr, lf...) into a single space char.
366
			$pkg_dep_str = preg_replace("'\s+'", ' ', $pkg_depends);
367
			// Get rid of any leading or trailing space.
368
			$pkg_dep_str = trim($pkg_dep_str);
369
			// Now we have a space-separated string. Make it into an array and process it.
370
			$pkg_dep_array = explode(" ", $pkg_dep_str);
371
			foreach ($pkg_dep_array as $pkg_depend) {
372
				delete_package($pkg_depend);
373
			}
356 374
		}
357 375
	}
358 376
	delete_package_xml($pkg_name);
......
794 812
				 *	change packages to store configs at /usr/pbi/pkg/etc and remove this
795 813
				 */
796 814
				eval_once($pkg_config['custom_php_install_command']);
797
				exec("/usr/local/sbin/pbi_info | grep {$pkg}- | xargs /usr/local/sbin/pbi_info | awk '/Prefix/ {print $2}'",$pbidirarray);
815
				// Note: pkg may be mixed-case, e.g. "squidGuard" but the PBI names are lowercase.
816
				// e.g. "squidguard-1.4_4-i386" so feed lowercase to pbi_info below.
817
				// Also add the "-" so that examples like "squid-" do not match "squidguard-".
818
				$pkg_name_for_pbi_match = strtolower($pkg) . "-";
819
				exec("/usr/local/sbin/pbi_info | grep {$pkg_name_for_pbi_match}- | xargs /usr/local/sbin/pbi_info | awk '/Prefix/ {print $2}'",$pbidirarray);
798 820
				$pbidir0 = $pbidirarray[0];
799 821
				exec("find /usr/local/etc/ -name *.conf | grep {$pkg}",$files);
800 822
				foreach($files as $f) {
801 823
					$pbiconf = str_replace('/usr/local',$pbidir0,$f);
802
					unlink($pbiconf);
824
					if (is_file($pbiconf) || is_link($pbiconf)) {
825
						unlink($pbiconf);
826
					}
803 827
					symlink($f,$pbiconf);
804 828
				}
805 829
				eval_once($pkg_config['custom_php_install_command']);
......
906 930
	if(!$pkg) 
907 931
		return;
908 932

  
933
	// Note: $pkg has the full PBI package name followed by ".pbi". Strip off ".pbi".
909 934
	$pkg = substr(reverse_strrchr($pkg, "."), 0, -1);
910 935

  
911 936
	if($pkg)

Also available in: Unified diff