From: Zbigniew Kostrzewa Date: Tue, 9 Apr 2013 07:51:10 +0000 (+0200) Subject: Refactor discovering widget's configuration file. X-Git-Tag: accepted/tizen_2.1/20130425.023916~8^2~9 X-Git-Url: http://review.tizen.org/git/?p=framework%2Fweb%2Fwrt-installer.git;a=commitdiff_plain;h=018381d0479886e0fa36d2f298e0308213a0eb6a Refactor discovering widget's configuration file. [Issue#] N/A [Problem] Read contents of a directory to search for config.xml. [Cause] N/A [Solution] Directly check for config.xml existence. [SCMRequest] N/A [Verification] 1. Build repository. 2. Install a widget that should successfully install. Change-Id: I8cebb2c868267c50905f67c54fcf156560fa7db9 --- diff --git a/src/jobs/widget_install/task_widget_config.cpp b/src/jobs/widget_install/task_widget_config.cpp index cbf6590..d7c3640 100644 --- a/src/jobs/widget_install/task_widget_config.cpp +++ b/src/jobs/widget_install/task_widget_config.cpp @@ -650,78 +650,30 @@ bool TaskWidgetConfig::parseConfigurationFileWidget( WrtDB::ConfigParserData& configInfo, const std::string& _currentPath) { - ParserRunner parser; - - //TODO: rewrite this madness - std::string cfgAbsPath; - DIR* dir = NULL; - - dir = opendir(_currentPath.c_str()); - if (dir == NULL) { + std::string configFilePath; + WrtUtilJoinPaths(configFilePath, _currentPath, WRT_WIDGET_CONFIG_FILE_NAME); + if (!WrtUtilFileExists(configFilePath)) + { + LogError("Archive does not contain configuration file"); return false; } - bool has_config_xml = false; - struct dirent ptr; - struct dirent *result; - int return_code; - errno = 0; - //Find configuration file, based on its name - for (return_code = readdir_r(dir, &ptr, &result); - result != NULL && return_code == 0; - return_code = readdir_r(dir, &ptr, &result)) - { - if (ptr.d_type == DT_REG) { - if (!strcmp(ptr.d_name, WRT_WIDGET_CONFIG_FILE_NAME)) { - std::string dName(ptr.d_name); - WrtUtilJoinPaths(cfgAbsPath, _currentPath, dName); - - //Parse widget configuration file - LogDebug("Found config: " << cfgAbsPath); - - Try - { - parser.Parse(cfgAbsPath, ElementParserPtr(new - RootParser< - WidgetParser>( - configInfo, - DPL - :: - FromUTF32String( - L"widget")))); - } - Catch(ElementParser::Exception::Base) - { - LogError("Invalid widget configuration file!"); - if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) { - LogError( - "Failed to close dir: " << _currentPath << - " with error: " - << DPL::GetErrnoString()); - } - return false; - } + LogDebug("Configuration file: " << configFilePath); - has_config_xml = true; - break; - } - } - } - if (errno != 0) { - LogError("readdir_r() failed with " << DPL::GetErrnoString()); - } - errno = 0; - if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) { - LogError("Failed to close dir: " << _currentPath << " with error: " - << DPL::GetErrnoString()); + Try + { + ParserRunner parser; + parser.Parse(configFilePath, + ElementParserPtr(new RootParser( + configInfo, + DPL::FromUTF32String(L"widget")))); + return true; } - - //We must have config.xml so leaveing if we doesn't - if (!has_config_xml) { - LogError("Invalid archive"); + Catch (ElementParser::Exception::Base) + { + LogError("Invalid configuration file!"); return false; } - return true; } bool TaskWidgetConfig::locateAndParseConfigurationFile(