From 9ae65d4ec5c10c08dd2bd4cc58cf4fde569dcadd Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sun, 28 Dec 2014 20:14:33 +0100 Subject: [PATCH] COPKGManager: add function to check package size --- src/gui/opkg_manager.cpp | 61 ++++++++++++++++++++++------------------ src/gui/opkg_manager.h | 1 + 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/gui/opkg_manager.cpp b/src/gui/opkg_manager.cpp index 192d5116b..a871705ef 100644 --- a/src/gui/opkg_manager.cpp +++ b/src/gui/opkg_manager.cpp @@ -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 }, diff --git a/src/gui/opkg_manager.h b/src/gui/opkg_manager.h index 3e1c2cf0b..45a5fee32 100644 --- a/src/gui/opkg_manager.h +++ b/src/gui/opkg_manager.h @@ -97,5 +97,6 @@ class COPKGManager : public CMenuTarget static bool hasOpkgSupport(); bool checkUpdates(const std::string & package_name = std::string(), bool show_progress = true); bool installPackage(const std::string& pkg_name); + bool checkSize(const std::string& pkg_name); }; #endif