COPKGManager: add function to check package size

This commit is contained in:
2014-12-28 20:14:33 +01:00
parent 33bf0fd7ba
commit 9ae65d4ec5
2 changed files with 35 additions and 27 deletions

View File

@@ -188,35 +188,16 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
force = "--force-reinstall ";
}
//get package size
string s_pkgsize = getPkgInfo(actionKey, "Size");
std::istringstream s(s_pkgsize);
u_int64_t pkg_size;
s >> pkg_size;
//get available size
//TODO: Check writability!
struct statfs root_fs;
statfs("/",&root_fs);
u_int64_t free_size = root_fs.f_bfree*root_fs.f_bsize;
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Package: %s [package size=%lld (free size: %lld)]\n", __func__, __LINE__, actionKey.c_str(), pkg_size, free_size);
//only for sure, it's more secure for users to abort installation if is available size too small
//TODO: Package size is not really the same like required/recommended size, because of unknown compression factor, some possible options like cache, different tmp-dir size eg. are still not considered.
u_int64_t rec_size = pkg_size/2*3;
if (free_size < rec_size){
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] WARNING: size check freesize=%lld required size=%lld (recommended: %lld)\n", __func__, __LINE__, free_size, pkg_size, rec_size);
//check package size...cancel installation if size check failed
if (!checkSize(actionKey)){
DisplayErrorMessage(g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_SIZE_ERROR));
}else{
string cmd = pkg_types[OM_INSTALL] + force + actionKey;
int r = execCmd(cmd, true, true);
string cur_version = getPkgInfo(actionKey, "Version");
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] %s: current version = %s\n", __func__, __LINE__, actionKey.c_str(), cur_version.c_str());
if (r){
showError(g_Locale->getText(LOCALE_OPKG_FAILURE_INSTALL), strerror(errno), cmd);
}else{
}
else{
int r = execCmd(pkg_types[OM_INSTALL] + force + actionKey, true, true);
if (r)
showError(g_Locale->getText(LOCALE_OPKG_FAILURE_INSTALL), strerror(errno), pkg_types[OM_INSTALL] + force + actionKey);
else
installed = true;
}
}
refreshMenu();
@@ -224,6 +205,32 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
return res;
}
bool COPKGManager::checkSize(const string& pkg_name)
{
//get package size
string s_pkgsize = getPkgInfo(pkg_name, "Size");
std::istringstream s(s_pkgsize);
u_int64_t pkg_size;
s >> pkg_size;
//get available size
//TODO: Check writability!
struct statfs root_fs;
statfs("/",&root_fs);
u_int64_t free_size = root_fs.f_bfree*root_fs.f_bsize;
dprintf(DEBUG_INFO, "[COPKGManager] [%s - %d] Package: %s [package size=%lld (free size: %lld)]\n", __func__, __LINE__, pkg_name.c_str(), pkg_size, free_size);
//only for sure, it's more secure for users to abort installation if is available size too small
//TODO: Package size is not really the same like required/recommended size, because of unknown compression factor, some possible options like cache, different tmp-dir size eg. are still not considered.
u_int64_t rec_size = pkg_size/2*3;
if (free_size < rec_size){
dprintf(DEBUG_NORMAL, "[COPKGManager] [%s - %d] WARNING: size check freesize=%lld required size=%lld (recommended: %lld)\n", __func__, __LINE__, free_size, pkg_size, rec_size);
return false;
}
return true;
}
#define COPKGManagerFooterButtonCount 3
static const struct button_label COPKGManagerFooterButtons[COPKGManagerFooterButtonCount] = {
{ NEUTRINO_ICON_BUTTON_YELLOW, LOCALE_OPKG_BUTTON_EXPERT_ON },