Removing compilation warnings in wrt-installer repo
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_update_files.cpp
index 30589a9..e3fabf0 100644 (file)
@@ -20,6 +20,7 @@
  * @brief   Implementation file for installer task update files
  */
 
+#include <unistd.h>
 #include <utility>
 #include <vector>
 #include <string>
@@ -44,7 +45,6 @@
 using namespace WrtDB;
 
 namespace {
-
 inline const char* GetWidgetBackupDirPath()
 {
     return "backup";
@@ -53,7 +53,6 @@ inline const char* GetWidgetBackupDirPath()
 
 namespace Jobs {
 namespace WidgetInstall {
-
 TaskUpdateFiles::TaskUpdateFiles(InstallerContext& context) :
     DPL::TaskDecl<TaskUpdateFiles>(this),
     m_context(context)
@@ -74,15 +73,19 @@ void TaskUpdateFiles::StepCreateBackupFolder()
 
     std::string srcBuPath = m_context.locations->getBackupSourceDir();
     LogDebug("backup resource directory path : " << srcBuPath);
-    if(!WrtUtilMakeDir(srcBuPath)) {
-        ThrowMsg(Exceptions::BackupFailed, "Error occurs during create \
+    if (!WrtUtilMakeDir(srcBuPath)) {
+        ThrowMsg(
+            Exceptions::BackupFailed,
+            "Error occurs during create \
                 backup directory.");
     }
 
     std::string binBuPath = m_context.locations->getBackupBinaryDir();
     LogDebug("backup execution directory path : " << binBuPath);
-    if(!WrtUtilMakeDir(binBuPath)) {
-        ThrowMsg(Exceptions::BackupFailed, "Error occurs during create backup \
+    if (!WrtUtilMakeDir(binBuPath)) {
+        ThrowMsg(
+            Exceptions::BackupFailed,
+            "Error occurs during create backup \
                 directory.");
     }
 
@@ -92,12 +95,13 @@ void TaskUpdateFiles::StepCreateBackupFolder()
 }
 
 void TaskUpdateFiles::ReadDirList(std::string dirPath, ExistFileList &list,
-        size_t subLen)
+                                  size_t subLen)
 {
     DIR* pkgDir = opendir(dirPath.c_str());
     if (!pkgDir) {
         LogError("Package directory " << dirPath << " doesn't exist");
-        ThrowMsg(Exceptions::InternalError, "Error occurs during read \
+        ThrowMsg(Exceptions::InternalError,
+                 "Error occurs during read \
                 directory");
     }
 
@@ -112,8 +116,9 @@ void TaskUpdateFiles::ReadDirList(std::string dirPath, ExistFileList &list,
             }
 
             if (S_ISDIR(statInfo.st_mode)) {
-                if(strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name,
-                            "..") == 0) {
+                if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name,
+                                                               "..") == 0)
+                {
                     continue;
                 }
                 ReadDirList(absFileName, list, subLen);
@@ -121,12 +126,11 @@ void TaskUpdateFiles::ReadDirList(std::string dirPath, ExistFileList &list,
 
             list.insert(absFileName.substr(subLen));
         }
-    }
-    while(dirent);
+    } while (dirent);
     //closing the directory
     if (-1 == TEMP_FAILURE_RETRY(closedir(pkgDir))) {
         LogError("Failed to close dir: " << dirPath << " with error: "
-                << DPL::GetErrnoString());
+                                         << DPL::GetErrnoString());
     }
 }
 
@@ -138,21 +142,21 @@ void TaskUpdateFiles::StepResourceFilesBackup()
     ExistFileList tempList;
 
     std::string pkgSrc = m_context.locations->getSourceDir();
-    ReadDirList(pkgSrc, resList, strlen(pkgSrc.c_str())+1);
-
+    ReadDirList(pkgSrc, resList, strlen(pkgSrc.c_str()) + 1);
 
     std::string tempSrc = m_context.locations->getTemporaryPackageDir();
-    ReadDirList(tempSrc, tempList, strlen(tempSrc.c_str())+1);
+    ReadDirList(tempSrc, tempList, strlen(tempSrc.c_str()) + 1);
 
     FOREACH(it, tempList) {
         std::set<std::string>::iterator res;
         res = resList.find(*it);
         std::string resFile = pkgSrc + "/" + (*it);
-        std::string newFile = tempSrc + "/" +(*it);
+        std::string newFile = tempSrc + "/" + (*it);
 
         if (res != resList.end()) {
-            std::string backupFile = m_context.locations->getBackupSourceDir() +
-                    "/"+ (*it);
+            std::string backupFile =
+                m_context.locations->getBackupSourceDir() +
+                "/" + (*it);
 
             struct stat sInfo;
             if (stat(resFile.c_str(), &sInfo) != 0) {
@@ -161,20 +165,27 @@ void TaskUpdateFiles::StepResourceFilesBackup()
 
             if (S_ISDIR(sInfo.st_mode)) {
                 LogDebug(resFile << " is a directory. so create a folder : " <<
-                        backupFile);
+                         backupFile);
                 WrtUtilMakeDir(backupFile);
             } else {
                 if ((rename(resFile.c_str(), backupFile.c_str())) != 0) {
-                    LogError("Failed to rename " << resFile << " to " << backupFile);
-                    ThrowMsg(Exceptions::BackupFailed, "Error occurs during \
+                    LogError(
+                        "Failed to rename " << resFile << " to " <<
+                        backupFile);
+                    ThrowMsg(
+                        Exceptions::BackupFailed,
+                        "Error occurs during \
                             rename file");
                 }
 
                 LogDebug("backup : " << resFile << " to " << backupFile);
 
                 if ((rename(newFile.c_str(), resFile.c_str())) != 0) {
-                    LogError("Failed to rename " << newFile << " to " << resFile);
-                    ThrowMsg(Exceptions::BackupFailed, "Error occurs during \
+                    LogError(
+                        "Failed to rename " << newFile << " to " << resFile);
+                    ThrowMsg(
+                        Exceptions::BackupFailed,
+                        "Error occurs during \
                             rename file");
                 }
                 LogDebug("copy : " << newFile << " to " << resFile);
@@ -183,7 +194,9 @@ void TaskUpdateFiles::StepResourceFilesBackup()
         } else {
             if ((rename(newFile.c_str(), resFile.c_str())) != 0) {
                 LogError("Failed to rename " << newFile << " to " << resFile);
-                ThrowMsg(Exceptions::BackupFailed, "Error occurs during \
+                ThrowMsg(
+                    Exceptions::BackupFailed,
+                    "Error occurs during \
                         rename file");
             }
             LogDebug("only copy : " << newFile << " to " << resFile);
@@ -196,7 +209,9 @@ void TaskUpdateFiles::StepResourceFilesBackup()
             std::string backFile = tempSrc + "/" + (*remain);
             if ((rename(pkgFile.c_str(), backFile.c_str())) != 0) {
                 LogError("Failed to backup : " << pkgFile << " to " << backFile);
-                ThrowMsg(Exceptions::BackupFailed, "Error occurs during \
+                ThrowMsg(
+                    Exceptions::BackupFailed,
+                    "Error occurs during \
                         rename file");
             }
             LogDebug("only backup : " << pkgFile << " to " << backFile);
@@ -214,13 +229,14 @@ void TaskUpdateFiles::StepExecFileBackup()
 
     LogDebug(" source : " << execFile);
 
-    std::string tempSource= m_context.locations->getBackupExecFile();
+    std::string tempSource = m_context.locations->getBackupExecFile();
     LogDebug(" source : " << tempSource);
 
     if ((rename(execFile.c_str(), tempSource.c_str())) != 0) {
         LogError("Failed to rename " << execFile << " to " <<
-                tempSource);
-        ThrowMsg(Exceptions::BackupFailed, "Error occurs during \
+                 tempSource);
+        ThrowMsg(Exceptions::BackupFailed,
+                 "Error occurs during \
                 rename file");
     }
     LogDebug("Backup : " << execFile << " to " << tempSource);
@@ -228,8 +244,17 @@ void TaskUpdateFiles::StepExecFileBackup()
     std::string clientPath = GlobalConfig::GetWrtClientExec();
 
     LogInfo("link -s " << clientPath << " " << execFile);
-    symlink(clientPath.c_str(), execFile.c_str());
 
+    errno = 0;
+    if( symlink(clientPath.c_str(), execFile.c_str()) != 0 )
+    {
+        int error = errno;
+        if(error)
+            LogPedantic("Failed to make a symbolic name for a file "
+                    << "[" <<  DPL::GetErrnoString(error) << "]");
+        ThrowMsg(Exceptions::BackupFailed,
+                "Error occurs during rename file");
+    }
     m_context.job->UpdateProgress(
         InstallerContext::INSTALL_BACKUP_EXEC,
         "Backup execution file for update");
@@ -243,7 +268,7 @@ void TaskUpdateFiles::StepAbortResourceFilesBackup()
 
     LogDebug("Backup Folder " << srcBuPath << " to " << srcPath);
 
-    if(!WrtUtilRemove(srcPath)) {
+    if (!WrtUtilRemove(srcPath)) {
         LogError("Failed to remove " << srcPath);
     }
 
@@ -257,7 +282,7 @@ void TaskUpdateFiles::StepAbortExecFileBackup()
     LogDebug("StepAbortExecFileBackup");
     std::string binPath = m_context.locations->getBinaryDir();
 
-    if(!WrtUtilRemove(binPath)) {
+    if (!WrtUtilRemove(binPath)) {
         LogError("Failed to remove " << binPath);
     }
 
@@ -275,10 +300,9 @@ void TaskUpdateFiles::StepAbortCreateBackupFolder()
     path << m_context.locations->getBackupDir();
     LogDebug("Remove backup directory : " << path.str());
 
-    if(!WrtUtilRemove(path.str())) {
+    if (!WrtUtilRemove(path.str())) {
         LogError("Failed to remove " << path);
     }
 }
-
 } //namespace WidgetInstall
 } //namespace Jobs