From a0d4336fa5f8f5dbfac05692b255ab61c6c5c9a9 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Thu, 7 May 2015 13:16:07 -0300 Subject: Rework sync_package, remove unused parameters, remove sync_depends, sanitize returns --- etc/inc/pkg-utils.inc | 75 +++++++++++---------------------------------------- etc/rc.start_packages | 2 +- 2 files changed, 17 insertions(+), 60 deletions(-) (limited to 'etc') diff --git a/etc/inc/pkg-utils.inc b/etc/inc/pkg-utils.inc index dc28a5c..0cfb124 100644 --- a/etc/inc/pkg-utils.inc +++ b/etc/inc/pkg-utils.inc @@ -204,7 +204,7 @@ function resync_all_package_configs($show_message = false) { if (platform_booting() != true) { stop_service(get_package_internal_name($package)); } - sync_package($idx, true, true); + sync_package($package['name']); if ($pkg_interface == "console") { echo "\n" . gettext("Syncing packages:"); } @@ -335,12 +335,9 @@ function uninstall_package($pkg_name) { update_output_window($static_output); } -/* - * sync_package($pkg_name, $sync_depends = true, $show_message = false) Force a package to setup its configuration and rc.d files. - */ -function sync_package($pkg_name, $sync_depends = true, $show_message = false) { - global $config; - global $builder_package_install; +/* Run */ +function sync_package($package_name) { + global $config, $builder_package_install; // If this code is being called by pfspkg_installer // which the builder system uses then return (ignore). @@ -351,13 +348,9 @@ function sync_package($pkg_name, $sync_depends = true, $show_message = false) { if (empty($config['installedpackages']['package'])) { return; } - if (!is_numeric($pkg_name)) { - $pkg_id = get_package_id($pkg_name); - if ($pkg_id == -1) { - return -1; // This package doesn't really exist - exit the function. - } - } else { - $pkg_id = $pkg_name; + + if (($pkg_id = get_package_id($package_name)) == -1) { + return; // This package doesn't really exist - exit the function. } if (!is_array($config['installedpackages']['package'][$pkg_id])) { @@ -368,24 +361,30 @@ function sync_package($pkg_name, $sync_depends = true, $show_message = false) { if (!file_exists("/usr/local/pkg/" . $package['configurationfile'])) { log_error(sprintf(gettext("The %s package is missing its configuration file and must be reinstalled."), $package['name'])); delete_package_xml($package['name']); - return -1; + return; } + $pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui"); if (isset($pkg_config['nosync'])) { return; } + /* Bring in package include files */ if (!empty($pkg_config['include_file'])) { $include_file = $pkg_config['include_file']; if (file_exists($include_file)) { require_once($include_file); } else { - /* XXX: What the heck is this?! */ log_error("Reinstalling package {$package['name']} because its include file({$include_file}) is missing!"); uninstall_package($package['name']); if (install_package($package['name']) < 0) { log_error("Reinstalling package {$package['name']} failed. Take appropriate measures!!!"); - return -1; + return; + } + if (file_exists($include_file)) { + require_once($include_file); + } else { + return; } } } @@ -396,48 +395,6 @@ function sync_package($pkg_name, $sync_depends = true, $show_message = false) { if (!empty($pkg_config['custom_php_resync_config_command'])) { eval($pkg_config['custom_php_resync_config_command']); } - if ($sync_depends == true) { - $depends = get_pkg_depends($pkg_name, ".xml", "files", 1); // Call dependency handler and do a little more error checking. - if (is_array($depends)) { - foreach ($depends as $item) { - if (!file_exists($item)) { - require_once("notices.inc"); - file_notice($package['name'], sprintf(gettext("The %s package is missing required dependencies and must be reinstalled."), $package['name']), "Packages", "/pkg_mgr_install.php?mode=reinstallpkg&pkg={$package['name']}", 1); - log_error("Could not find {$item}. Reinstalling package."); - uninstall_package($pkg_name); - if (install_package($pkg_name) < 0) { - log_error("Reinstalling package {$package['name']} failed. Take appropriate measures!!!"); - return -1; - } - } else { - $item_config = parse_xml_config_pkg($item, "packagegui"); - if (empty($item_config)) { - continue; - } - if (isset($item_config['nosync'])) { - continue; - } - if (!empty($item_config['include_file'])) { - if (file_exists($item_config['include_file'])) { - require_once($item_config['include_file']); - } else { - log_error("Not calling package sync code for dependency {$item_config['name']} of {$package['name']} because some include files are missing."); - continue; - } - } - if ($item_config['custom_php_global_functions'] <> "") { - eval($item_config['custom_php_global_functions']); - } - if ($item_config['custom_php_resync_config_command'] <> "") { - eval($item_config['custom_php_resync_config_command']); - } - if ($show_message == true) { - print " " . $item_config['name']; - } - } - } - } - } } /* diff --git a/etc/rc.start_packages b/etc/rc.start_packages index df074a9..66f4f63 100755 --- a/etc/rc.start_packages +++ b/etc/rc.start_packages @@ -65,7 +65,7 @@ if (!$rcfiles) { if (is_array($config['installedpackages']['package'])) { foreach ($config['installedpackages']['package'] as $pkgid => $package) { echo " Starting package {$package['name']}..."; - sync_package($pkgid); + sync_package($package['name']); $internal_name = get_package_internal_name($package); start_service($internal_name); unset($rcfiles[RCFILEPREFIX . strtolower($internal_name) . ".sh"]); -- cgit v1.1