- Refactor CompareVersion() to return verson compare result directly.
- Change enum type name to use more common abbreviation of "compare".
- Fix using UnzipPkgFromZip() to deliver std::string.
- Remove unnecessary variable initialization.
- Change return type of UnzipPkgFromZip to boolean.
- Replace some command and its arguments into constexpr.
- Extract BackendInvoker constructor with several functions for readability.
- Adjust ordering of include files with alphabetical order.
Change-Id: I4c6f7a8617da1e3fbbf6eca53fe308a8f0b61d8d
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
private:
std::list<std::string> parameters_;
+
+ void SetBackend(PkgType type);
+ void SetOperation(PkgOperation op, const std::string& pkgid);
+ void SetPreload(PkgLocation loc);
+ void SetRemovable(bool removable);
};
} // common_fota
COMPLEX
};
-enum class PkgVersionCompResult {
+enum class PkgVersionCmpResult {
LOWER,
SAME,
HIGHER,
std::string GetId() const;
std::string GetVersion() const;
const BackendInvoker& GetBackendInvoker() const;
- bool CompareVersion(const PkgUpgrader& pkg,
- PkgVersionCompResult* result) const;
+ PkgVersionCmpResult CompareVersion(const PkgUpgrader& pkg) const;
virtual bool Upgrade() = 0;
int UnzipFiles(const std::string& dest_path);
int UnzipXml(const std::string& pkgid);
int UnzipData(const std::string& pkgid, const std::string& dest);
- int UnzipPkgFromZip(const std::string& pkgid);
+ bool UnzipPkgFromZip(const std::string& pkgid);
private:
std::unique_ptr<PkgUpgrader> old_pkg_;
* limitations under the License.
*/
-#include <unistd.h>
-#include <sys/stat.h>
-#include <errno.h>
+#include "backend_invoker.hh"
+
#include <ctype.h>
+#include <errno.h>
+
+#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <unistd.h>
-#include "backend_invoker.hh"
#include "logging.hh"
namespace {
-constexpr char kManifestDirectInstallCmdStr[] = "-y";
-constexpr char kUninstallCmdStr[] = "-d";
+constexpr char kTpkBackendCmdStr[] = "/usr/bin/tpk-backend";
+constexpr char kWgtBackendCmdStr[] = "/usr/bin/wgt-backend";
+
+constexpr char kManifestDirectInstallOptStr[] = "-y";
+constexpr char kUninstallOptStr[] = "-d";
+
+constexpr char kPreloadOptStr[] = "--preload";
+constexpr char kPreloadRWOptStr[] = "--preload-rw";
+constexpr char kPartialRWOptStr[] = "--partial-rw";
+
+constexpr char kForceRemoveOptStr[] = "--force-remove";
+constexpr char kNoRemoveOptStr[] = "--no-remove";
+
+constexpr char kKeepRWDataOptStr[] = "--keep-rwdata";
+constexpr char kSkipCheckReferenceOptStr[] = "--skip-check-reference";
} // namespace
namespace common_fota {
-BackendInvoker::BackendInvoker(std::string pkgid, PkgType type, PkgLocation loc,
- PkgOperation op, bool removable) {
- if (type == PkgType::WGT)
- parameters_.push_back("/usr/bin/wgt-backend");
- else
- parameters_.push_back("/usr/bin/tpk-backend");
+BackendInvoker::BackendInvoker(std::string pkgid, PkgType type,
+ PkgLocation loc, PkgOperation op, bool removable) {
+ SetBackend(type);
+ SetPreload(loc);
+ SetOperation(op, pkgid);
if (op == PkgOperation::INSTALL || op == PkgOperation::UPDATE) {
- parameters_.push_back(kManifestDirectInstallCmdStr);
- parameters_.push_back(std::move(pkgid));
if (loc == PkgLocation::RO) {
- parameters_.push_back("--preload");
- parameters_.push_back("--partial-rw");
+ parameters_.push_back(kPartialRWOptStr);
} else {
- if (!removable)
- parameters_.push_back("--no-remove");
- parameters_.push_back("--preload-rw");
+ SetRemovable(removable);
+
+ parameters_.push_back(kPreloadRWOptStr);
}
- parameters_.push_back("--skip-check-reference");
+ parameters_.push_back(kSkipCheckReferenceOptStr);
} else if (op == PkgOperation::UNINSTALL) {
- parameters_.push_back(kUninstallCmdStr);
- parameters_.push_back(std::move(pkgid));
- if (loc == PkgLocation::RO)
- parameters_.push_back("--preload");
- parameters_.push_back("--force-remove");
- parameters_.push_back("--partial-rw");
+ parameters_.push_back(kForceRemoveOptStr);
+ parameters_.push_back(kPartialRWOptStr);
} else if (op == PkgOperation::UNINSTALL_KEEP_RW_DATA) {
- parameters_.push_back(kUninstallCmdStr);
- parameters_.push_back(std::move(pkgid));
- if (loc == PkgLocation::RO)
- parameters_.push_back("--preload");
- parameters_.push_back("--force-remove");
- parameters_.push_back("--keep-rwdata");
+ parameters_.push_back(kForceRemoveOptStr);
+ parameters_.push_back(kKeepRWDataOptStr);
}
}
return parameters_;
}
+void BackendInvoker::SetBackend(PkgType type) {
+ if (type == PkgType::WGT)
+ parameters_.push_back(kWgtBackendCmdStr);
+ else
+ parameters_.push_back(kTpkBackendCmdStr);
+}
+
+void BackendInvoker::SetOperation(
+ PkgOperation op, const std::string& pkgid) {
+ if (op == PkgOperation::INSTALL || op == PkgOperation::UPDATE)
+ parameters_.push_back(kManifestDirectInstallOptStr);
+ else if (op == PkgOperation::UNINSTALL ||
+ op == PkgOperation::UNINSTALL_KEEP_RW_DATA)
+ parameters_.push_back(kUninstallOptStr);
+
+ parameters_.push_back(std::move(pkgid));
+}
+
+void BackendInvoker::SetPreload(PkgLocation loc) {
+ if (loc == PkgLocation::RO)
+ parameters_.push_back(kPreloadOptStr);
+}
+
+void BackendInvoker::SetRemovable(bool removable) {
+ if (!removable)
+ parameters_.push_back(kNoRemoveOptStr);
+}
+
+
int BackendInvoker::Run() const {
const char* param[parameters_.size() + 1] = { nullptr, };
* limitations under the License.
*/
+#include "file_logbackend.hh"
+
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <utility>
#include "logging.hh"
-#include "file_logbackend.hh"
namespace utils {
#include "pkg_finder.hh"
+#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
-#include <dirent.h>
+
#include <tzplatform_config.h>
-#include <cstring>
#include <algorithm>
#include <cctype>
+#include <cstring>
#include "logging.hh"
#include "backend_invoker.hh"
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
#include <iostream>
+
#include <pkgmgr-info.h>
#include "pkg_upgrader.hh"
return backend_;
}
-bool PkgUpgrader::CompareVersion(const PkgUpgrader& pkg,
- PkgVersionCompResult* result) const {
+PkgVersionCmpResult PkgUpgrader::CompareVersion(
+ const PkgUpgrader& pkg) const {
pkgmgrinfo_version_compare_type compare = PMINFO_VERSION_OLD;
- int ret = pkgmgrinfo_compare_package_version(version_.c_str(),
- pkg.GetVersion().c_str(), &compare);
- if (ret != 0)
- return false;
+ if (pkgmgrinfo_compare_package_version(version_.c_str(),
+ pkg.GetVersion().c_str(), &compare) != 0)
+ return PkgVersionCmpResult::UNKNOWN;
if (compare == PMINFO_VERSION_NEW)
- *result = PkgVersionCompResult::HIGHER;
+ return PkgVersionCmpResult::HIGHER;
else if (compare == PMINFO_VERSION_OLD)
- *result = PkgVersionCompResult::LOWER;
+ return PkgVersionCmpResult::LOWER;
else
- *result = PkgVersionCompResult::SAME;
-
- return true;
+ return PkgVersionCmpResult::SAME;
}
* limitations under the License.
*/
+#include "pkg_upgrader_factory.hh"
+
#include <memory>
#include "logging.hh"
-#include "pkg_upgrader_factory.hh"
#include "ro2rw_upgrader.hh"
-#include "rw2ro_upgrader.hh"
#include "ro_upgrader.hh"
+#include "rw2ro_upgrader.hh"
#include "rw_upgrader.hh"
#include "simple_upgrader.hh"
bool RoUpgrader::Upgrade() {
if (old_pkg_) {
- PkgVersionCompResult result = PkgVersionCompResult::UNKNOWN;
- if (!new_pkg_->CompareVersion(*old_pkg_, &result)) {
- LOG(ERROR) << "Failed to compare version of package(" << new_pkg_->GetId()
- << ")";
+ PkgVersionCmpResult result = new_pkg_->CompareVersion(*old_pkg_);
+ if (result == PkgVersionCmpResult::UNKNOWN) {
+ LOG(ERROR) << "Failed to compare version of package("
+ << new_pkg_->GetId() << ")";
return false;
}
- if (result == PkgVersionCompResult::SAME) {
+ if (result == PkgVersionCmpResult::SAME) {
LOG(INFO) << new_pkg_->GetId() << " has same version("
<< new_pkg_->GetVersion() << "). Nothing to do.";
return true;
bool Rw2RoUpgrader::Upgrade() {
// Update only if New RO package has higher(or same) version.
- PkgVersionCompResult result = PkgVersionCompResult::UNKNOWN;
- if (!new_pkg_->CompareVersion(*old_pkg_, &result)) {
+ PkgVersionCmpResult result = new_pkg_->CompareVersion(*old_pkg_);
+ if (result == PkgVersionCmpResult::UNKNOWN) {
LOG(ERROR) << "Failed to compare version of package(" << new_pkg_->GetId()
<< ")";
return false;
}
- if (result == PkgVersionCompResult::LOWER) {
+ if (result == PkgVersionCmpResult::LOWER) {
LOG(INFO) << old_pkg_->GetId() << " has higher version("
<< old_pkg_->GetVersion() << ") already. Nothing to do.";
return true;
bool RwUpgrader::Upgrade() {
if (old_pkg_) {
- PkgVersionCompResult result = PkgVersionCompResult::UNKNOWN;
- if (!new_pkg_->CompareVersion(*old_pkg_, &result)) {
- LOG(ERROR) << "Failed to compare version of package(" << new_pkg_->GetId()
- << ")";
+ PkgVersionCmpResult result = new_pkg_->CompareVersion(*old_pkg_);
+ if (result == PkgVersionCmpResult::UNKNOWN) {
+ LOG(ERROR) << "Failed to compare version of package("
+ << new_pkg_->GetId() << ")";
return false;
}
- if (result == PkgVersionCompResult::SAME) {
+ if (result == PkgVersionCmpResult::SAME) {
LOG(INFO) << new_pkg_->GetId() << " has same version("
<< new_pkg_->GetVersion() << "). Nothing to do.";
return true;
}
}
- if (UnzipPkgFromZip(new_pkg_->GetId().c_str()) != 0) {
- LOG(ERROR) << "UnzipPkgFromZip(" << new_pkg_->GetId() << ") failed";
+ if (!UnzipPkgFromZip(new_pkg_->GetId()))
return false;
- }
if (!new_pkg_->Upgrade()) {
LOG(ERROR) << "Upgrade operation failed";
int RwUpgrader::UnzipFiles(const std::string& dest_path) {
const char* unzip_argv[] = { "/usr/bin/unzip", "-oXqq", kOptZipFile,
dest_path.c_str(), "-d", "/", nullptr };
+
return BackendInvoker::XSystem(unzip_argv);
}
int RwUpgrader::UnzipXml(const std::string& pkgid) {
std::string path = "opt/share/packages/" + pkgid + ".xml";
+
return UnzipFiles(path);
}
int RwUpgrader::UnzipData(const std::string& pkgid,
const std::string& dest) {
std::string path = dest + pkgid + "/*";
+
return UnzipFiles(path);
}
-int RwUpgrader::UnzipPkgFromZip(const std::string& pkgid) {
- int ret = -1;
-
- ret = UnzipXml(pkgid);
- if (ret != 0) {
+bool RwUpgrader::UnzipPkgFromZip(const std::string& pkgid) {
+ if (UnzipXml(pkgid) != 0) {
LOG(ERROR) << "UnzipXml(" << pkgid << ") failed";
- return ret;
+ return false;
}
- ret = UnzipData(pkgid, "opt/usr/globalapps/");
- if (ret != 0) {
- LOG(ERROR) << "UnzipData(" << pkgid << ") failed";
- return ret;
+ if (UnzipData(pkgid, "opt/usr/globalapps/") != 0) {
+ LOG(ERROR) << "Failed to unzip userdata for pkg(" << pkgid << ")";
+ return false;
}
- ret = UnzipData(pkgid, "opt/etc/skel/apps_rw/");
- if (ret != 0) {
- LOG(ERROR) << "UnzipData(" << pkgid << ") failed";
- return ret;
+ if (UnzipData(pkgid, "opt/etc/skel/apps_rw/") != 0) {
+ LOG(ERROR) << "Failed to unzip skel for pkg(" << pkgid << ")";
+ return false;
}
- return 0;
+ return true;
}
} // namespace common_fota
* limitations under the License.
*/
+#include "upgrader.hh"
+
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
#include <fcntl.h>
+#include <pwd.h>
#include <sqlite3.h>
-#include <string.h>
#include <stdlib.h>
#include <stdio.h>
-#include <dirent.h>
-#include <unistd.h>
+#include <string.h>
#include <sys/smack.h>
#include <sys/stat.h>
-#include <errno.h>
-#include <ctype.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
-#include <sys/time.h>
-#include <pwd.h>
+#include <unistd.h>
+
#include <tzplatform_config.h>
#include "logging.hh"
#include "pkg_upgrader_factory.hh"
-#include "upgrader.hh"
using std::list;
using std::shared_ptr;