// limitations under the License.
//
-#include <dpl/log/log.h>
#include <Commons/Exception.h>
#include "AttachmentFactory.h"
#include "Attachments.h"
#include "Attachment.h"
#include <Commons/WrtAccess/WrtAccess.h>
#include <WidgetDB/WidgetDBMgr.h>
+#include <Logger.h>
using namespace std;
using namespace WrtDeviceApis;
IAttachmentPtr AttachmentFactory::createAttachment(const std::string& fullPath,
bool isVirtualPath)
{
- LogDebug("enter");
+ LoggerD("enter");
IAttachmentPtr attachment(new Attachment(fullPath, isVirtualPath));
if (!attachment->getIsCreatedProperly()) {
ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,
IAttachmentPtr AttachmentFactory::createAttachment(const std::string& path,
const std::string& mimeType)
{
- LogDebug("enter");
+ LoggerD("enter");
//check virtualPath
bool isVirtualPath = true;
std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context,
const std::string& real_path)
{
- LogDebug("path = " << real_path);
+ LoggerD("path = " << real_path);
//find virtual root
std::string root;
{
std::string vroot(PATH_DOWNLOADS);
tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
- LogDebug("tail = " << tail);
+ LoggerD("tail = " << tail);
vroot=VPATH_DOWNLOADS;
std::string virtualpath = vroot + AttachmentFactory::m_pathSeparator + tail ;
{
std::string vroot(PATH_DOCUMENTS);
tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
- LogDebug("tail = " << tail);
+ LoggerD("tail = " << tail);
vroot=VPATH_DOCUMENTS;
std::string virtualpath = vroot + AttachmentFactory::m_pathSeparator + tail ;
{
std::string vroot(PATH_SOUNDS);
tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
- LogDebug("tail = " << tail);
+ LoggerD("tail = " << tail);
vroot=VPATH_SOUNDS;
std::string virtualpath = vroot + AttachmentFactory::m_pathSeparator + tail ;
{
std::string vroot(PATH_IMAGES);
tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
- LogDebug("tail = " << tail);
+ LoggerD("tail = " << tail);
vroot=VPATH_IMAGES;
std::string virtualpath = vroot + AttachmentFactory::m_pathSeparator + tail ;
- LogDebug("virtualpath = " << virtualpath);
+ LoggerD("virtualpath = " << virtualpath);
return virtualpath;
}
{
std::string vroot(PATH_VIDEOS);
tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
- LogDebug("tail = " << tail);
+ LoggerD("tail = " << tail);
vroot=VPATH_VIDEOS;
std::string virtualpath = vroot + AttachmentFactory::m_pathSeparator + tail ;
- LogDebug("virtualpath = " << virtualpath);
+ LoggerD("virtualpath = " << virtualpath);
return virtualpath;
}
{
std::string vroot(widgetDB->getWidgetInstallationPath());
tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
- LogDebug("tail = " << tail);
+ LoggerD("tail = " << tail);
vroot=VPATH_WGT_PACKAGE;
std::string virtualpath = vroot + AttachmentFactory::m_pathSeparator + tail ;
- LogDebug("virtualpath = " << virtualpath);
+ LoggerD("virtualpath = " << virtualpath);
return virtualpath;
}
{
std::string vroot(widgetDB->getWidgetPersistentStoragePath());
tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
- LogDebug("tail = " << tail);
+ LoggerD("tail = " << tail);
vroot=VPATH_WGT_PRIVATE;
std::string virtualpath = vroot + AttachmentFactory::m_pathSeparator + tail ;
- LogDebug("virtualpath = " << virtualpath);
+ LoggerD("virtualpath = " << virtualpath);
return virtualpath;
}
{
std::string vroot(widgetDB->getWidgetTemporaryStoragePath());
tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
- LogDebug("tail = " << tail);
+ LoggerD("tail = " << tail);
vroot=VPATH_WGT_PRIVATE_TEMP;
std::string virtualpath = vroot + AttachmentFactory::m_pathSeparator + tail ;
- LogDebug("virtualpath = " << virtualpath);
+ LoggerD("virtualpath = " << virtualpath);
return virtualpath;
}
//another folder
//copy
- LogDebug("path = " << real_path);
+ LoggerD("path = " << real_path);
int widgetId = WrtAccessSingleton::Instance().getWidgetId();
int error = 0;
size_t pos = real_path.find_last_of("/");
if ((pos + 1) >= real_path.size()) {
- LogError("Problem with short name creation");
+ LoggerE("Problem with short name creation");
Throw(InvalidArgumentException);
}
std::string attachShortName = real_path.substr(pos + 1);
std::string privat_dir = widgetDB->getWidgetPersistentStoragePath();
if ( privat_dir.empty())
{
- LogError("Problem with short name creation");
+ LoggerE("Problem with short name creation");
Throw(InvalidArgumentException);
}
mode_t mask = umask(S_IWGRP | S_IWOTH);
error = mkstemp(buf);
umask(mask);
- LogDebug("mkstemp =" << error);
+ LoggerD("mkstemp =" << error);
- LogDebug("temp file=" << buf << AttachmentFactory::m_pathSeparator << attachShortName);
+ LoggerD("temp file=" << buf << AttachmentFactory::m_pathSeparator << attachShortName);
std::stringstream mkdir_cmd;
mkdir_cmd << MKDIR_COMMAND_NAME;
mkdir_cmd << " " << MKDIR_COMMAND_SWITCH_RECURSIVE;
mkdir_cmd << " \"" << privat_dir << buf << AttachmentFactory::m_pathSeparator << "\"";
- LogDebug("mkdir path=" << mkdir_cmd.str());
+ LoggerD("mkdir path=" << mkdir_cmd.str());
int result = system(mkdir_cmd.str().c_str());
if (-1 != result) {
cp_cmd << " \"" << real_path << "\"";
cp_cmd << " \"" << privat_dir << buf << AttachmentFactory::m_pathSeparator << attachShortName << "\"";
- LogDebug("cp path=" << cp_cmd.str());
+ LoggerD("cp path=" << cp_cmd.str());
result = system(cp_cmd.str().c_str());
if (-1 != result) {
const std::string& real_path)
{
//This file is not in list of root locations
- LogDebug("path = " << real_path);
+ LoggerD("path = " << real_path);
int widgetId = WrtAccessSingleton::Instance().getWidgetId();
int error = 0;
size_t pos = real_path.find_last_of("/");
if ((pos + 1) >= real_path.size()) {
- LogError("Problem with short name creation");
+ LoggerE("Problem with short name creation");
Throw(InvalidArgumentException);
}
std::string attachShortName = real_path.substr(pos + 1);
std::string privat_dir = widgetDB->getWidgetPersistentStoragePath();
if ( privat_dir.empty())
{
- LogError("Problem with short name creation");
+ LoggerE("Problem with short name creation");
Throw(InvalidArgumentException);
}
mode_t mask = umask(S_IWGRP | S_IWOTH);
error = mkstemp(buf);
umask(mask);
- LogDebug("mkstemp =" << error);
+ LoggerD("mkstemp =" << error);
- LogDebug("temp file=" << buf << AttachmentFactory::m_pathSeparator << attachShortName);
+ LoggerD("temp file=" << buf << AttachmentFactory::m_pathSeparator << attachShortName);
std::stringstream mkdir_cmd;
mkdir_cmd << MKDIR_COMMAND_NAME;
mkdir_cmd << " " << MKDIR_COMMAND_SWITCH_RECURSIVE;
mkdir_cmd << " \"" << privat_dir << buf << AttachmentFactory::m_pathSeparator << "\"";
- LogDebug("mkdir path=" << mkdir_cmd.str());
+ LoggerD("mkdir path=" << mkdir_cmd.str());
int result = system(mkdir_cmd.str().c_str()); //make folder in the wgt-private.
if (-1 != result) {
cp_cmd << " \"" << real_path << "\"";
cp_cmd << " \"" << privat_dir << buf << AttachmentFactory::m_pathSeparator << attachShortName << "\"";
- LogDebug("cp path=" << cp_cmd.str());
+ LoggerD("cp path=" << cp_cmd.str());
result = system(cp_cmd.str().c_str()); //copy
if (-1 != result) {
std::string AttachmentFactory::getRealPathFromVirtualPath(JSContextRef context,
const std::string& path)
{
- LogDebug("path = " << path);
+ LoggerD("path = " << path);
std::string root;
std::string tail;
} else {
root = path;
}
- LogDebug("root = " << root);
- LogDebug("tail = " << tail);
+ LoggerD("root = " << root);
+ LoggerD("tail = " << tail);
int widgetId = WrtAccessSingleton::Instance().getWidgetId();
WidgetDB::Api::IWidgetDBPtr widgetDB =
}
else
{ //exception
- LogDebug("Can't find root path");
+ LoggerD("Can't find root path");
ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,
"Attachment couldn't be created");
}
//remove folder
size_t pos = dummyFilePath.find_last_of("/");
if ((pos + 1) >= dummyFilePath.size()) {
- LogError("Problem with short name creation");
+ LoggerE("Problem with short name creation");
}
std::string folder = dummyFilePath.substr(0, pos);
- LogDebug("remove folder : " << folder);
+ LoggerD("remove folder : " << folder);
if ( 0 != remove(folder.c_str()))
{
- LogError("Remove Error");
+ LoggerE("Remove Error");
}
}
else
{
- LogDebug("remove file error : " << dummyFilePath);
+ LoggerD("remove file error : " << dummyFilePath);
}
}