Refactor discovering widget's configuration file.
authorZbigniew Kostrzewa <z.kostrzewa@samsung.com>
Tue, 9 Apr 2013 07:51:10 +0000 (09:51 +0200)
committerGerrit Code Review <gerrit2@kim11>
Thu, 11 Apr 2013 10:24:18 +0000 (19:24 +0900)
[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

src/jobs/widget_install/task_widget_config.cpp

index cbf6590..d7c3640 100644 (file)
@@ -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<WidgetParser>(
+                                          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(