filesystem::FilePtr file = archive_file_ptr->getFile();
if (!file) {
- LoggerE("File is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "File is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "File is null");
}
filesystem::NodePtr node = file->getNode();
if(!node) {
- LoggerE("Node is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Node is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Node is null");
}
const FileMode fm = archive_file_ptr->m_file_mode;
unsigned long long size = 0;
archive_file_ptr->setIsOpen(true);
}
else {
- LoggerE("The file is empty throwing: InvalidValuesException - Invalid ZIP archive");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid ZIP archive");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid ZIP archive", ("The file is empty"));
}
}
else {
guint id = g_idle_add(ArchiveFile::openTaskCompleteCB, this);
if (!id) {
- LoggerE("g_idle_add fails");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "g_idle_add fails");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "g_idle_add fails");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
guint id = g_idle_add(ArchiveFile::getEntriesTaskCompleteCB, this);
if (!id) {
- LoggerE("g_idle_add fails");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "g_idle_add fails");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "g_idle_add fails");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
}
if (it == entries->end()) {
- LoggerE("GetEntryByName Entry with name: [%s] not found", getName().c_str());
- LoggerE("Throwing NotFoundException - Entry not found");
- return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Entry not found");
+ SLoggerE("GetEntryByName Entry with name: [%s] not found", getName().c_str());
+ return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Entry not found");
}
setFileEntry(it->second);
guint id = g_idle_add(ArchiveFile::getEntryByNameTaskCompleteCB, this);
if (!id) {
- LoggerE("g_idle_add fails");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "g_idle_add fails");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "g_idle_add fails");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
LoggerD("Entered");
if(!m_file_entry) {
- LoggerE("ArchiveFileEntry is not set in callback");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not add file to archive");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not add file to archive", ("ArchiveFileEntry is not set in callback"));
}
if(!archive_file_ptr) {
- LoggerE("archive_file_ptr is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not extract archive file entry");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not extract archive file entry", ("archive_file_ptr is NULL"));
}
AddProgressCallback* callback = this;
LoggerD("Entered");
if(!m_archive_file_entry) {
- LoggerE("ArchiveFileEntry is not set in callback");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not extract archive file entry");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not extract archive file entry", ("ArchiveFileEntry is not set in callback"));
}
if(!archive_file_ptr) {
- LoggerE("archive_file_ptr is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not extract archive file entry");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not extract archive file entry", ("archive_file_ptr is NULL"));
}
UnZipPtr unzip;
if(1 == size) {
ArchiveFileHolder* holder = new(std::nothrow) ArchiveFileHolder();
if(!holder) {
- LoggerE("Memory allocation error");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Memory allocation error");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Memory allocation error");
}
holder->ptr = shared_from_this();
// (no risk of parallel operations on file)
if (!g_thread_pool_push(ArchiveManager::getInstance().getThreadPool(),
static_cast<gpointer>(holder), NULL)) {
- LoggerE("Thread creation failed");
delete holder;
holder = NULL;
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Thread creation failed");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Thread creation failed");
}
}
return PlatformResult(ErrorCode::NO_ERROR);
filesystem::FilePtr directory = callback->getDirectory();
if(!directory) {
- LoggerE("Directory is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Directory is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Directory is null");
} else {
if(!directory->getNode()){
- LoggerE("Node in directory is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Node is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Node in directory is null");
}
}
if(!m_file) {
- LoggerE("File is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "File is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "File is null");
} else {
if(!m_file->getNode()){
- LoggerE("Node in file is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Node in file is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Node in file is null");
}
}
return PlatformResult(ErrorCode::NO_ERROR);
}
else {
- LoggerW("m_created_as_new_empty_archive is false");
- LoggerE("Throwing InvalidStateException: File is not valid ZIP archive");
- return PlatformResult(ErrorCode::INVALID_STATE_ERR, "File is not valid ZIP archive");
+ return LogAndCreateResult(ErrorCode::INVALID_STATE_ERR, "File is not valid ZIP archive", ("m_created_as_new_empty_archive is false"));
}
}
{
LoggerD("Entered");
if(!callback) {
- LoggerE("callback is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not get list of files in archive");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not get list of files in archive", ("callback is NULL"));
}
if(!m_is_open){
- LoggerE("ArchiveFile closed - operation not permitted");
- return PlatformResult(ErrorCode::INVALID_STATE_ERR, "ArchiveFile closed - operation not permitted");
+ return LogAndCreateResult(ErrorCode::INVALID_STATE_ERR, "ArchiveFile closed - operation not permitted");
}
return addOperation(callback);
{
LoggerD("Entered");
if(!callback) {
- LoggerE("callback is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not extract all files from archive");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not extract all files from archive", ("callback is NULL"));
}
if(!m_is_open){
- LoggerE("ArchiveFile closed - operation not permitted");
- return PlatformResult(ErrorCode::INVALID_STATE_ERR, "ArchiveFile closed - operation not permitted");
+ return LogAndCreateResult(ErrorCode::INVALID_STATE_ERR, "ArchiveFile closed - operation not permitted");
}
return addOperation(callback);
{
LoggerD("Entered");
if(!callback) {
- LoggerE("callback is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not extract archive file entry");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not extract archive file entry", ("callback is NULL"));
}
// FIXME according to documentation:
// uncomment in case when this method have permission to throwing InvalidStateError
if(!m_is_open) {
- LoggerE("Archive is not opened");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Archive is not opened");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Archive is not opened");
}
return addOperation(callback);
{
LoggerD("Entered");
if(!callback) {
- LoggerE("callback is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not add file to archive");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not add file to archive", ("callback is NULL"));
}
if(FileMode::READ == m_file_mode) {
- LoggerE("Trying to add file when READ access mode selected");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Add not allowed for \"r\" access mode");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Add not allowed for \"r\" access mode", ("Trying to add file when READ access mode selected"));
}
if(!m_is_open){
- LoggerE("ArchiveFile closed - operation not permitted");
- return PlatformResult(ErrorCode::INVALID_STATE_ERR, "ArchiveFile closed - operation not permitted");
+ return LogAndCreateResult(ErrorCode::INVALID_STATE_ERR, "ArchiveFile closed - operation not permitted");
}
return addOperation(callback);
{
LoggerD("Entered");
if(!callback) {
- LoggerE("callback is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not get archive file entries by name");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not get archive file entries by name", ("callback is NULL"));
}
if(!m_is_open){
- LoggerE("ArchiveFile closed - operation not permitted");
- return PlatformResult(ErrorCode::INVALID_STATE_ERR, "ArchiveFile closed - operation not permitted");
+ return LogAndCreateResult(ErrorCode::INVALID_STATE_ERR, "ArchiveFile closed - operation not permitted");
}
return addOperation(callback);
{
LoggerD("Entered");
if(!m_is_open) {
- LoggerE("File is not opened");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "File is not opened");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "File is not opened");
}
if (!m_file) {
- LoggerE("m_file is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "File is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "File is null", ("m_file is null"));
}
filesystem::NodePtr node = m_file->getNode();
if(!node) {
- LoggerE("Node is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "File is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "File is null", ("Node is null"));
}
return UnZip::open(m_file->getNode()->getPath()->getFullPath(), unzip);
{
LoggerD("Entered");
if(!m_is_open) {
- LoggerE("File is not opened");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "File is not opened");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "File is not opened");
}
if (!m_file) {
- LoggerE("m_file is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "File is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "File is null", ("m_file is null"));
}
filesystem::NodePtr node = m_file->getNode();
if(!node) {
- LoggerE("Node is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Node is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Node is null");
}
return Zip::open(m_file->getNode()->getPath()->getFullPath(), zip);
return PlatformResult(ErrorCode::NO_ERROR);
}
else {
- LoggerW("m_created_as_new_empty_archive is false");
- LoggerE("Throwing InvalidStateException: File is not valid ZIP archive");
- return PlatformResult(ErrorCode::INVALID_STATE_ERR, "File is not valid ZIP archive");
+ return LogAndCreateResult(ErrorCode::INVALID_STATE_ERR, "File is not valid ZIP archive", ("m_created_as_new_empty_archive is false"));
}
}
PlatformResult ArchiveFileEntry::extractTo(ExtractEntryProgressCallback* callback)
{
if(!m_archive) {
- LOGE("m_archive is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not extract archive file entry");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not extract archive file entry", ("m_archive is NULL"));
}
//Callback should be associated with this instance of ArchiveFileEntry
}
void ArchiveInstance::PostError(const PlatformResult& e, double callback_id) {
+ LoggerD("Entered");
+
+ LoggerE("Posting an error: %d, message: %s", e.error_code(), e.message().c_str());
+
picojson::value val = picojson::value(picojson::object());
picojson::object& obj = val.get<picojson::object>();
obj[JSON_CALLBACK_ID] = picojson::value(callback_id);
}
file_ptr.reset(); //We need to create new empty file
} else if (FileMode::WRITE == fm) {
- LoggerE("open: %s with mode: \"w\" file exists and overwrite is FALSE!"
- " throwing InvalidModificationException", location_full_path.c_str());
+ SLoggerE("open: %s with mode: \"w\" file exists and overwrite is FALSE!",
+ location_full_path.c_str());
PostError(PlatformResult(ErrorCode::INVALID_MODIFICATION_ERR,
"Zip archive already exists"), callbackId);
delete callback;
}
} else {
LoggerE("Archive file not found");
- LoggerE("Filesystem exception - calling error callback");
PostError(PlatformResult(ErrorCode::NOT_FOUND_ERR, "Archive file not found"), callbackId);
delete callback;
callback = NULL;
if (result) {
ReportSuccess(out);
} else {
- ReportError(result, &out);
+ LogAndReportError(result, &out, ("Failed to open archive."));
}
}
*archive_file = it->second;
return PlatformResult(ErrorCode::NO_ERROR);
}
- LoggerE("Failed: Priv is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Priv is null");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Priv is null");
}
PlatformResult ArchiveManager::open(OpenCallbackData* callback)
*fm_str = "a";
break;
default:
- LoggerE("Unknown file mode");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown file mode");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown file mode");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
}
// In widl it's "TypeMismatchError" so this exception used
// instead of InvalidValues
- LoggerE("Invalid FileMode");
- return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Invalid FileMode");
+ return LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR, "Invalid FileMode");
}
void getBasePathAndName(const std::string& filepath,
DIR* dir = opendir(path->getFullPath().c_str());
if (!dir) {
- LoggerE("throw InvalidValuesException");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Node has been deleted from platform.");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Node has been deleted from platform.");
}
if (closedir(dir) != 0) {
- LoggerE("throw InvalidValuesException");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Could not close platform node.");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Could not close platform node.");
}
if (mode == "r") {
*granted = true;
return PlatformResult(ErrorCode::NO_ERROR);
}
- LoggerE("throw InvalidValuesException");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "invalid mode");
+
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "invalid mode");
}
break;
case NT_FILE:
}
else
{
- LoggerE("throw InvalidValuesException");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "invalid mode");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "invalid mode");
}
stream.open(path->getFullPath().c_str(), modeBit);
switch (errno)
{
case EACCES:
- LoggerE("throw InvalidValuesException for file:[%s]", path->getFullPath().c_str());
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Node access denied");
+ SLoggerE("File: [%s]", path->getFullPath().c_str());
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Node access denied");
break;
case ENOENT:
- LoggerE("throw NotFoundException for file:[%s]", path->getFullPath().c_str());
- return PlatformResult(ErrorCode::NOT_FOUND_ERR, "NotFoundError");
+ SLoggerE("File: [%s]", path->getFullPath().c_str());
+ return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "NotFoundError");
break;
default:
- LoggerE("throw IOException for file:[%s]", path->getFullPath().c_str());
- return PlatformResult(ErrorCode::IO_ERR, "Platform exception fail");
+ SLoggerE("File: [%s]", path->getFullPath().c_str());
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Platform exception fail");
}
}
if ((!S_ISDIR(info.st_mode)) & (!S_ISREG(info.st_mode)) && !S_ISLNK(info.st_mode)) {
- LoggerE("throw IOException for file:[%s]", path->getFullPath().c_str());
- return PlatformResult(ErrorCode::IO_ERR, "Platform node is of unsupported type.");
+ SLoggerE("File: [%s]", path->getFullPath().c_str());
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Platform node is of unsupported type.");
}
NodeType type = S_ISDIR(info.st_mode) ? NT_DIRECTORY : NT_FILE;
{
LoggerD("Enter");
if (m_type != NT_DIRECTORY) {
- LoggerW("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Not a directory.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Not a directory.");
}
return Node::resolve(*m_path + *path, node);
}
{
LoggerD("Enter");
if (m_type != NT_DIRECTORY) {
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Node is not directory.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Node is not directory.");
}
if ((m_perms & PERM_READ) == 0) {
- LoggerE("throw InvalidValuesException");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "No permission.");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "No permission.");
}
DIR* dir = opendir(m_path->getFullPath().c_str());
if (!dir) {
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Node has been deleted from platform.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Node has been deleted from platform.");
}
int err = 0;
}
if (closedir(dir) != 0) {
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Could not close platform node.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Could not close platform node.");
}
if (0 != err) {
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Error while reading directory.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Error while reading directory.");
}
*out_name_list = name_list;
LoggerD("Enter");
if (m_type != NT_DIRECTORY) {
- LoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
- LoggerE("throw IOException");
- LoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
- return PlatformResult(ErrorCode::IO_ERR, "Node is not directory.");
+ SLoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Node is not directory.");
}
if ((m_perms & PERM_READ) == 0) {
- LoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
- LoggerE("throw InvalidValuesException");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "No permission.");
+ SLoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "No permission.");
}
DIR* dir = opendir(m_path->getFullPath().c_str());
if (!dir) {
- LoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Node has been deleted from platform.");
+ SLoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Node has been deleted from platform.");
}
int err = 0;
}
if (closedir(dir) != 0) {
- LoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Could not close platform node.");
+ SLoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Could not close platform node.");
}
if (0 != err) {
- LoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Error while reading directory.");
+ SLoggerE("Path %s Perm %d", m_path->getFullPath().c_str(), m_perms);
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Error while reading directory.");
}
*out_node_list = node_list;
{
LoggerD("Enter");
if (m_type != NT_DIRECTORY) {
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Parent node is not a directory.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Parent node is not a directory.");
}
if ((m_perms & PERM_WRITE) == 0) {
- LoggerE("throw InvalidValuesException");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Not enough permissions.");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Not enough permissions.");
}
PathPtr childPath = *m_path + *path;
return result;
}
if (existed) {
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Node already exists.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Node already exists.");
}
switch (type) {
result = createAsDirectory(childPath, node, options);
break;
default:
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Unsupported node type.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Unsupported node type.");
}
if (result.error_code() != ErrorCode::NO_ERROR) {
LoggerE("Fail CreateAs...()");
if (!!(*node)) {
(*node)->m_perms = m_perms;
} else {
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Node creation error");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Node creation error");
}
return PlatformResult(ErrorCode::NO_ERROR);
result = removeAsDirectory(m_path, (options & OPT_RECURSIVE));
break;
default:
- LoggerE("throw UnknownError");
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Not supported value of m_type");
+ result = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Not supported value of m_type");
}
return result;
}
{
LoggerD("Enter");
if (m_type == NT_DIRECTORY) {
- LoggerE("Getting size for directories is not supported.");
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Getting size for directories is not supported.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Getting size for directories is not supported.");
}
struct stat info;
}
if (!S_ISREG(info.st_mode)) {
- LoggerE("Specified node is not a regular file.");
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Specified node is not a regular file.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Specified node is not a regular file.");
}
*size = info.st_size;
}
else if (ENAMETOOLONG == errno)
{
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "file name is too long");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "file name is too long");
}
else if (errno != ENOENT)
{
if (::stat(path->getFullPath().c_str(), &info) != 0)
{
- LoggerE("File: %s", path->getFullPath().c_str());
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Node does not exist or no access");
+ SLoggerE("File: %s", path->getFullPath().c_str());
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Node does not exist or no access");
}
*out_info = info;
return PlatformResult(ErrorCode::NO_ERROR);
FILE* file = std::fopen(path->getFullPath().c_str(), "wb");
if (!file) {
- LoggerE("fopen fails IOException throw for path [%s]",
- path->getFullPath().c_str());
- return PlatformResult(ErrorCode::IO_ERR, "Platform node could not be created.");
+ SLoggerE("fopen fails IOException throw for path [%s]",
+ path->getFullPath().c_str());
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Platform node could not be created.");
}
std::fclose(file);
return PlatformResult(ErrorCode::NO_ERROR);
if (mkdir(path->getFullPath().c_str(), S_IRWXU | S_IRWXG | S_IROTH |
S_IXOTH) != 0) {
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Platform node could not be created.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Platform node could not be created.");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
auto fullPath = path->getFullPath();
if (unlink(fullPath.c_str()) != 0) {
- LoggerE("remove [%s]", fullPath.c_str());
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Error while removing platform node.");
+ SLoggerE("remove [%s]", fullPath.c_str());
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Error while removing platform node.");
}
return PlatformResult(ErrorCode::NO_ERROR);
}
if (recursive) {
DIR* dir = opendir(path->getFullPath().c_str());
if (!dir) {
- LoggerE("File %s", path->getFullPath().c_str());
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Node does not exist or access denied.");
+ SLoggerE("File %s", path->getFullPath().c_str());
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Node does not exist or access denied.");
}
struct dirent entry = {0};
struct dirent* result = nullptr;
errno = 0;
if (rmdir(path->getFullPath().c_str()) != 0) {
if (errno == EEXIST) {
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Node has child nodes.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Node has child nodes.");
}
- LoggerE("throw IOException");
- return PlatformResult(ErrorCode::IO_ERR, "Error while removing platform node.");
+ return LogAndCreateResult(ErrorCode::IO_ERR, "Error while removing platform node.");
}
return PlatformResult(ErrorCode::NO_ERROR);
m_unzip = NULL;
if (errclose != UNZ_OK) {
- LoggerE("ret: %d",errclose);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(errclose, "unzClose()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(errclose, "unzClose()"), ("ret: %d", errclose));
}
m_is_open = false;
return PlatformResult(ErrorCode::NO_ERROR);
UnZipPtr unzip = UnZipPtr(new UnZip(filename));
if(!unzip->m_unzip) {
- LoggerE("unzOpen returned NULL : It means the file is invalid.");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Failed to open zip file");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Failed to open zip file", ("unzOpen returned NULL : It means the file is invalid."));
}
unzip->m_is_open = true;
*out_unzip = unzip;
{
LoggerD("Enter");
if(!m_is_open) {
- LoggerE("Failed to get list of entries - UnZip closed");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get list of files in zip archive");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to get list of files in zip archive");
}
unz_global_info gi;
int err = unzGetGlobalInfo (m_unzip, &gi);
if (UNZ_OK != err) {
- LoggerE("ret: %d",err);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGetGlobalInfo()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGetGlobalInfo()"), ("ret: %d", err));
}
char filename_inzip[512];
err = unzGetCurrentFileInfo(m_unzip, &file_info,
filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0);
if (err != UNZ_OK) {
- LoggerE("ret: %d",err);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGetCurrentFileInfo()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGetCurrentFileInfo()"), ("ret: %d", err));
}
LoggerD("file: %s | unc size: %d | comp size: %d", filename_inzip,
err = unzGoToNextFile(m_unzip);
if (UNZ_OK != err) {
- LoggerE("ret: %d",err);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGoToNextFile()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGoToNextFile()"), ("ret: %d", err));
}
}
}
{
LoggerD("Enter");
if(!m_is_open) {
- LoggerE("Failed to extract files - UnZip closed");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to extract zip archive");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to extract zip archive");
}
//
for (uLong i = 0; i < gi.number_entry; i++) {
if (callback->isCanceled()) {
- LoggerD("Operation cancelled");
- return PlatformResult(ErrorCode::OPERATION_CANCELED_ERR);
+ return LogAndCreateResult(ErrorCode::OPERATION_CANCELED_ERR, "Operation canceled");
}
result = extractCurrentFile(extract_path, std::string(), callback);
if ((i + 1) < gi.number_entry) {
err = unzGoToNextFile(m_unzip);
if (UNZ_OK != err) {
- LoggerE("ret: %d",err);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGoToNextFile()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGoToNextFile()"), ("ret: %d", err));
}
}
}
{
LoggerD("Enter");
if(!m_is_open) {
- LoggerE("Extract archive file entry failed - UnZip closed");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Extract archive file entry failed");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Extract archive file entry failed");
}
if(!callback) {
- LoggerE("callback is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Extract archive file entry failed");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Extract archive file entry failed", ("callback is NULL"));
}
if(!callback->getArchiveFileEntry()) {
- LoggerE("callback->getArchiveFileEntry() is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Extract archive file entry failed");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Extract archive file entry failed", ("callback->getArchiveFileEntry() is NULL"));
}
filesystem::FilePtr out_dir = callback->getDirectory();
if(!out_dir) {
- LoggerE("Output directory is not valid");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Output directory is not correct");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Output directory is not correct");
}
NodePtr out_node = out_dir->getNode();
if(!out_node) {
- LoggerE("Output directory is not valid");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Output directory is not correct");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Output directory is not correct");
}
PathPtr out_path = out_node->getPath();
if(!out_path) {
- LoggerE("Output directory is not valid");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Output directory is not correct");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Output directory is not correct");
}
auto entry_name_in_zip = callback->getArchiveFileEntry()->getName();
LoggerD("Enter");
ExtractDataHolder* h = static_cast<ExtractDataHolder*>(user_data);
if(!h) {
- LoggerE("ExtractDataHolder is NULL!");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not list content of zip archive");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not list content of zip archive", ("ExtractDataHolder is NULL!"));
}
PlatformResult result = h->unzip->extractCurrentFile(h->root_output_path,
for (uLong i = 0; i < gi.number_entry; i++) {
if (callback->isCanceled()) {
- LoggerD("Operation cancelled");
- return PlatformResult(ErrorCode::OPERATION_CANCELED_ERR);
+ return LogAndCreateResult(ErrorCode::OPERATION_CANCELED_ERR, "Operation canceled");
}
err = unzGetCurrentFileInfo(m_unzip, &cur_file_info,
tmp_fname, sizeof(tmp_fname), NULL, 0, NULL, 0);
if (UNZ_OK != err) {
- LoggerE("ret: %d",err);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGetCurrentFileInfo()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGetCurrentFileInfo()"), ("ret: %d", err));
}
const std::string cur_filename_in_zip(tmp_fname);
if ((i + 1) < gi.number_entry) {
err = unzGoToNextFile(m_unzip);
if (UNZ_OK != err) {
- LoggerE("ret: %d",err);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGoToNextFile()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGoToNextFile()"), ("ret: %d", err));
}
}
}
LoggerD("Entered");
if (callback->isCanceled()) {
- LoggerD("Operation cancelled");
- return PlatformResult(ErrorCode::OPERATION_CANCELED_ERR);
+ return LogAndCreateResult(ErrorCode::OPERATION_CANCELED_ERR, "Operation canceled");
}
LoggerD("extract_path: [%s] base_strip_path: [%s] ", extract_path.c_str(),
LoggerD("Enter");
int err = unzGetGlobalInfo(m_unzip, &out_global_info);
if (UNZ_OK != err) {
- LoggerE("ret: %d",err);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGetGlobalInfo()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGetGlobalInfo()"), ("ret: %d", err));
}
ArchiveStatistics astats;
return result;
}
if(0 == num_matched) {
- LoggerE("No matching file/directory: [%s] has been found in zip archive",
- optional_filter.c_str());
- LoggerE("Throwing NotFoundException - Could not extract file from archive");
- return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Could not extract file from archive");
+ SLoggerE("No matching file/directory: [%s] has been found in zip archive",
+ optional_filter.c_str());
+ return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Could not extract file from archive");
}
callback->setExpectedDecompressedSize(astats.uncompressed_size);
LoggerD("Enter");
UnZipExtractRequest req(owner, extract_path, base_strip_path, callback);
if(!req.m_callback){
- LoggerE("Callback is null");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Problem with callback functionality");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Problem with callback functionality", ("Callback is null"));
}
return req.run();
}
int err = unzGetCurrentFileInfo(m_owner.m_unzip, &m_file_info,
m_filename_inzip, sizeof(m_filename_inzip), NULL, 0, NULL, 0);
if (err != UNZ_OK) {
- LoggerE("ret: %d", err);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGetCurrentFileInfo()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzGetCurrentFileInfo()"), ("ret: %d", err));
}
LoggerD("Input from ZIP: m_filename_inzip: [%s]", m_filename_inzip);
if(m_callback->getOverwrite()) { //Is a file & overwrite is set:
std::string fn = removeTrailingDirectorySlashFromPath(m_new_dir_path);
if(std::remove(fn.c_str()) != 0) {
- LoggerE("std::remove(\"%s\") failed with errno: %s",
- m_new_dir_path.c_str(), GetErrorString(errno).c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not overwrite file in output directory");
+ SLoggerE("std::remove(\"%s\") failed with errno: %s",
+ m_new_dir_path.c_str(), GetErrorString(errno).c_str());
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not overwrite file in output directory");
}
} else { //Is a file & overwrite is not set:
- LoggerE("Failed to extract directory, "
- "file with the same name exists in output directory");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to extract directory, "
- "file with the same name exists in output directory");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to extract directory, "
+ "file with the same name exists in output directory");
}
}
//Try to create new directory in output directory
if(mkdir(m_new_dir_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) {
- LoggerE("Couldn't create new directory: %s errno: %s",
- m_new_dir_path.c_str(), GetErrorString(errno).c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not create new directory in extract output directory");
+ SLoggerE("Couldn't create new directory: %s errno: %s",
+ m_new_dir_path.c_str(), GetErrorString(errno).c_str());
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not create new directory in extract output directory");
}
}
//This zip entry points to file - verify that parent directory in output dir exists
if(FPS_DIRECTORY != m_new_dir_status) {
if(FPS_FILE == m_new_dir_status) {
- LoggerE("Path: %s is pointing to file not directory!",
- m_new_dir_path.c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to extract file from zip archive, "
- "output path is invalid");
+ SLoggerE("Path: %s is pointing to file not directory!",
+ m_new_dir_path.c_str());
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to extract file from zip archive, "
+ "output path is invalid");
}
// permissions would be changed after extract process would be finished,
}
if(m_callback->isCanceled()) {
- LoggerD("Operation cancelled");
- return PlatformResult(ErrorCode::OPERATION_CANCELED_ERR);
+ return LogAndCreateResult(ErrorCode::OPERATION_CANCELED_ERR, "Operation canceled");
}
const FilePathStatus output_fstatus = getPathStatus(m_output_filepath);
if(FPS_NOT_EXIST != output_fstatus) {
if(!m_callback->getOverwrite()) {
- LoggerW("%s exists at output path: [%s], overwrite is set to FALSE",
- (FPS_DIRECTORY == output_fstatus ? "Directory" : "File"),
- m_output_filepath.c_str());
- return PlatformResult(ErrorCode::INVALID_MODIFICATION_ERR, "file already exists.");
+ SLoggerE("%s exists at output path: [%s], overwrite is set to FALSE",
+ (FPS_DIRECTORY == output_fstatus ? "Directory" : "File"),
+ m_output_filepath.c_str());
+ return LogAndCreateResult(ErrorCode::INVALID_MODIFICATION_ERR, "File already exists.");
} else {
if(FPS_DIRECTORY == output_fstatus) {
filesystem::PathPtr path = filesystem::Path::create(m_output_filepath);
int err = unzOpenCurrentFilePassword(m_owner.m_unzip,
NULL); //password is not supported yet therefore passing NULL
if (UNZ_OK != err) {
- LoggerE("ret: %d", err);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzOpenCurrentFilePassword()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "unzOpenCurrentFilePassword()"), ("ret: %d", err));
}
//We have successfully opened curent file, therefore we should close it later
const size_t buffer_size = m_owner.m_default_buffer_size;
m_buffer = new(std::nothrow) char[buffer_size];
if(!m_buffer) {
- LoggerE("Couldn't allocate buffer with size: %s",
- bytesToReadableString(buffer_size).c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Memory allocation failed", ("Couldn't allocate buffer with size: %s",
+ bytesToReadableString(buffer_size).c_str()));
}
m_output_file = fopen(m_output_filepath.c_str(), "wb");
if(!m_output_file) {
- LoggerE("Couldn't open output file: %s", m_output_filepath.c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not create extracted file");
+ SLoggerE("Couldn't open output file: %s", m_output_filepath.c_str());
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not create extracted file");
}
m_delete_output_file = true;
ArchiveFileEntryPtrMapPtr entries = m_callback->getArchiveFile()->getEntryMap();
auto it = entries->find(m_filename_inzip);
if (it == entries->end()) {
- LoggerE("Entry not found");
- return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Entry not found");
+ return LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Entry not found");
}
while(true) {
if(m_callback->isCanceled()) {
- LoggerD("Operation cancelled");
- return PlatformResult(ErrorCode::OPERATION_CANCELED_ERR);
+ return LogAndCreateResult(ErrorCode::OPERATION_CANCELED_ERR, "Operation canceled");
}
int read_size = unzReadCurrentFile(m_owner.m_unzip, m_buffer, buffer_size);
if (read_size < 0) {
- LoggerE("unzReadCurrentFile failed with error code:%d for file:%s", read_size,
- m_filename_inzip);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to extract file from zip archive");
+ SLoggerE("unzReadCurrentFile failed with error code: %d for file: %s", read_size,
+ m_filename_inzip);
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Failed to extract file from zip archive");
}
else if(0 == read_size) {
}
if (fwrite(m_buffer, read_size, 1, m_output_file) != 1) {
- LoggerE("Couldn't write extracted data to output file:%s",
- m_output_filepath.c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not write extract file into output file");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not write extract file into output file");
}
if(extract_callback) {
m_zip = NULL;
if (errclose != ZIP_OK) {
- LoggerE("ret: %d", errclose);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(errclose, "zipClose()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(errclose, "zipClose()"), ("ret: %d", errclose));
}
m_is_open = false;
return PlatformResult(ErrorCode::NO_ERROR);
LoggerD("Entered");
ZipPtr zip = ZipPtr(new Zip(filename, ZOM_CREATE));
if(!zip->m_zip) {
- LoggerE("zipOpen returned NULL!");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Opening/creating zip file failed");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Opening/creating zip file failed", ("zipOpen returned NULL!"));
}
zip->m_is_open = true;
*out_zip = zip;
LoggerD("Entered");
ZipPtr zip = ZipPtr(new Zip(filename, ZOM_ADDINZIP));
if(!zip->m_zip) {
- LoggerE("zipOpen returned NULL!");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Opening/creating zip file failed");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Opening/creating zip file failed", ("zipOpen returned NULL!"));
}
zip->m_is_open = true;
*out_zip = zip;
{
LoggerD("Entered");
if(!callback) {
- LoggerE("callback is NULL!");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not add file(-s) to archive");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not add file(-s) to archive", ("callback is NULL!"));
}
if(!m_is_open) {
- LoggerE("Zip file not opened - exiting");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not add file(-s) to archive - zip file closed");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not add file(-s) to archive - zip file closed");
}
return ZipAddRequest::execute(*this, callback);
{
LoggerD("Enter");
if(!m_callback) {
- LoggerE("m_callback is NULL");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not add file(-s) to archive");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not add file(-s) to archive", ("m_callback is NULL"));
}
if(!m_callback->getFileEntry()) {
- LoggerE("m_callback->getFileEntry() is NULL");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Provided ArchiveFileEntry is not correct");
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Provided ArchiveFileEntry is not correct", ("m_callback->getFileEntry() is NULL"));
}
if(m_callback->isCanceled()) {
- LoggerD("Operation cancelled");
- return PlatformResult(ErrorCode::OPERATION_CANCELED_ERR);
+ return LogAndCreateResult(ErrorCode::OPERATION_CANCELED_ERR, "Operation canceled");
}
m_compression_level = m_callback->getFileEntry()->getCompressionLevel();
addNodeAndSubdirsToList(m_root_src_file_node, all_sub_nodes);
if(m_callback->isCanceled()) {
- LoggerD("Operation cancelled");
- return PlatformResult(ErrorCode::OPERATION_CANCELED_ERR);
+ return LogAndCreateResult(ErrorCode::OPERATION_CANCELED_ERR, "Operation canceled");
}
// Calculate total size to be compressed
bytesToReadableString(m_bytes_to_compress).c_str());
if(m_callback->isCanceled()) {
- LoggerD("Operation cancelled");
- return PlatformResult(ErrorCode::OPERATION_CANCELED_ERR);
+ return LogAndCreateResult(ErrorCode::OPERATION_CANCELED_ERR, "Operation canceled");
}
// Begin files compression
&is_directory, &conflicting_name)) {
if(!is_directory) {
- LoggerE("Entry: [%s] exists and is NOT directory!", conflicting_name.c_str());
-
- LoggerE("Throwing InvalidValuesException - File with the same name exists");
- return PlatformResult(ErrorCode::INVALID_VALUES_ERR, "File with the same name exists");
+ SLoggerE("Entry: [%s] exists and is NOT directory!", conflicting_name.c_str());
+ return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "File with the same name exists");
}
LoggerD("Directory: [%s] already exists -> nothing to do", name_in_zip.c_str());
}
if(m_callback->isCanceled()) {
- LoggerD("Operation cancelled");
- return PlatformResult(ErrorCode::OPERATION_CANCELED_ERR);
+ return LogAndCreateResult(ErrorCode::OPERATION_CANCELED_ERR, "Operation canceled");
}
zip_fileinfo new_dir_info;
NULL, 0);
if (err != ZIP_OK) {
- LoggerE("ret: %d", err);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "zipOpenNewFileInZip3()"));
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, getArchiveLogMessage(err, "zipOpenNewFileInZip3()"), ("ret: %d", err));
}
m_new_file_in_zip_opened = true;
}
if(m_callback->isCanceled()) {
- LoggerD("Operation cancelled");
- return PlatformResult(ErrorCode::OPERATION_CANCELED_ERR);
+ return LogAndCreateResult(ErrorCode::OPERATION_CANCELED_ERR, "Operation canceled");
}
std::string conflicting_name;
if(m_callback->getArchiveFile()->isEntryWithNameInArchive(name_in_zip,
NULL, &conflicting_name)) {
- LoggerE("Cannot add new entry with name name: [%s] "
- "it would conflict with existing entry: [%s]",
- name_in_zip.c_str(), conflicting_name.c_str());
+ SLoggerE("Cannot add new entry with name name: [%s] "
+ "it would conflict with existing entry: [%s]",
+ name_in_zip.c_str(), conflicting_name.c_str());
- LoggerE("Throwing InvalidModificationException - Archive entry name conflicts");
- return PlatformResult(ErrorCode::INVALID_MODIFICATION_ERR, "Archive entry name conflicts");
+ return LogAndCreateResult(ErrorCode::INVALID_MODIFICATION_ERR, "Archive entry name conflicts");
}
int err = zipOpenNewFileInZip3(m_owner.m_zip, name_in_zip.c_str(), &new_file_info,
NULL, 0);
if (err != ZIP_OK) {
- LoggerE("Error opening new file: [%s] in zipfile", name_in_zip.c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not add new file to zip archive");
+ SLoggerE("Error opening new file: [%s] in zipfile", name_in_zip.c_str());
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not add new file to zip archive");
}
m_new_file_in_zip_opened = true;
if(src_file_node->getType() == filesystem::NT_FILE) {
m_input_file = fopen(src_file_path.c_str(), "rb");
if (!m_input_file) {
- LoggerE("Error opening source file:%s", src_file_path.c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not open file to be added");
+ SLoggerE("Error opening source file: %s", src_file_path.c_str());
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not open file to be added");
}
//Get file length
if(!m_buffer) {
m_buffer = new(std::nothrow) char[m_buffer_size];
if(!m_buffer) {
- LoggerE("Couldn't allocate m_buffer");
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Memory allocation error");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Memory allocation error");
}
}
size_read = fread(m_buffer, 1, m_buffer_size, m_input_file);
if (size_read < m_buffer_size &&
feof(m_input_file) == 0) {
- LoggerE("Error reading source file: %s\n", src_file_path.c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "New file addition failed");
+ SLoggerE("Error reading source file: %s", src_file_path.c_str());
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "New file addition failed");
}
LoggerD("Read: %d bytes from input file:[%s]", size_read,
if (size_read > 0) {
err = zipWriteInFileInZip (m_owner.m_zip, m_buffer, size_read);
if (err < 0) {
- LoggerE("Error during adding file: %s into zip archive",
- src_file_path.c_str());
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "New file addition failed");
+ SLoggerE("Error during adding file: %s into zip archive",
+ src_file_path.c_str());
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "New file addition failed");
}
}
} while (size_read > 0 && total_bytes_read < in_file_size);
if(in_file_size != total_bytes_read) {
- LoggerE("in_file_size(%d) != total_bytes_read(%d)", in_file_size,
- total_bytes_read);
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not add file to archive");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Could not add file to archive", ("in_file_size(%d) != total_bytes_read(%d)", in_file_size,
+ total_bytes_read));
}
fclose(m_input_file);