#include <unistd.h>
#include <string>
#include <sys/stat.h>
-#include <dirent.h>
+#include <fts.h>
#include <dpl/log/log.h>
#include <dpl/errno_string.h>
return encryptSet;
}
-bool isSupportedForEncryption(std::string file)
+bool isSupportedForEncryption(const std::string &file)
{
size_t foundKey = file.rfind(".");
if (std::string::npos != foundKey) {
void TaskEncryptResource::EncryptDirectory(std::string path)
{
- DIR* pkgDir = opendir(path.c_str());
- if (!pkgDir) {
- LogDebug("Package directory doesn't exist");
- ThrowMsg(Exceptions::InternalError, "Error occurs during read \
- directory");
+ FTS *fts;
+ FTSENT *ftsent;
+ char * const paths[] = {const_cast<char * const>(path.c_str()), NULL};
+
+ if ((fts = fts_open(paths, FTS_PHYSICAL|FTS_NOCHDIR, NULL)) == NULL) {
+ //ERROR
+ int error = errno;
+ LogWarning(__PRETTY_FUNCTION__ << ": fts_open failed with error: "
+ << strerror(error));
+ ThrowMsg(Exceptions::InternalError, "Error reading directory: "
+ << path);
}
- struct dirent* dirent;
- struct stat statInfo;
- do {
- if ((dirent = readdir(pkgDir))) {
- std::string dirName = dirent->d_name;
- std::string absFileName = path + "/" + 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;
- }
- EncryptDirectory(absFileName);
- } else {
- if (isSupportedForEncryption(absFileName)) {
- EncryptFile(absFileName);
+ while ((ftsent = fts_read(fts)) != NULL) {
+ switch (ftsent->fts_info) {
+ case FTS_DP:
+ case FTS_DC:
+ case FTS_D:
+ case FTS_DEFAULT:
+ case FTS_SLNONE:
+ //directories, non-regular files, dangling symbolic links
+ break;
+ case FTS_F:
+ case FTS_NSOK:
+ case FTS_SL:
+ //regular files and other objects that can be counted
+ if (isSupportedForEncryption(ftsent->fts_path)) {
+ EncryptFile(ftsent->fts_path);
}
- }
+ break;
+ case FTS_NS:
+ case FTS_DOT:
+ case FTS_DNR:
+ case FTS_ERR:
+ default:
+ LogWarning(__PRETTY_FUNCTION__
+ << ": traversal failed on file: "
+ << ftsent->fts_path
+ << " with error: "
+ << strerror(ftsent->fts_errno));
+ ThrowMsg(Exceptions::InternalError, "Error reading file");
}
}
- while(dirent);
- if (closedir(pkgDir)) {
- LogError("Fail to close directory : " << path);
+
+ if (fts_close(fts) == -1) {
+ int error = errno;
+ LogWarning(__PRETTY_FUNCTION__ << ": fts_close failed with error: "
+ << strerror(error));
}
}
#include <dpl/wrt-dao-ro/global_config.h>
#include <dpl/log/log.h>
#include <dpl/file_input.h>
+#include <dpl/errno_string.h>
#include <dpl/file_output.h>
#include <dpl/copy.h>
#include <dpl/exception.h>
list.push_back(file_name);
}
}while(d_ent);
+ if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
+ LogError("Failed to close dir: " << path << " with error: "
+ << DPL::GetErrnoString());
+ }
}
void TaskManifestFile::stepGenerateManifest()
#include <dpl/log/log.h>
#include <dpl/string.h>
#include <dpl/utils/wrt_utility.h>
+#include <dpl/errno_string.h>
#include <widget_install_context.h>
#include <widget_install/widget_install_errors.h>
#include <dpl/exception.h>
while ((entry = readdir(dir)) != NULL){
tempname = m_npsource + "/" + entry->d_name;
if(lstat(tempname.c_str(), &st) != 0) {
- LogDebug("Failed to call \"lstat\" (errno:" <<errno <<") on entry - skipping");
+ LogDebug("Failed to call \"lstat\" (errno:" <<errno
+ <<") on entry - skipping");
continue;
}
/* 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) {
- LogError("Directory detected instead of plugin file: " << entry->d_name);
+ if(strncmp(entry->d_name, "..", 2)!=0
+ && strncmp(entry->d_name, ".", 1)!=0) {
+ LogError("Directory detected instead of plugin file: "
+ << entry->d_name);
/* Subdirectories inside plugins/ARCH are not supported */
- closedir(dir);
+ if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
+ LogError("Failed to close dir: " << m_npsource
+ << " with error: " << DPL::GetErrnoString());
+ }
ThrowMsg(Exceptions::PluginsSubdirectory,
"Subdirectories inside plugins directory are not supported");
}
LogWarning("Non-plugin file found: " <<tempname);
}
}
- closedir(dir);
+ if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
+ LogError("Failed to close dir: " << m_npsource << " with error: "
+ << DPL::GetErrnoString());
+ }
/* If no .so files found (list is empty) abort taks*/
if(m_nplugins.empty()) {
LogError("No valid plugin files found");
#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;
}
}
while(dirent);
+ //closing the directory
+ if (-1 == TEMP_FAILURE_RETRY(closedir(pkgDir))) {
+ LogError("Failed to close dir: " << dirPath << " with error: "
+ << DPL::GetErrnoString());
+ }
}
void TaskUpdateFiles::StepResourceFilesBackup()
LogError("readdir() failed with " << DPL::GetErrnoString());
}
- if (closedir(localeDir)) {
- LogError("closedir() failed with " << DPL::GetErrnoString());
+ if (-1 == TEMP_FAILURE_RETRY(closedir(localeDir))) {
+ LogError("Failed to close dir: " << localePath << " with error: "
+ << DPL::GetErrnoString());
}
}
LogDebug("Invalid widget configuration file!");
// _rethrown_exception.Dump();
*pErrCode = WRT_WM_ERR_INVALID_ARCHIVE;
- closedir(dir);
+ if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
+ LogError("Failed to close dir: " << _currentPath << " with error: "
+ << DPL::GetErrnoString());
+ }
return false;
}
}
}
}
- closedir(dir);
+ if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
+ LogError("Failed to close dir: " << _currentPath << " with error: "
+ << DPL::GetErrnoString());
+ }
//We must have config.xml so leaveing if we doesn't
if (!has_config_xml) {
#include <dpl/zip_input.h>
#include <dpl/binary_queue.h>
#include <dpl/copy.h>
+#include <dpl/errno_string.h>
#include <dpl/utils/wrt_global_settings.h>
#include "option_parser.h"
#include <parser_runner.h>
::PostEvent(WRTInstallerNS::InstallPluginEvent());
if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
- LogError("Failed to close dir: " << dir);
+ LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
+ << DPL::GetErrnoString());
}
}
#include <dpl/assert.h>
#include <dpl/semaphore.h>
#include <dpl/sstream.h>
+#include <dpl/errno_string.h>
#include <libxml/parser.h>
#include <vconf.h>
}
if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
- LogError("Failed to close dir: " << dir);
+ LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
+ << DPL::GetErrnoString());
}
if (0 != unlink(installRequest.c_str())) {