COPKGManager: use config file for bad package detection

To detect bad packages, it must be existing a matching pattern list file.
Path is defined in OPKG_BAD_PATTERN_LIST_FILE.
This gives the option to filter some bad entries in the package listing menue.
NOTE: a sample file you should find here as : "/var/tuxbox/config/bad_package_pattern.list.sample".
If required, remove the ".sample" extension and change the entries for your requirements


Origin commit data
------------------
Commit: 9345f792a7
Author: Thilo Graf <dbt@novatux.de>
Date: 2015-06-11 (Thu, 11 Jun 2015)
This commit is contained in:
2015-06-11 10:27:08 +02:00
parent b365d430bb
commit c190f485de
4 changed files with 64 additions and 22 deletions

View File

@@ -5,7 +5,7 @@ SUBDIRS += lcd
endif
configdir = $(CONFIGDIR)
config_DATA = cables.xml satellites.xml encoding.conf tobackup.conf providermap.xml settingsupdate.conf terrestrial.xml
config_DATA = cables.xml satellites.xml encoding.conf tobackup.conf providermap.xml settingsupdate.conf terrestrial.xml bad_package_pattern.list.sample
install-data-hook:
$(INSTALL) -d $(DESTDIR)/$(CONFIGDIR)/zapit

View File

@@ -0,0 +1,11 @@
-dev$
-doc$
-dbg$
-ptest$
-staticdev$
-locale-
-charmap-
-gconv-
-localedata-
^locale-base-
^perl-module-

View File

@@ -55,13 +55,14 @@
#include <alloca.h>
#include <errno.h>
#include <sys/wait.h>
#include <fstream>
#define OPKG_CL "opkg"
#define OPKG_TMP_DIR "/tmp/.opkg"
#define OPKG_TEST_DIR OPKG_TMP_DIR "/test"
#define OPKG_CL_CONFIG_OPTIONS " -V2 --tmp-dir=/tmp --cache=" OPKG_TMP_DIR
#define OPKG_BAD_PATTERN_LIST_FILE "/var/tuxbox/config/bad_package_pattern.list"
#define OPKG_CONFIG_FILE "/etc/opkg/opkg.conf"
using namespace std;
@@ -113,8 +114,8 @@ COPKGManager::COPKGManager(): opkg_conf('\t')
list_upgradeable_done = false;
expert_mode = false;
local_dir = &g_settings.update_dir_opkg;
v_bad_pattern = getBadPackagePatternList();
CFileHelpers::createDir(OPKG_TMP_DIR);
}
COPKGManager::~COPKGManager()
@@ -305,29 +306,38 @@ static const struct button_label COPKGManagerFooterButtonsExpert[COPKGManagerFoo
{ NEUTRINO_ICON_BUTTON_BLUE, LOCALE_OPKG_BUTTON_UNINSTALL }
};
/* TODO: this should go into a config file... */
static std::string bad_pattern[] = {
"-dev$",
"-doc$",
"-dbg$",
"-ptest$",
"-staticdev$",
"-locale-",
"-charmap-",
"-gconv-",
"-localedata-",
"^locale-base-",
"^perl-module-",
""
};
vector<string> COPKGManager::getBadPackagePatternList()
{
vector<string> v_ret;
ifstream in (OPKG_BAD_PATTERN_LIST_FILE, ios::in);
if (!in){
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] can't open %s, %s\n", __func__, __LINE__, OPKG_BAD_PATTERN_LIST_FILE, strerror(errno));
return v_ret;
}
string line;
while(getline(in, line)){
v_ret.push_back(line);
}
in.close();
return v_ret;
}
bool COPKGManager::badpackage(std::string &s)
{
int i;
if(v_bad_pattern.empty())
return false;
size_t i;
string st = "";
for (i = 0; !bad_pattern[i].empty(); i++)
for (i = 0; i < v_bad_pattern.size(); i++)
{
string p = bad_pattern[i];
string p = v_bad_pattern[i];
if (p.empty())
continue;
size_t patlen = p.length() - 1;
bool res = false;
/* poor man's regex :-) only supported are "^" and "$" */

View File

@@ -56,6 +56,9 @@ class COPKGManager : public CMenuTarget
std::string config_src[OPKG_MAX_FEEDS];
std::vector<std::string> config_dest;
//filter
std::vector<std::string> v_bad_pattern;
std::map<std::string,pkg> pkg_map;
std::vector<pkg*> pkg_vec;
@@ -107,7 +110,7 @@ class COPKGManager : public CMenuTarget
bool isInstalled(const std::string& pkg_name);
bool isUpgradable(const std::string& pkg_name);
/*
/*!
* Gets an info from opkg command info or status from a package via keywords as std::string
* 1st parameter is name of package as string eg. "gdb", without file extension or version data
* 2nd parameter needs a keyword like:
@@ -125,7 +128,25 @@ class COPKGManager : public CMenuTarget
void showMenuConfigFeed(CMenuWidget *feed_menu);
void updateMenu();
void refreshMenu();
//!Returns a vector with possible filter entries from OPKG_BAD_PATTERN_LIST_FILE
static std::vector<std::string> getBadPackagePatternList();
/*!
* Returns true if found a ''bad'' package, Parameter: package name as std::string by rev
* To detect bad packages, it must be exist a matching pattern list file.
* Path is defined in OPKG_BAD_PATTERN_LIST_FILE.
* This provides the option to filter some unwanted entries in the package list menue.
* This makes sense eg. to hinder that the user could change important system packages.
* NOTE: a sample file you should find here as : "/var/tuxbox/config/bad_package_pattern.list.sample"
* If required, remove the ".sample" extension and change the entries for your requirements
* howto: a simple way to filter a package is to add the pure name, if you want
* to hide a package (even which name) then add this name to a line. Eg. if you want to hide
* package wget then add this and this package is not displayed at the gui.
* Also a few place holders should work, see the badpackage() function, but this
* can be inaccurately because it could filter innocent packages.
*/
bool badpackage(std::string &s);
void showError(const char* local_msg, char* err_msg = NULL, const std::string& additional_text = std::string());
int doUpdate();
void handleShellOutput(std::string* cur_line, int* res, bool* ok);