return old_author_certificate;
}
+bool IsPackageInstalled(const std::string& pkg_id) {
+ pkgmgrinfo_pkginfo_h handle;
+ int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), getuid(),
+ &handle);
+ if (ret != PMINFO_R_OK)
+ return false;
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return true;
+}
+
+
} // namespace common_installer
const std::string& pkgid, uid_t uid);
std::string QueryCertificateAuthorCertificate(const std::string& pkgid,
uid_t uid);
+bool IsPackageInstalled(const std::string& pkg_id);
} // namespace common_installer
step/step_parse.cc
step/step_create_symbolic_link.cc
step/step_copy_manifest_xml.cc
+ tpk_app_query_interface.cc
xml_parser/xml_parser.cc
)
ADD_EXECUTABLE(${TARGET_TPK} ${SRCS})
#include "common/step/step_backup_icons.h"
#include "common/step/step_backup_manifest.h"
#include "common/step/step_create_icons.h"
+#include "common/step/step_create_storage_directories.h"
#include "common/step/step_copy.h"
#include "common/step/step_copy_backup.h"
-#include "common/step/step_copy_storage_directories.h"
-#include "common/step/step_create_storage_directories.h"
#include "common/step/step_check_old_certificate.h"
#include "common/step/step_generate_xml.h"
#include "common/step/step_old_manifest.h"
namespace tpk {
-/* Constructor
- */
Task::Task() {
}
-
-/* Destructor
- */
-::tpk::Task::~Task() {
+Task::~Task() {
}
-
bool Task::Init(int argc, char** argv) {
- pkgmgr_ = ci::PkgMgrInterface::Create(argc, argv);
+ query_interface_.reset(new TpkAppQueryInterface());
+ pkgmgr_ = ci::PkgMgrInterface::Create(argc, argv, query_interface_.get());
if (!pkgmgr_) {
- LOG(ERROR) << "Options of pkgmgr installer cannot be parsed";
+ LOG(ERROR) << "Cannot connect to PkgMgrInstaller";
return false;
}
return true;
}
-
bool Task::Run() {
switch (pkgmgr_->GetRequestType()) {
case ci::RequestType::Install:
ai.AddStep<ci::backup::StepBackupManifest>();
ai.AddStep<ci::backup::StepBackupIcons>();
ai.AddStep<ci::backup::StepCopyBackup>();
- ai.AddStep<ci::filesystem::StepCopyStorageDirectories>();
+ ai.AddStep<ci::filesystem::StepCreateStorageDirectories>();
+ // TODO(t.iwanek): handle coping storage directories
ai.AddStep<tpk::filesystem::StepCreateSymbolicLink>();
ai.AddStep<ci::filesystem::StepCreateIcons>();
ai.AddStep<ci::security::StepUpdateSecurity>();
#ifndef TPK_TASK_H_
#define TPK_TASK_H_
+#include <memory>
+
#ifdef HOSTTEST
#include "test/mock_pkgmgr_installer.h"
#endif
#include "common/utils/logging.h"
#include "common/pkgmgr_interface.h"
+#include "tpk/tpk_app_query_interface.h"
namespace tpk {
bool Reinstall();
common_installer::PkgMgrPtr pkgmgr_;
+ std::unique_ptr<TpkAppQueryInterface> query_interface_;
SCOPE_LOG_TAG(TpkTask)
}; // class Task
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "tpk/tpk_app_query_interface.h"
+
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <memory>
+#include <string>
+
+#include "common/pkgmgr_registration.h"
+#include "common/utils/file_util.h"
+#include "common/utils/logging.h"
+#include "tpk/xml_parser/xml_parser.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+namespace ci = common_installer;
+namespace xp = xml_parser;
+
+namespace {
+
+const char kManifestFileName[] = "tizen-manifest.xml";
+
+std::string GetInstallationPackagePath(int argc, char** argv) {
+ std::string path;
+ for (int i = 0; i < argc; ++i) {
+ if (!strcmp(argv[i], "-i")) {
+ if (i + 1 < argc) {
+ path = argv[i + 1];
+ break;
+ }
+ }
+ }
+ return path;
+}
+
+std::string GetPkgIdFromPath(const std::string& path) {
+ bf::path tmp_path = common_installer::GenerateTmpDir("/tmp");
+ bs::error_code code;
+ bf::create_directories(tmp_path, code);
+ if (code)
+ return {};
+ if (!common_installer::ExtractToTmpDir(path.c_str(), tmp_path,
+ kManifestFileName)) {
+ bf::remove_all(tmp_path, code);
+ return {};
+ }
+ bf::path manifest_path = tmp_path / kManifestFileName;
+ if (!bf::exists(manifest_path)) {
+ bf::remove_all(tmp_path, code);
+ return {};
+ }
+ xp::XmlParser parser;
+ std::unique_ptr<xp::XmlTree> tree(parser.ParseAndGetNewTree(
+ manifest_path.c_str()));
+ if (!tree) {
+ bf::remove_all(tmp_path, code);
+ return {};
+ }
+ xp::XmlElement* manifest = tree->GetRootElement();
+ if (!manifest) {
+ bf::remove_all(tmp_path, code);
+ return {};
+ }
+ std::string pkg_id = manifest->attr("package");
+ bf::remove_all(tmp_path, code);
+ return pkg_id;
+}
+
+} // namespace
+
+namespace tpk {
+
+bool TpkAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) {
+ std::string path = GetInstallationPackagePath(argc, argv);
+ if (path.empty()) {
+ // not the installaton
+ return false;
+ }
+ std::string pkg_id = GetPkgIdFromPath(path);
+ if (pkg_id.empty())
+ return false;
+ return ci::IsPackageInstalled(pkg_id);
+}
+
+} // namespace tpk
+
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef TPK_TPK_APP_QUERY_INTERFACE_H_
+#define TPK_TPK_APP_QUERY_INTERFACE_H_
+
+#include "common/app_query_interface.h"
+
+namespace tpk {
+
+class TpkAppQueryInterface : public common_installer::AppQueryInterface {
+ public:
+ bool IsAppInstalledByArgv(int argc, char** argv) override;
+};
+
+} // namespace tpk
+
+#endif // TPK_TPK_APP_QUERY_INTERFACE_H_
#include <manifest_handlers/widget_handler.h>
#include <manifest_parser/manifest_parser.h>
-#include <pkgmgr-info.h>
-
-#include <cstring>
#include <memory>
#include <string>
-#include <utility>
#include <vector>
+#include "common/pkgmgr_registration.h"
#include "common/utils/file_util.h"
#include "common/utils/logging.h"
namespace bf = boost::filesystem;
namespace bs = boost::system;
+namespace ci = common_installer;
namespace {
return path;
}
-std::string GetAppIdFromPath(const std::string& path) {
+std::string GetPkgIdFromPath(const std::string& path) {
bf::path tmp_path = common_installer::GenerateTmpDir("/tmp");
bs::error_code code;
bf::create_directories(tmp_path, code);
return pkg_id;
}
-bool IsPackageInstalled(const std::string& pkg_id) {
- pkgmgrinfo_pkginfo_h handle;
- int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), getuid(),
- &handle);
- if (ret != PMINFO_R_OK)
- return false;
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- return true;
-}
-
} // namespace
namespace wgt {
// not the installaton
return false;
}
- std::string pkg_id = GetAppIdFromPath(path);
+ std::string pkg_id = GetPkgIdFromPath(path);
if (pkg_id.empty())
return false;
- return IsPackageInstalled(pkg_id);
+ return ci::IsPackageInstalled(pkg_id);
}
} // namespace wgt