- std::string srcBuPath = m_context.locations->getBackupSourceDir();
- LogDebug("backup resource directory path : " << srcBuPath);
- 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 \
- directory.");
- }
-
- m_context.job->UpdateProgress(
- InstallerContext::INSTALL_CREATE_BACKUP_DIR,
- "Backup directory created for update");
-}
-
-void TaskUpdateFiles::ReadDirList(std::string dirPath, ExistFileList &list,
- size_t subLen)
-{
- DIR* pkgDir = opendir(dirPath.c_str());
- if (!pkgDir) {
- LogError("Package directory " << dirPath << " doesn't exist");
- ThrowMsg(Exceptions::BackupFailed,
- "Error occurs during read \
- directory");
- }
-
- struct stat statInfo;
- 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::BackupFailed, "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);
- }
-
- 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: "
- << DPL::GetErrnoString());
- }
-}
-
-void TaskUpdateFiles::StepResourceFilesBackup()
-{
- LogDebug("StepCopyFiles");
-
- ExistFileList resList;
- ExistFileList tempList;
-
- std::string pkgSrc = m_context.locations->getSourceDir();
- ReadDirList(pkgSrc, resList, strlen(pkgSrc.c_str()) + 1);
-
- std::string tempSrc = m_context.locations->getTemporaryPackageDir();
- 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);
-
- if (res != resList.end()) {
- std::string backupFile =
- m_context.locations->getBackupSourceDir() +
- "/" + (*it);
-
- struct stat sInfo;
- if (stat(resFile.c_str(), &sInfo) != 0) {
- ThrowMsg(Exceptions::BackupFailed, "Error occurs read file");
- }
-
- if (S_ISDIR(sInfo.st_mode)) {
- LogDebug(resFile << " is a directory. so create a folder : " <<
- 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 \
- rename file");
- }
-
- LogDebug("backup : " << resFile << " to " << backupFile);