{
LoggerD("Entered");
m_base_path = path;
- m_base_virt_path = filesystem::External::toVirtualPath(m_base_path);
+ m_base_virt_path = filesystem::External::cutVirtualRoot(m_base_path);
std::string::size_type pos = m_base_virt_path.find(filesystem::Path::getSeparator());
if (pos != std::string::npos)
{
#include <iomanip>
#include "common/logger.h"
-//TODO:
-//#include <FilesystemExternalUtils.h>
-
using namespace common;
namespace extension {
return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Invalid FileMode");
}
-// FilePtr fileReferenceToFile(JSContextRef context, JSValueRef fileReference)
-// {
-// auto g_ctx = GlobalContextManager::getInstance()->getGlobalContext(context);
-//
-// FilePtr file_ptr;
-// try {
-// file_ptr = JSFile::getPrivateObject(context, fileReference);
-// } catch (const TypeMismatchException &tme) {
-// LOGD("Use virtual path.");
-// std::string virtual_path =
-// JSUtil::JSValueToString(context, fileReference);
-// if (!External::isVirtualPath(virtual_path)) {
-// LOGE("FileReference can be File object or a virtual path");
-// throw TypeMismatchException(
-// "FileReference can be File object or a virtual path");
-// }
-// std::string string_path =
-// External::fromVirtualPath(virtual_path, g_ctx);
-// LOGD("Path: %s", string_path.c_str());
-//
-// PathPtr path = Path::create(string_path);
-// NodePtr node_ptr = Node::resolve(path);
-// file_ptr = FilePtr(new File(node_ptr, File::PermissionList()));
-// }
-//
-// return file_ptr;
-// }
-
void getBasePathAndName(const std::string& filepath,
std::string& out_basepath,
std::string& out_name)
common::PlatformResult fileModeToString(FileMode fm, std::string* fm_str);
common::PlatformResult stringToFileMode(std::string fmString, FileMode* fm);
-//extern Filesystem::FilePtr fileReferenceToFile(
-// JSContextRef context, JSValueRef fileReference);
-
/**
* Gets base path and name from full path string, example cases:
* full path | base path | name
namespace extension {
namespace filesystem {
+namespace {
+const std::string kVirtualRootsDirectory = "/opt/usr/media/";
+const std::string kSlash = "/";
+}
+
File::File(NodePtr node, const File::PermissionList &parentPermissions,
const std::string& original_location) :
m_node(node),
return m_original_fullpath;
}
-std::string External::toVirtualPath(const std::string& path)
+std::string External::cutVirtualRoot(const std::string& path)
{
- //TODO::implement this method
- LoggerW("Just STUB");
- return path;
+ LoggerD("Enter path %s", path.c_str());
+ std::string tmp_path = path.substr(kVirtualRootsDirectory.length());
+ return tmp_path.substr(tmp_path.find(kSlash));
}
} // filesystem
class External {
public:
- static std::string toVirtualPath(const std::string& path);
+ static std::string cutVirtualRoot(const std::string& path);
};
return PlatformResult(ErrorCode::NO_ERROR);
}
-// TODO Optimize it, maybe store a flag indicating that node is a root.
PlatformResult Node::getParent(NodePtr* node) const
{
LoggerD("Enter");
return PlatformResult(ErrorCode::NO_ERROR);
}
-std::string Node::toUri(int /*widgetId*/) const
-{
- LoggerD("Enter");
- // TODO I believe moving this feature to WrtWrapper would make more sense.
- return "file://" + m_path->getFullPath();
-}
-
bool Node::isSubPath(std::string aDirPath, PathPtr aFilePath)
{
LoggerD("Enter");
//! - OPT_RECURSIVE - remove node recursively.
common::PlatformResult remove(int options);
- std::string toUri(int widgetId) const;
-
static bool isSubPath(std::string aDirPath, PathPtr aFilePath);
private:
#include "common/logger.h"
#include "common/platform_exception.h"
+#include "common/tools.h"
#include "filesystem_file.h"
#include "archive_file.h"
namespace archive {
using namespace common;
+using common::tools::GetErrorString;
UnZip::UnZip(const std::string& filename) :
m_zipfile_name(filename),
UnZip::~UnZip()
{
LoggerD("Enter");
+ for (auto& x: path_access_map) {
+ LoggerD("Setting permission for path: %s [%d] ", x.first.c_str(), x.second);
+ if(chmod(x.first.c_str(), x.second) == -1) {
+ LoggerE("Couldn't set permissions for: [%s] errno: %s", x.first.c_str(),
+ GetErrorString(errno).c_str());
+ }
+ }
close();
}
size_t m_default_buffer_size;
bool m_is_open;
+ struct ComparePaths : public std::binary_function <bool, std::string, std::string> {
+ bool operator() (const std::string& lhs, const std::string& rhs) {
+ return lhs.length() > rhs.length();
+ }
+ };
+ std::map<std::string, __mode_t, ComparePaths> path_access_map;
+
friend class UnZipExtractRequest;
};
//LoggerD("left_part: [%s] status:%d", left_part.c_str(), status);
if(FPS_DIRECTORY != status) {
- //TODO investigate 0775 (mode) - filesystem assumed that file should have parent mode
+ // permissions would be changed after extract process would be finished,
+ // for now using default 0775
if(mkdir(left_part.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) {
LoggerE("Couldn't create new directory: %s errno: %s",
left_part.c_str(), GetErrorString(errno).c_str());
- //TODO check why mkdir return -1 but directory is successfully created
- // throw UnknownException(
- // "Could not create new directory");
}
}
}
m_file_info.tmu_date.tm_min,
m_file_info.tmu_date.tm_sec);
+ // change modify date and store permission for later update
+ storePermissions();
// Directory already exists we only need to update time
changeFileAccessAndModifyDate(m_new_dir_path, m_file_info.tmu_date);
"output path is invalid");
}
- //Try to create new directory in output directory
- //TODO investigate 0775 (mode) - filesystem assumed that file should have parent mode
+ // permissions would be changed after extract process would be finished,
+ // for now using default 0775
if(mkdir(m_new_dir_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) {
LoggerW("couldn't create new directory: %s errno: %s",
m_new_dir_path.c_str(), GetErrorString(errno).c_str());
- //TODO check why mkdir return -1 but directory is successfully created
- // throw UnknownException(
- // "Could not create new directory in extract output directory");
}
}
LoggerW("%s exists at output path: [%s], overwrite is set to FALSE",
(FPS_DIRECTORY == output_fstatus ? "Directory" : "File"),
m_output_filepath.c_str());
-
- //Just skip this file - TODO: this should be documented in WIDL
return PlatformResult(ErrorCode::INVALID_MODIFICATION_ERR, "file already exists.");
} else {
if(FPS_DIRECTORY == output_fstatus) {
m_output_file = NULL;
}
+ // change modify date and store permission for later update
+ storePermissions();
changeFileAccessAndModifyDate(m_output_filepath, m_file_info.tmu_date);
return PlatformResult(ErrorCode::NO_ERROR);
}
+void UnZipExtractRequest::storePermissions() {
+ // hold access information for later set
+ // The high 16 bits of the external file attributes seem to be used for OS-specific permissions
+ __mode_t mode = m_file_info.external_fa >> 16;
+ // check if proper permission mode is provided, if not use default 0775
+ if (mode == 0) {
+ mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
+ }
+ m_owner.path_access_map[m_output_filepath.c_str()] = mode;
+}
+
} //namespace archive
} //namespace extension
PlatformResult handleDirectoryEntry();
PlatformResult handleFileEntry();
PlatformResult prepareOutputSubdirectory();
+ void storePermissions();
//-----------------------------------------------------------------------------
//Input request variables