mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 08:21:12 +02:00
COPKGManager: add function to check package size
This commit is contained in:
@@ -188,8 +188,27 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
|
|||||||
force = "--force-reinstall ";
|
force = "--force-reinstall ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check package size...cancel installation if size check failed
|
||||||
|
if (!checkSize(actionKey)){
|
||||||
|
DisplayErrorMessage(g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_SIZE_ERROR));
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool COPKGManager::checkSize(const string& pkg_name)
|
||||||
|
{
|
||||||
//get package size
|
//get package size
|
||||||
string s_pkgsize = getPkgInfo(actionKey, "Size");
|
string s_pkgsize = getPkgInfo(pkg_name, "Size");
|
||||||
std::istringstream s(s_pkgsize);
|
std::istringstream s(s_pkgsize);
|
||||||
u_int64_t pkg_size;
|
u_int64_t pkg_size;
|
||||||
s >> pkg_size;
|
s >> pkg_size;
|
||||||
@@ -199,30 +218,18 @@ int COPKGManager::exec(CMenuTarget* parent, const string &actionKey)
|
|||||||
struct statfs root_fs;
|
struct statfs root_fs;
|
||||||
statfs("/",&root_fs);
|
statfs("/",&root_fs);
|
||||||
u_int64_t free_size = root_fs.f_bfree*root_fs.f_bsize;
|
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);
|
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
|
//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.
|
//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;
|
u_int64_t rec_size = pkg_size/2*3;
|
||||||
if (free_size < rec_size){
|
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);
|
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);
|
||||||
DisplayErrorMessage(g_Locale->getText(LOCALE_OPKG_MESSAGEBOX_SIZE_ERROR));
|
return false;
|
||||||
}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{
|
|
||||||
installed = true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshMenu();
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define COPKGManagerFooterButtonCount 3
|
#define COPKGManagerFooterButtonCount 3
|
||||||
static const struct button_label COPKGManagerFooterButtons[COPKGManagerFooterButtonCount] = {
|
static const struct button_label COPKGManagerFooterButtons[COPKGManagerFooterButtonCount] = {
|
||||||
|
@@ -97,5 +97,6 @@ class COPKGManager : public CMenuTarget
|
|||||||
static bool hasOpkgSupport();
|
static bool hasOpkgSupport();
|
||||||
bool checkUpdates(const std::string & package_name = std::string(), bool show_progress = true);
|
bool checkUpdates(const std::string & package_name = std::string(), bool show_progress = true);
|
||||||
bool installPackage(const std::string& pkg_name);
|
bool installPackage(const std::string& pkg_name);
|
||||||
|
bool checkSize(const std::string& pkg_name);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user