* @brief Implementation file for installer task update files
*/
+#include <unistd.h>
#include <utility>
#include <vector>
#include <string>
#include <widget_install/widget_install_errors.h>
#include <widget_install/job_widget_install.h>
-#include <dpl/wrt-dao-rw/widget_dao.h>
#include <dpl/wrt-dao-ro/global_config.h>
-#include <dpl/utils/wrt_utility.h>
#include <dpl/exception.h>
+#include <dpl/errno_string.h>
using namespace WrtDB;
namespace {
-
inline const char* GetWidgetBackupDirPath()
{
return "backup";
namespace Jobs {
namespace WidgetInstall {
-
TaskUpdateFiles::TaskUpdateFiles(InstallerContext& context) :
DPL::TaskDecl<TaskUpdateFiles>(this),
m_context(context)
AddStep(&TaskUpdateFiles::StepCreateBackupFolder);
AddStep(&TaskUpdateFiles::StepResourceFilesBackup);
AddStep(&TaskUpdateFiles::StepExecFileBackup);
- AddStep(&TaskUpdateFiles::StepUpdateExternalFiles);
AddAbortStep(&TaskUpdateFiles::StepAbortCreateBackupFolder);
AddAbortStep(&TaskUpdateFiles::StepAbortExecFileBackup);
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.");
}
}
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");
}
}
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);
list.insert(absFileName.substr(subLen));
}
+ } while (dirent);
+ //closing the directory
+ if (-1 == TEMP_FAILURE_RETRY(closedir(pkgDir))) {
+ LogError("Failed to close dir: " << dirPath << " with error: "
+ << DPL::GetErrnoString());
}
- while(dirent);
}
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) {
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);
} 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);
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);
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);
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");
LogDebug("Backup Folder " << srcBuPath << " to " << srcPath);
- if(!WrtUtilRemove(srcPath)) {
+ if (!WrtUtilRemove(srcPath)) {
LogError("Failed to remove " << srcPath);
}
LogDebug("StepAbortExecFileBackup");
std::string binPath = m_context.locations->getBinaryDir();
- if(!WrtUtilRemove(binPath)) {
+ if (!WrtUtilRemove(binPath)) {
LogError("Failed to remove " << binPath);
}
path << m_context.locations->getBackupDir();
LogDebug("Remove backup directory : " << path.str());
- if(!WrtUtilRemove(path.str())) {
+ if (!WrtUtilRemove(path.str())) {
LogError("Failed to remove " << path);
}
}
-
-void TaskUpdateFiles::StepUpdateExternalFiles()
-{
- WidgetDAO dao(m_context.locations->getPkgname());
- WrtDB::ExternalLocationList externalLocationsUpdate = m_context.locations->listExternalLocations();
- WrtDB::ExternalLocationList externalLocationsDB = dao.getWidgetExternalLocations();
- LogDebug("Removing external files:");
- FOREACH(file, externalLocationsDB)
- {
- if(std::find(externalLocationsUpdate.begin(), externalLocationsUpdate.end(), *file) == externalLocationsUpdate.end())
- {
- if(WrtUtilFileExists(*file))
- {
- LogDebug(" -> " << *file);
- remove(file->c_str());
- }
- else if(WrtUtilDirExists(*file))
- {
- LogDebug(" -> " << *file);
- if(!WrtUtilRemove(*file)){
- ThrowMsg(Exceptions::RemovingFolderFailure,
- "Failed to remove external directory");
- }
- }
- else
- {
- LogWarning(" -> " << *file << "(no such a path)");
- }
- }
- }
- dao.unregisterAllExternalLocations();
- LogDebug("Registering(update) external files:");
- FOREACH(file, externalLocationsUpdate)
- {
- LogDebug(" -> " << *file);
- }
- dao.registerExternalLocations(externalLocationsUpdate);
-}
-
} //namespace WidgetInstall
} //namespace Jobs