}
return (0 == filename.compare(fileLen - extLen, extLen, extension));
}
-
-bool checkTizenPkgIdExist(const std::string& tizenPkgId)
-{
- std::string installPath =
- std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
- "/" + tizenPkgId;
- std::string preinstallPath =
- std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
- "/" + tizenPkgId;
-
- struct stat dirStat;
- if ((stat(installPath.c_str(), &dirStat) == 0) ||
- (stat(preinstallPath.c_str(), &dirStat) == 0))
- {
- return true;
- }
- return false;
-}
} // namespace anonymous
namespace Jobs {
TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
LogDebug("Checking if pkg id is unique");
while (true) {
- if (checkTizenPkgIdExist(DPL::ToUTF8String(pkgId))) {
+ if (!validateTizenPackageID(pkgId)) {
//path exist, chose another one
pkgId = WidgetDAOReadOnly::generatePkgId();
continue;
const WrtDB::ConfigParserData &configData,
const std::string &tempPath)
{
- WidgetUpdateInfo update = detectWidgetUpdate(
- configData,
- m_installerContext.
- widgetConfig.webAppType,
- m_installerContext.
- widgetConfig.tzAppid);
- ConfigureResult result = checkWidgetUpdate(update);
-
- // Validate tizenId
- regex_t reg;
- if (regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
- LogDebug("Regcomp failed");
+ ConfigureResult result = ConfigureResult::Failed;
+ WidgetUpdateInfo update;
+
+ // checking installed web application
+ Try {
+ // checking existing application is installed
+ WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
+ // no excpetion means, it isn't update mode
+ getInstallerStruct().pkgmgrInterface->sendSignal(
+ PKGMGR_START_KEY,
+ PKGMGR_START_UPDATE);
+
+ update = detectWidgetUpdate(configData,
+ m_installerContext.widgetConfig.tzAppid);
+ result = checkWidgetUpdate(update);
+ if (result != ConfigureResult::Updated) {
+ // Already installed TizenAppId. return failed
+ return ConfigureResult::Failed_AlreadyInstalled;
+ }
+ m_installerContext.isUpdateMode = true;
}
+ Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) {
+ result = ConfigureResult::Ok;
+ getInstallerStruct().pkgmgrInterface->sendSignal(
+ PKGMGR_START_KEY,
+ PKGMGR_START_INSTALL);
+ m_installerContext.isUpdateMode = false;
- if ((regexec(®,
- DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid).
- c_str(),
- static_cast<size_t>(0), NULL, 0) == REG_NOMATCH) ||
- (checkTizenPkgIdExist(DPL::ToUTF8String(m_installerContext.widgetConfig
- .tzPkgid)) &&
- result != ConfigureResult::Updated))
- {
- //it is true when tizenId does not fit REG_TIZENID_PATTERN
- LogError("tizen_id provided but not proper or pkgId directory exists");
- //TODO(t.iwanek): appId is unique, what about installation of
- // abcdefghij.test1 and abcdefghij.test2?
- regfree(®);
- return ConfigureResult::Failed_AlreadyInstalled;
+ if (!validateTizenApplicationID(
+ m_installerContext.widgetConfig.tzAppid))
+ {
+ LogError("tizen application ID is already used");
+ return ConfigureResult::Failed_InvalidConfig;
+ }
+ if (!validateTizenPackageID(m_installerContext.widgetConfig.tzPkgid)) {
+ LogError("tizen package ID is already used");
+ return ConfigureResult::Failed_AlreadyInstalled;
+ }
}
- regfree(®);
configureWidgetLocation(widgetSource, tempPath);
// Init installer context
m_installerContext.installStep = InstallerContext::INSTALL_START;
m_installerContext.job = this;
- m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
m_installerContext.widgetConfig.shareHref = std::string();
return result;
}
-ConfigureResult JobWidgetInstall::checkWidgetUpdate(
- const WidgetUpdateInfo &update)
+bool JobWidgetInstall::validateTizenApplicationID(
+ const WrtDB::TizenAppId &tizenAppId)
{
- LogInfo(
- "Widget install/update: incoming guid = '" <<
- update.incomingGUID << "'");
- LogInfo(
- "Widget install/update: incoming version = '" <<
- update.incomingVersion << "'");
-
- // Check policy
- WidgetUpdateMode::Type updateTypeCheckBit;
-
- if (update.existingWidgetInfo.isExist == false) {
- LogInfo("Widget info does not exist");
- updateTypeCheckBit = WidgetUpdateMode::NotInstalled;
-
- getInstallerStruct().pkgmgrInterface->sendSignal(
- PKGMGR_START_KEY,
- PKGMGR_START_INSTALL);
-
- } else {
- LogInfo("Widget info exists. appid: " <<
- update.existingWidgetInfo.tzAppid);
+ LogInfo("tizen application ID = [" << tizenAppId << "]");
- getInstallerStruct().pkgmgrInterface->sendSignal(
- PKGMGR_START_KEY,
- PKGMGR_START_UPDATE);
+ regex_t reg;
+ if (regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
+ LogDebug("Regcomp failed");
+ }
- TizenAppId tzAppid = update.existingWidgetInfo.tzAppid;
+ if (regexec(®, DPL::ToUTF8String(tizenAppId).c_str(), 0, NULL, 0)
+ == REG_NOMATCH)
+ {
+ regfree(®);
+ return false;
+ }
+ regfree(®);
+ return true;
+}
- LogInfo("Widget model exists. tizen app id: " << tzAppid);
+bool JobWidgetInstall::validateTizenPackageID(
+ const WrtDB::TizenPkgId &tizenPkgId)
+{
+ std::string pkgId = DPL::ToUTF8String(tizenPkgId);
- // Check running state
- bool isRunning = false;
- int retval = app_manager_is_running(DPL::ToUTF8String(
- tzAppid).c_str(), &isRunning);
- if (APP_MANAGER_ERROR_NONE != retval) {
- LogError("Fail to get running state");
- return ConfigureResult::Failed_WidgetRunning;
- }
+ std::string installPath =
+ std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
+ "/" + pkgId;
+ std::string preinstallPath =
+ std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
+ "/" + pkgId;
- if (true == isRunning) {
- // Must be deferred when update in progress
- if (m_jobStruct.updateMode == WidgetUpdateMode::PolicyWac) {
- LogInfo(
- "Widget is already running. Policy is update according to WAC");
+ struct stat dirStat;
+ if ((stat(installPath.c_str(), &dirStat) == 0) ||
+ (stat(preinstallPath.c_str(), &dirStat) == 0))
+ {
+ return false;
+ }
+ return true;
+}
- return ConfigureResult::Deferred;
- } else {
- LogInfo(
- "Widget is already running. Policy is not update according to WAC");
+ConfigureResult JobWidgetInstall::checkWidgetUpdate(
+ const WidgetUpdateInfo &update)
+{
+ LogInfo("incoming version = '" << update.incomingVersion);
+ LogInfo("Tizen AppID = " << update.tzAppId);
+
+ // Check running state
+ bool isRunning = false;
+ int retval =
+ app_manager_is_running(DPL::ToUTF8String(update.tzAppId).c_str(),
+ &isRunning);
+ if (APP_MANAGER_ERROR_NONE != retval || isRunning) {
+ LogError("Fail to get running state");
+ return ConfigureResult::Failed_WidgetRunning;
+ }
- return ConfigureResult::Failed_WidgetRunning;
- }
- }
+ m_installerContext.widgetConfig.tzAppid = update.tzAppId;
- m_installerContext.widgetConfig.tzAppid = tzAppid;
- OptionalWidgetVersion existingVersion;
- existingVersion = update.existingWidgetInfo.existingVersion;
- OptionalWidgetVersion incomingVersion = update.incomingVersion;
-
- updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion,
- incomingVersion);
- // Calc proceed flag
- if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
- m_jobStruct.updateMode ==
- WidgetUpdateMode::PolicyDirectoryForceInstall)
- {
- LogInfo("Whether widget policy allow proceed ok");
- return ConfigureResult::Updated;
- } else {
- return ConfigureResult::Failed_LowerVersion;
- }
+ WidgetUpdateMode::Type updateTypeCheckBit;
+ updateTypeCheckBit = CalcWidgetUpdatePolicy(update.existingVersion,
+ update.incomingVersion);
+ // Calc proceed flag
+ if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
+ m_jobStruct.updateMode ==
+ WidgetUpdateMode::PolicyDirectoryForceInstall)
+ {
+ LogInfo("Whether widget policy allow proceed ok");
+ return ConfigureResult::Updated;
+ } else {
+ return ConfigureResult::Failed_LowerVersion;
}
- return ConfigureResult::Ok;
+
+ return ConfigureResult::Failed;
}
WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
const ConfigParserData &configInfo,
- const WrtDB::WidgetType appType,
const WrtDB::TizenAppId &tizenId)
{
LogInfo("Checking up widget package for config.xml...");
+ OptionalWidgetVersion incomingVersion;
- DPL::OptionalString widgetGUID;
- OptionalWidgetVersion widgetVersion;
-
- // Check widget id
- widgetGUID = configInfo.widget_id;
-
- if (widgetGUID.IsNull()) {
- LogWarning("Installed widget has no GUID");
- return WidgetUpdateInfo();
- }
-
- LogDebug("Installed widget GUID: " << *widgetGUID);
-
- // Locate widget ID with this GUID
- // Incoming widget version
if (!configInfo.version.IsNull()) {
- widgetVersion =
+ incomingVersion =
DPL::Optional<WidgetVersion>(
WidgetVersion(*configInfo.version));
}
- if (appType == APP_TYPE_WAC20) {
- Try
- {
- // Search widget handle by GUID
- WidgetDAOReadOnly dao(widgetGUID);
- return WidgetUpdateInfo(
- widgetGUID,
- widgetVersion,
- WidgetUpdateInfo::ExistingWidgetInfo(
- dao.getTzAppId(), dao.getVersion()));
- }
- Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
- {
- // GUID isn't installed
- return WidgetUpdateInfo(
- widgetGUID,
- widgetVersion,
- WidgetUpdateInfo::ExistingWidgetInfo());
- }
- } else {
- Try
- {
- // Search widget handle by appId
- WidgetDAOReadOnly dao(tizenId);
- return WidgetUpdateInfo(
- widgetGUID,
- widgetVersion,
- WidgetUpdateInfo::ExistingWidgetInfo(
- dao.getTzAppId(), dao.getVersion()));
- }
- Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
- {
- // GUID isn't installed
- return WidgetUpdateInfo(
- widgetGUID,
- widgetVersion,
- WidgetUpdateInfo::ExistingWidgetInfo());
- }
- }
+ WidgetDAOReadOnly dao(tizenId);
+ return WidgetUpdateInfo(
+ dao.getTzAppId(),
+ WidgetVersion(*dao.getVersion()),
+ incomingVersion);
}
void JobWidgetInstall::SendProgress()
sync();
if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
- if (false == m_installerContext.existingWidgetInfo.isExist) {
- WidgetInstallToExtSingleton::Instance().postInstallation(true);
- } else {
+ if (m_installerContext.isUpdateMode) {
WidgetInstallToExtSingleton::Instance().postUpgrade(true);
+ } else {
+ WidgetInstallToExtSingleton::Instance().postInstallation(true);
}
WidgetInstallToExtSingleton::Instance().deinitialize();
}
}
m_name = m_argv[2];
AddStep(&WrtInstaller::uninstallPkgNameStep);
- } else if (arg == "-ug" || arg == "--uninstall-guid") {
- if (m_argc != 3) {
- return showHelpAndQuit();
- }
- m_name = m_argv[2];
- AddStep(&WrtInstaller::uninstallGuidStep);
} else if (arg == "-up" || arg == "--uninstall-packagepath") {
if (m_argc != 3) {
return showHelpAndQuit();
void WrtInstaller::showHelpAndQuit()
{
- printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/GUID/PATH]...\n"
+ printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/PATH]...\n"
"Operate with WebRuntime daemon: install, uninstall"
" and launch widgets.\n"
"Query list of installed widgets and setup up debugging support.\n"
"install forcibly widget package for given path\n"
" -un, --uninstall-name "
"uninstall widget for given package name\n"
- " -ug, --uninstall-guid "
- "uninstall widget for given Global Unique IDentifier\n"
" -up, --uninstall-packagepath "
"uninstall widget for given package file path\n"
"\n");
pkgmgrSignalInterface);
}
-void WrtInstaller::uninstallGuidStep()
-{
- LogDebug("Uninstalling widget ...");
- std::string appid;
- WrtErrStatus status = wrt_get_widget_by_guid(appid, m_name);
- if (status == WRT_SUCCESS) {
- LogDebug("Guid : " << m_name);
- wrt_uninstall_widget(
- appid.c_str(), this, &staticWrtStatusCallback,
- !m_quiet ? &staticWrtUninstallProgressCallback :
- NULL,
- pkgmgrSignalInterface);
- } else {
- printf("failed: can not uninstall widget\n");
- LogError("Fail to uninstalling widget... ");
- m_returnStatus = -1;
- DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
- PostEvent(
- WRTInstallerNS::QuitEvent());
- }
-}
-
void WrtInstaller::unistallWgtFileStep()
{
LogDebug("Uninstalling widget ...");
resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
printMsg = "installation";
} else if (current == &WrtInstaller::uninstallPkgNameStep ||
- current == &WrtInstaller::uninstallGuidStep ||
current == &WrtInstaller::unistallWgtFileStep)
{
resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);