Removing warnings reported by cppcheck tool.
authorGrzegorz Rynkowski <g.rynkowski@samsung.com>
Fri, 22 Feb 2013 15:02:36 +0000 (16:02 +0100)
committerGerrit Code Review <gerrit2@kim11>
Tue, 26 Feb 2013 11:30:18 +0000 (20:30 +0900)
[Issue#] LINUXWRT-127
[Problem] Cppcheck reports some warnings.
[Cause] N/A
[Solution] N/A
[Verification] Run cppcheck on wrt-installer (with
--suppress=incorrectStringBooleanError) or check cppcheck.txt generated
by buildbot (ignore warnigs like "A boolean comparison with the string literal
... is always true").
Useful could be installation of rpm on target and checking that is all
right still.

Change-Id: Idf0533e5ef7f1de1f127b3b3fea3418ad34e1680

20 files changed:
src/configuration_parser/widget_parser.cpp
src/jobs/job.cpp
src/jobs/plugin_install/plugin_install_task.cpp
src/jobs/widget_install/ace_registration.cpp
src/jobs/widget_install/job_widget_install.cpp
src/jobs/widget_install/task_certificates.cpp
src/jobs/widget_install/task_encrypt_resource.cpp
src/jobs/widget_install/task_file_manipulation.cpp
src/jobs/widget_install/task_manifest_file.cpp
src/jobs/widget_install/task_plugins_copy.cpp
src/jobs/widget_install/task_recovery.cpp
src/jobs/widget_install/task_update_files.cpp
src/jobs/widget_install/task_widget_config.cpp
src/jobs/widget_uninstall/task_check.cpp
src/jobs/widget_uninstall/task_smack.cpp
src/misc/widget_location.cpp
src/wrt-installer/wrt_installer.cpp
src/wrt-installer/wrt_installer_api.cpp
src/wrt-installer/wrt_installer_api.h
tests/general/common/src/InstallerWrapper.cpp

index 8f878c6..b1407a0 100644 (file)
@@ -88,6 +88,7 @@ void UpdateTextWithDirectionMark(Direction direction,
         break;
     default:
         Assert(false);
+        break;
     }
 }
 } // namespace Unicode
@@ -275,6 +276,7 @@ class AccessParser : public ElementParser
             break;
         default:
             LogError("Error in Access tag - unknown standard.");
+            break;
         }
     }
 
@@ -293,7 +295,7 @@ class AccessParser : public ElementParser
 
         ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin,
                                                 m_bSubDomainAccess);
-        std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
+        //std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
             m_data.accessInfoSet.insert(accessInfo);
     }
 
@@ -305,6 +307,7 @@ class AccessParser : public ElementParser
             break;
         default:
             LogError("Error in Access tag - unknown standard.");
+            break;
         }
     }
 
@@ -1880,6 +1883,7 @@ class LiveboxParser : public ElementParser
             explicit BoxSizeParser(
                 ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
                 ElementParser(),
+                m_properNamespace(false),
                 m_data(data)
             {}
 
index e65f46b..335ab76 100644 (file)
@@ -18,6 +18,7 @@
 
 namespace Jobs {
 Job::Job(InstallationType installType) :
+    m_handle(0),
     m_installationType(installType),
     m_UndoType(false),
     m_paused(false)
index b4c30c3..2eccd38 100644 (file)
@@ -64,6 +64,7 @@ namespace PluginInstall {
 PluginInstallTask::PluginInstallTask(PluginInstallerContext *inCont) :
     DPL::TaskDecl<PluginInstallTask>(this),
     m_context(inCont),
+    m_pluginHandle(0),
     m_dataFromConfigXML(true)
 {
     AddStep(&PluginInstallTask::stepCheckPluginPath);
index faee3ea..e2077ef 100644 (file)
@@ -92,6 +92,7 @@ bool registerAceWidget(const WrtDB::DbWidgetHandle& widgetHandle,
         default:
             LogDebug("Unknown owner type of cert");
             certData[i]->owner = UNKNOWN;
+            break;
         }
         switch (it->type) {
         case WrtDB::WidgetCertificateData::ENDENTITY:
@@ -103,6 +104,7 @@ bool registerAceWidget(const WrtDB::DbWidgetHandle& widgetHandle,
         default:
             LogError("Unknown type of cert");
             certData[i]->type = ENDENTITY;
+            break;
         }
         certData[i]->chain_id = it->chainId;
 
@@ -114,8 +116,7 @@ bool registerAceWidget(const WrtDB::DbWidgetHandle& widgetHandle,
     }
 
     LogDebug("Registerign widget in ace");
-    ace_return_t retval = ACE_ACE_UNKNOWN_ERROR;
-    retval = ace_register_widget(
+    ace_return_t retval = ace_register_widget(
             static_cast<ace_widget_handle_t>(widgetHandle), &wi, certData);
 
     //clean up - WidgetInfo
index a1150f8..e693422 100644 (file)
@@ -167,10 +167,6 @@ JobWidgetInstall::JobWidgetInstall(
     JobContextBase<WidgetInstallationStruct>(installerStruct),
     m_exceptionCaught(Exceptions::Success)
 {
-    struct timeval tv;
-    gettimeofday(&tv, NULL);
-    srand(time(NULL) + tv.tv_usec);
-
     m_installerContext.m_quiet = m_jobStruct.m_quiet;
 
     ConfigureResult result = PrePareInstallation(widgetPath);
@@ -407,8 +403,11 @@ void JobWidgetInstall::setTizenId(
             // TODO : generate name move to wrt-commons
             std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
             std::ostringstream genName;
+            struct timeval tv;
+            gettimeofday(&tv, NULL);
+            unsigned int seed = time(NULL) + tv.tv_usec;
 
-            genName << "_" << allowedString[rand() % allowedString.length()];
+            genName << "_" << allowedString[rand_r(&seed) % allowedString.length()];
             name = DPL::FromUTF8String(genName.str());
             LogDebug("name was generated by WRT");
         }
@@ -529,9 +528,8 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
         LogInfo("Widget model exists. tizen app id: " << tzAppid);
 
         // Check running state
-        int retval = APP_MANAGER_ERROR_NONE;
         bool isRunning = false;
-        retval = app_manager_is_running(DPL::ToUTF8String(
+        int retval = app_manager_is_running(DPL::ToUTF8String(
                                             tzAppid).c_str(), &isRunning);
         if (APP_MANAGER_ERROR_NONE != retval) {
             LogError("Fail to get running state");
index b4a67f7..04247fa 100644 (file)
@@ -39,7 +39,8 @@ namespace Jobs {
 namespace WidgetInstall {
 TaskCertificates::TaskCertificates(InstallerContext& context) :
     DPL::TaskDecl<TaskCertificates>(this),
-    m_context(context)
+    m_context(context),
+    m_pkgHandle(NULL)
 {
     AddStep(&TaskCertificates::StepSetCertiInfo);
     AddAbortStep(&TaskCertificates::StepAbortCertiInfo);
index 7d3b5ff..ae9cebb 100644 (file)
@@ -163,7 +163,8 @@ namespace Jobs {
 namespace WidgetInstall {
 TaskEncryptResource::TaskEncryptResource(InstallerContext& context) :
     DPL::TaskDecl<TaskEncryptResource>(this),
-    m_context(context)
+    m_context(context),
+    m_resEnc(NULL)
 {
     AddStep(&TaskEncryptResource::StepEncryptResource);
 }
@@ -224,6 +225,7 @@ void TaskEncryptResource::EncryptDirectory(std::string path)
                        << " with error: "
                        << strerror(ftsent->fts_errno));
             ThrowMsg(Exceptions::InternalError, "Error reading file");
+            break;
         }
     }
 
index 4d8c669..db50d6b 100644 (file)
@@ -56,11 +56,15 @@ bool _FolderCopy(std::string source, std::string dest)
         return false;
     }
 
-    struct dirent* dEntry = NULL;
+    struct dirent dEntry;
+    struct dirent *dEntryResult;
+    int return_code;
+
     do {
         struct stat statInfo;
-        if ((dEntry = readdir(dir)) != NULL) {
-            std::string fileName = dEntry->d_name;
+        return_code = readdir_r(dir, &dEntry, &dEntryResult);
+        if (dEntryResult != NULL && return_code == 0) {
+            std::string fileName = dEntry.d_name;
             std::string fullName = source + "/" + fileName;
 
             if (stat(fullName.c_str(), &statInfo) != 0) {
@@ -88,7 +92,7 @@ bool _FolderCopy(std::string source, std::string dest)
             outfile.close();
             infile.close();
         }
-    } while (dEntry);
+    } while (dEntryResult != NULL && return_code == 0);
     closedir(dir);
     return true;
 }
@@ -98,7 +102,8 @@ namespace Jobs {
 namespace WidgetInstall {
 TaskFileManipulation::TaskFileManipulation(InstallerContext& context) :
     DPL::TaskDecl<TaskFileManipulation>(this),
-    m_context(context)
+    m_context(context),
+    m_extHandle(NULL)
 {
     if (INSTALL_LOCATION_TYPE_EXTERNAL !=
         m_context.locationType)
index a6ba63d..135b252 100644 (file)
@@ -102,7 +102,8 @@ const char * TaskManifestFile::encoding = "UTF-8";
 
 TaskManifestFile::TaskManifestFile(InstallerContext &inCont) :
     DPL::TaskDecl<TaskManifestFile>(this),
-    m_context(inCont)
+    m_context(inCont),
+    writer(NULL)
 {
     if (false == m_context.existingWidgetInfo.isExist) {
         AddStep(&TaskManifestFile::stepCopyIconFiles);
@@ -170,7 +171,7 @@ void TaskManifestFile::stepCopyIconFiles()
     for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
          icon = icons.rbegin();
          icon != icons.rend();
-         icon++)
+         ++icon)
     {
         FOREACH(locale, icon->availableLocales)
         {
@@ -463,18 +464,27 @@ void TaskManifestFile::getFileList(const char* path,
         ThrowMsg(Exceptions::InternalError, path);
     }
 
-    struct dirent* d_ent;
-    do {
-        if ((d_ent = readdir(dir))) {
-            if (strcmp(d_ent->d_name, ".") == 0 ||
-                strcmp(d_ent->d_name, "..") == 0)
-            {
-                continue;
-            }
-            std::string file_name = d_ent->d_name;
-            list.push_back(file_name);
+    struct dirent entry;
+    struct dirent *result;
+    int return_code;
+    errno = 0;
+    for (return_code = readdir_r(dir, &entry, &result);
+            result != NULL && return_code == 0;
+            return_code = readdir_r(dir, &entry, &result))
+    {
+        if (strcmp(entry.d_name, ".") == 0 ||
+            strcmp(entry.d_name, "..") == 0)
+        {
+            continue;
         }
-    } while (d_ent);
+        std::string file_name = entry.d_name;
+        list.push_back(file_name);
+    }
+
+    if (return_code != 0 || errno != 0) {
+        LogError("readdir_r() failed with " << DPL::GetErrnoString());
+    }
+
     if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
         LogError("Failed to close dir: " << path << " with error: "
                                          << DPL::GetErrnoString());
@@ -676,7 +686,7 @@ void TaskManifestFile::setWidgetIcons(UiApplication & uiApp)
     for (WrtDB::WidgetRegisterInfo::LocalizedIconList::const_reverse_iterator
          icon = icons.rbegin();
          icon != icons.rend();
-         icon++)
+         ++icon)
     {
         FOREACH(locale, icon->availableLocales)
         {
@@ -865,10 +875,9 @@ void TaskManifestFile::setLiveBoxInfo(Manifest& manifest)
         LiveBoxInfo liveBox;
         DPL::Optional<WrtDB::ConfigParserData::LiveboxInfo> ConfigInfo = *it;
         DPL::String appid = m_context.widgetConfig.tzAppid;
-        size_t found;
 
         if (ConfigInfo->m_liveboxId != L"") {
-            found = ConfigInfo->m_liveboxId.find_last_of(L".");
+            size_t found = ConfigInfo->m_liveboxId.find_last_of(L".");
             if (found != std::string::npos) {
                 if (0 == ConfigInfo->m_liveboxId.compare(0, found, appid)) {
                     liveBox.setLiveboxId(ConfigInfo->m_liveboxId);
index 1b6d02e..bf295ea 100644 (file)
@@ -85,7 +85,6 @@ void TaskPluginsCopy::StepFindPlugins()
 
     /* Find all .so files and store their names in list */
     DIR *dir;
-    struct dirent *entry;
     struct stat st;
     LogDebug("Opening plugins directory");
     dir = opendir(m_npsource.c_str());
@@ -94,10 +93,17 @@ void TaskPluginsCopy::StepFindPlugins()
         ThrowMsg(Exceptions::InternalError, "Unable to read plugins directory");
     }
     std::string tempname;
+    struct dirent entry;
+    struct dirent *result;
+    int return_code;
+    errno = 0;
     const std::string ext(".so");
     /* Listing directory and checking entries found inside */
-    while ((entry = readdir(dir)) != NULL) {
-        tempname = m_npsource + "/" + entry->d_name;
+    for (return_code = readdir_r(dir, &entry, &result);
+                result != NULL && return_code == 0;
+                return_code = readdir_r(dir, &entry, &result))
+    {
+        tempname = m_npsource + "/" + entry.d_name;
         if (lstat(tempname.c_str(), &st) != 0) {
             LogWarning(
                 "Failed to call \"lstat\" (errno:" << errno
@@ -107,11 +113,11 @@ void TaskPluginsCopy::StepFindPlugins()
         }
         /* Directories other than "." and ".." should not be found*/
         if (S_ISDIR(st.st_mode)) {
-            if (strncmp(entry->d_name, "..", 2) != 0
-                && strncmp(entry->d_name, ".", 1) != 0)
+            if (strncmp(entry.d_name, "..", 2) != 0
+                && strncmp(entry.d_name, ".", 1) != 0)
             {
                 LogError("Directory detected instead of plugin file: "
-                         << entry->d_name);
+                         << entry.d_name);
                 /* Subdirectories inside plugins/ARCH are not supported */
                 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
                     LogError(
@@ -127,7 +133,7 @@ void TaskPluginsCopy::StepFindPlugins()
             }
         }
 
-        tempname = std::string(entry->d_name);
+        tempname = std::string(entry.d_name);
         /* Check whether file extension is ".so" */
         if (tempname.compare(tempname.size() - ext.size(), ext.size(),
                              ext) == 0)
@@ -140,6 +146,10 @@ void TaskPluginsCopy::StepFindPlugins()
             LogWarning("Non-plugin file found: " << tempname);
         }
     }
+    if (return_code != 0 || errno != 0) {
+        LogError("readdir_r() failed with " << DPL::GetErrnoString());
+    }
+    errno = 0;
     if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
         LogError("Failed to close dir: " << m_npsource << " with error: "
                                          << DPL::GetErrnoString());
@@ -171,7 +181,7 @@ void TaskPluginsCopy::StepCopyPlugins()
     /* Copy plugins from widget package into
      * .netscape/plugins in widget's target directory */
     for (std::list<std::string>::const_iterator it = m_nplugins.begin();
-         it != m_nplugins.end(); it++)
+         it != m_nplugins.end(); ++it)
     {
         LogDebug("Copying plugin file: " << (*it));
         source = m_npsource + "/" + (*it);
index bdf2e71..c6a5e9b 100644 (file)
@@ -63,11 +63,11 @@ void TaskRecovery::StepCreateCheckFile()
     FILE *temp = fopen(infoPath.str().c_str(), "w+");
     if (temp != NULL) {
         fputs(m_context.locations->getWidgetSource().c_str(), temp);
-        if (-1 == fsync(temp->_fileno)) {
-            fclose(temp);
+        int ret = fsync(temp->_fileno);
+        fclose(temp);
+        if (-1 == ret) {
             ThrowMsg(Exceptions::InternalError, "Fail to fsync for recovery.");
         }
-        fclose(temp);
 
         m_context.installInfo = infoPath.str();
 
index e3fabf0..76ff014 100644 (file)
@@ -69,7 +69,6 @@ TaskUpdateFiles::TaskUpdateFiles(InstallerContext& context) :
 void TaskUpdateFiles::StepCreateBackupFolder()
 {
     LogDebug("StepCreateBackupFolder");
-    std::ostringstream backDirPath;
 
     std::string srcBuPath = m_context.locations->getBackupSourceDir();
     LogDebug("backup resource directory path : " << srcBuPath);
@@ -105,28 +104,36 @@ void TaskUpdateFiles::ReadDirList(std::string dirPath, ExistFileList &list,
                 directory");
     }
 
-    struct dirent* dirent;
     struct stat statInfo;
-    do {
-        if ((dirent = readdir(pkgDir))) {
-            std::string dirName = dirent->d_name;
-            std::string absFileName = dirPath + "/" + dirName;
-            if (stat(absFileName.c_str(), &statInfo) != 0) {
-                ThrowMsg(Exceptions::InternalError, "Error occurs read file");
-            }
+    struct dirent dirent;
+    struct dirent *result;
+    int return_code;
+    errno = 0;
+    for (return_code = readdir_r(pkgDir, &dirent, &result);
+            result != NULL && return_code == 0;
+            return_code = readdir_r(pkgDir, &dirent, &result))
+    {
+        std::string dirName = dirent.d_name;
+        std::string absFileName = dirPath + "/" + dirName;
+        if (stat(absFileName.c_str(), &statInfo) != 0) {
+            ThrowMsg(Exceptions::InternalError, "Error occurs read file");
+        }
 
-            if (S_ISDIR(statInfo.st_mode)) {
-                if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name,
-                                                               "..") == 0)
-                {
-                    continue;
-                }
-                ReadDirList(absFileName, list, subLen);
+        if (S_ISDIR(statInfo.st_mode)) {
+            if (strcmp(dirent.d_name, ".") == 0 || strcmp(dirent.d_name,
+                                                           "..") == 0)
+            {
+                continue;
             }
-
-            list.insert(absFileName.substr(subLen));
+            ReadDirList(absFileName, list, subLen);
         }
-    } while (dirent);
+
+        list.insert(absFileName.substr(subLen));
+    }
+    if (return_code != 0 || errno != 0) {
+        LogError("readdir_r() failed with " << DPL::GetErrnoString());
+    }
+    errno = 0;
     //closing the directory
     if (-1 == TEMP_FAILURE_RETRY(closedir(pkgDir))) {
         LogError("Failed to close dir: " << dirPath << " with error: "
index 54462a6..d4702f8 100644 (file)
@@ -126,32 +126,37 @@ void TaskWidgetConfig::ReadLocaleFolders()
         return;
     }
 
-    struct dirent* dirent;
+
+
     struct stat statStruct;
-    do {
-        errno = 0;
-        if ((dirent = readdir(localeDir))) {
-            DPL::String dirName = DPL::FromUTF8String(dirent->d_name);
-            std::string absoluteDirName = localePath + "/";
-            absoluteDirName += dirent->d_name;
-
-            if (stat(absoluteDirName.c_str(), &statStruct) != 0) {
-                LogError("stat() failed with " << DPL::GetErrnoString());
-                continue;
-            }
+    struct dirent dirent;
+    struct dirent *result;
+    int return_code;
+    errno = 0;
+    for (return_code = readdir_r(localeDir, &dirent, &result);
+            result != NULL && return_code == 0;
+            return_code = readdir_r(localeDir, &dirent, &result))
+    {
+        DPL::String dirName = DPL::FromUTF8String(dirent.d_name);
+        std::string absoluteDirName = localePath + "/";
+        absoluteDirName += dirent.d_name;
 
-            if (S_ISDIR(statStruct.st_mode)) {
-                //Yes, we ignore current, parent & hidden directories
-                if (dirName[0] != L'.') {
-                    LogDebug("Adding locale directory \"" << dirName << "\"");
-                    m_localeFolders.insert(dirName);
-                }
+        if (stat(absoluteDirName.c_str(), &statStruct) != 0) {
+            LogError("stat() failed with " << DPL::GetErrnoString());
+            continue;
+        }
+
+        if (S_ISDIR(statStruct.st_mode)) {
+            //Yes, we ignore current, parent & hidden directories
+            if (dirName[0] != L'.') {
+                LogDebug("Adding locale directory \"" << dirName << "\"");
+                m_localeFolders.insert(dirName);
             }
         }
-    } while (dirent);
+    }
 
-    if (errno != 0) {
-        LogError("readdir() failed with " << DPL::GetErrnoString());
+    if (return_code != 0 || errno != 0) {
+        LogError("readdir_r() failed with " << DPL::GetErrnoString());
     }
 
     if (-1 == TEMP_FAILURE_RETRY(closedir(localeDir))) {
@@ -676,7 +681,6 @@ bool TaskWidgetConfig::parseConfigurationFileWidget(
     //TODO: rewrite this madness
     std::string cfgAbsPath;
     DIR* dir = NULL;
-    struct dirent* ptr = NULL;
 
     dir = opendir(_currentPath.c_str());
     if (dir == NULL) {
@@ -684,12 +688,19 @@ bool TaskWidgetConfig::parseConfigurationFileWidget(
         return false;
     }
     bool has_config_xml = false;
+    struct dirent ptr;
+    struct dirent *result;
+    int return_code;
     errno = 0;
-    while ((ptr = readdir(dir)) != NULL) { //Find configuration file, based on
-                                           // its name
-        if (ptr->d_type == DT_REG) {
-            if (!strcmp(ptr->d_name, WRT_WIDGET_CONFIG_FILE_NAME)) {
-                std::string dName(ptr->d_name);
+
+    //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
@@ -725,6 +736,10 @@ bool TaskWidgetConfig::parseConfigurationFileWidget(
             }
         }
     }
+    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());
index e87a50a..1a1f62b 100644 (file)
@@ -46,9 +46,8 @@ void TaskCheck::StepUninstallPreCheck()
     //check if deferred
     //TODO if widget to be updated, then remove it from Deferred list?
 
-    int ret = APP_MANAGER_ERROR_NONE;
     bool isRunning = false;
-    ret = app_manager_is_running(m_context.tzAppid.c_str(), &isRunning);
+    int ret = app_manager_is_running(m_context.tzAppid.c_str(), &isRunning);
     if (APP_MANAGER_ERROR_NONE != ret) {
         LogError("Fail to get running state");
         ThrowMsg(Exceptions::PlatformAPIFailure,
index e104bc4..7074dd6 100644 (file)
@@ -45,7 +45,6 @@ void TaskSmack::Step()
     try {
         WrtDB::WidgetDAOReadOnly dao(m_context.widgetConfig.tzAppid);
         TizenAppId tzAppid = dao.getTizenAppId();
-        const char *devCap = "";
         int result = handle_access_control_conf_forWAC(
                 DPL::ToUTF8String(tzAppid).c_str(),
                 NULL,
index 323a7d7..d6fff67 100644 (file)
 
 #include <widget_install/task_commons.h>
 
-WidgetLocation::DirectoryDeletor::DirectoryDeletor()
-{
-    m_dirpath = Jobs::WidgetInstall::createTempPath();
-}
+WidgetLocation::DirectoryDeletor::DirectoryDeletor() :
+    m_dirpath(Jobs::WidgetInstall::createTempPath())
+{}
 
-WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath)
-{
-    m_dirpath = tempPath;
-}
+WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath) :
+        m_dirpath(tempPath)
+{}
 
 WidgetLocation::DirectoryDeletor::~DirectoryDeletor()
 {
index b9b016b..a1c9014 100644 (file)
@@ -82,6 +82,7 @@ struct PluginInstallerData
 WrtInstaller::WrtInstaller(int argc, char **argv) :
     Application(argc, argv, "backend", false),
     DPL::TaskDecl<WrtInstaller>(this),
+    m_installPolicy(WRT_WIM_NOT_INSTALLED),
     m_packagePath(),
     m_handle(-1),
     m_initialized(false),
@@ -403,22 +404,25 @@ void WrtInstaller::installPluginsStep()
     }
 
     LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
-    struct dirent* libdir;
-
-    errno = 0;
 
     std::list<std::string> pluginsPaths;
-
-    while ((libdir = readdir(dir)) != 0) {
-        if (strcmp(libdir->d_name, ".") == 0 ||
-            strcmp(libdir->d_name, "..") == 0)
+    struct dirent libdir;
+    struct dirent *result;
+    int return_code;
+    errno = 0;
+    for (return_code = readdir_r(dir, &libdir, &result);
+            result != NULL && return_code == 0;
+            return_code = readdir_r(dir, &libdir, &result))
+    {
+        if (strcmp(libdir.d_name, ".") == 0 ||
+            strcmp(libdir.d_name, "..") == 0)
         {
             continue;
         }
 
         std::string path = PLUGIN_PATH;
         path += "/";
-        path += libdir->d_name;
+        path += libdir.d_name;
 
         struct stat tmp;
 
@@ -435,6 +439,10 @@ void WrtInstaller::installPluginsStep()
         pluginsPaths.push_back(path);
     }
 
+    if (return_code != 0 || errno != 0) {
+        LogError("readdir_r() failed with " << DPL::GetErrnoString());
+    }
+
     //set nb of plugins to install
     //this value indicate how many callbacks are expected
     m_numPluginsToInstall = pluginsPaths.size();
@@ -866,7 +874,6 @@ void WrtInstaller::staticWrtInstallProgressCallback(float percent,
                                                     void* userdata)
 {
     WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
-    std::stringstream percentStr;
     LogInfo(" progress: " << percent <<
             " description: " << description);
 
@@ -881,7 +888,6 @@ void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
                                                       void* userdata)
 {
     WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
-    std::stringstream percentStr;
     LogInfo(" progress: " << percent <<
             " description: " << description);
 
index 9ef38e9..f6bb4fb 100644 (file)
@@ -451,22 +451,27 @@ EXPORT_API void wrt_install_all_plugins(
         }
 
         LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
-        struct dirent* libdir;
+        struct dirent libdir;
+        struct dirent *result;
+        int return_code;
 
         errno = 0;
 
         std::list<std::string> pluginsPaths;
 
-        while ((libdir = readdir(dir)) != 0) {
-            if (strcmp(libdir->d_name, ".") == 0 ||
-                strcmp(libdir->d_name, "..") == 0)
+        for (return_code = readdir_r(dir, &libdir, &result);
+                    result != NULL && return_code == 0;
+                    return_code = readdir_r(dir, &libdir, &result))
+        {
+            if (strcmp(libdir.d_name, ".") == 0 ||
+                strcmp(libdir.d_name, "..") == 0)
             {
                 continue;
             }
 
             std::string path = PLUGIN_PATH;
             path += "/";
-            path += libdir->d_name;
+            path += libdir.d_name;
 
             struct stat tmp;
 
@@ -498,6 +503,11 @@ EXPORT_API void wrt_install_all_plugins(
                 plugin_install_progress_cb);
         }
 
+        if (return_code != 0 || errno != 0) {
+            LogError("readdir_r() failed with " << DPL::GetErrnoString());
+        }
+
+        errno = 0;
         if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
             LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
                                              << DPL::GetErrnoString());
@@ -583,7 +593,7 @@ EXPORT_API void wrt_installer_shutdown_for_tests()
 }
 
 EXPORT_API WrtErrStatus wrt_get_widget_by_guid(std::string & tzAppid,
-                                               const std::string guid)
+                                               const std::string guid)
 {
     try {
         LogInfo("[WRT-API] GETTING WIDGET PACKAGE NAME BY WidgetID : "
@@ -593,7 +603,7 @@ EXPORT_API WrtErrStatus wrt_get_widget_by_guid(std::string & tzAppid,
         WrtDB::WidgetDAOReadOnly dao(widget_guid);
         tzAppid = DPL::ToUTF8String(dao.getTzAppId());
         return WRT_SUCCESS;
-    } catch (WidgetDAOReadOnly::Exception::WidgetNotExist) {
+    } catch (WidgetDAOReadOnly::Exception::WidgetNotExist&) {
         LogError("Error package name is not found");
         return WRT_ERROR_PKGNAME_NOT_FOUND;
     } catch (const DPL::Exception& ex) {
index 4710d17..c8a058c 100644 (file)
@@ -352,7 +352,7 @@ void wrt_installer_shutdown_for_tests();
  * @return error code
  */
 WrtErrStatus wrt_get_widget_by_guid(std::string &tzAppid,
-                                    const std::string guid);
+                                    const std::string &guid);
 #ifdef __cplusplus
 }
 #endif
index a1f8917..662f617 100644 (file)
@@ -70,11 +70,8 @@ InstallResult install(
     }
 
     char buffer[1024] = "";
-    int ret;
-    while ((ret = fread_unlocked(buffer,
-                                 sizeof(char),
-                                 sizeof(buffer)/sizeof(char),
-                                 filehandle)) > 0)
+    while ( fread_unlocked(buffer, sizeof(char),
+            sizeof(buffer)/sizeof(char), filehandle) > 0 )
     {
         msg += buffer;
     }