[DEV] change etk::fs in etk::path

This commit is contained in:
Edouard DUPIN 2018-09-13 23:16:14 +02:00
parent 0997e7a39d
commit 9b318f4cac
22 changed files with 226 additions and 326 deletions

View File

@ -11,7 +11,7 @@
#include <etk/Map.hpp> #include <etk/Map.hpp>
#include <ethread/Mutex.hpp> #include <ethread/Mutex.hpp>
#include <ememory/memory.hpp> #include <ememory/memory.hpp>
#include <etk/fs/Path.hpp> #include <etk/path/Path.hpp>
#include <etk/uri/Uri.hpp> #include <etk/uri/Uri.hpp>
namespace etk { namespace etk {

View File

@ -12,7 +12,7 @@
#include <etk/typeInfo.hpp> #include <etk/typeInfo.hpp>
#include <etk/Allocator.hpp> #include <etk/Allocator.hpp>
#include <etk/theme/theme.hpp> #include <etk/theme/theme.hpp>
#include <etk/fs/fileSystem.hpp> #include <etk/path/fileSystem.hpp>
#include <etk/uri/provider/provider.hpp> #include <etk/uri/provider/provider.hpp>
static int32_t nbTimeInit = 0; static int32_t nbTimeInit = 0;
@ -48,7 +48,7 @@ void etk::init(int _argc, const char** _argv) {
} else { } else {
TK_INFO("ETK system init (BEGIN) "); TK_INFO("ETK system init (BEGIN) ");
} }
elog::init(_argc, _argv, etk::fs::getBinaryName()); elog::init(_argc, _argv, etk::path::getBinaryName());
etk::uri::provider::init(); etk::uri::provider::init();
etk::theme::init(); etk::theme::init();
for (int32_t iii=0; iii<_argc ; ++iii) { for (int32_t iii=0; iii<_argc ; ++iii) {
@ -82,5 +82,5 @@ void etk::init(int _argc, const char** _argv) {
} }
etk::String etk::getApplicationName() { etk::String etk::getApplicationName() {
return etk::fs::getBinaryName(); return etk::path::getBinaryName();
} }

View File

@ -1,42 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2018, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <etk/fs/Type.hpp>
etk::Stream& etk::operator <<(etk::Stream &_os, const enum etk::fs::Type &_obj) {
switch (_obj) {
case etk::fs::Type::Unknow:
_os << "etk::fs::Type::Unknow";
break;
case etk::fs::Type::Direct:
_os << "etk::fs::Type::Direct";
break;
case etk::fs::Type::Home:
_os << "etk::fs::Type::Home";
break;
case etk::fs::Type::Data:
_os << "etk::fs::Type::Data";
break;
case etk::fs::Type::UserData:
_os << "etk::fs::Type::UserData";
break;
case etk::fs::Type::Cache:
_os << "etk::fs::Type::Cache";
break;
case etk::fs::Type::Theme:
_os << "etk::fs::Type::Theme";
break;
case etk::fs::Type::ThemeData:
_os << "etk::fs::Type::Theme(DATA)";
break;
default:
_os << "etk::fs::Type::????";
break;
}
return _os;
}

View File

@ -1,55 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2018, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <etk/Stream.hpp>
#pragma once
namespace etk {
namespace fs {
/**
* @brief Type of the file/folder/... accessible in the Node
*/
enum class Type {
Unknow, //!< Unknow type of the node (many time no file name seted)
// user might done abstraction ==> acces of the sdcard when possible ...
Direct, //!< Access at the file System with a direct naming like "/home/plop/xxx.txt"
// depend on case
// - PC : ~/
// - Android : /sdcard/
// - Apple : ????
Home, //!< acces at the home path of the system (with name of the current user)
// depend of the case
// - PC : /usr/shared/programName/
// - Android : Internal at the executable file (pointer on static area)
// - Apple : Internal at the executable file
Data, //!< Access on the application data (internal application data are the one provided with the binary)
// depend on case
// - PC : ~/.local/programName/
// - Android : /data/data/programName/files/
// - Apple : ????
UserData, //!< Access on the user application data (where the data are stored when the application stop)
// depend on case
// - PC : ~/.programName/cache/
// - Android : /data/data/programName/cache/
// - Apple : ????
Cache, //!< Access on the application temporary path (remove when user want and whe the compter restart or have not enought memory)
// depend on case
// - try on USER_DATA:/theme/themeName/xxx
// - try on DATA:/theme/themeName/xxx
// and jump to the default theme file
// - try on USER_DATA:/theme/default/xxx
// - try on DATA:/theme/default/xxx
Theme, //!< Theme area
ThemeData //!< Theme data area
};
}
//! @not_in_doc
etk::Stream& operator <<(etk::Stream &_os, const etk::fs::Type &_obj);
}

View File

@ -6,7 +6,7 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/io/File.hpp> #include <etk/io/File.hpp>
#include <etk/debug.hpp> #include <etk/debug.hpp>
#include <etk/fs/fileSystem.hpp> #include <etk/path/fileSystem.hpp>
#include <sys/stat.h> #include <sys/stat.h>
extern "C" { extern "C" {
#include <errno.h> #include <errno.h>
@ -67,7 +67,7 @@ bool etk::io::File::close() {
} }
uint64_t etk::io::File::size() { uint64_t etk::io::File::size() {
return etk::fs::fileSize(m_path); return etk::path::fileSize(m_path);
} }
bool etk::io::File::seek(uint64_t _offset, enum etk::io::SeekMode _origin) { bool etk::io::File::seek(uint64_t _offset, enum etk::io::SeekMode _origin) {

View File

@ -8,7 +8,7 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/io/Interface.hpp> #include <etk/io/Interface.hpp>
#include <etk/io/File.hpp> #include <etk/io/File.hpp>
#include <etk/fs/Path.hpp> #include <etk/path/Path.hpp>
namespace etk { namespace etk {
namespace io { namespace io {

View File

@ -7,7 +7,7 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/io/Interface.hpp> #include <etk/io/Interface.hpp>
#include <etk/fs/Path.hpp> #include <etk/path/Path.hpp>
#include <ememory/SharedPtr.hpp> #include <ememory/SharedPtr.hpp>
#include <etk/archive/Archive.hpp> #include <etk/archive/Archive.hpp>

View File

@ -3,10 +3,10 @@
* @copyright 2018, Edouard DUPIN, all right reserved * @copyright 2018, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
#include <etk/fs/Path.hpp> #include <etk/path/Path.hpp>
#include <etk/debug.hpp> #include <etk/debug.hpp>
#include <etk/Exception.hpp> #include <etk/Exception.hpp>
#include <etk/fs/fileSystem.hpp> #include <etk/path/fileSystem.hpp>
#include <etk/typeInfo.hpp> #include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(etk::Path); ETK_DECLARE_TYPE(etk::Path);
@ -23,7 +23,7 @@ static etk::String simplifyPath(etk::String _input) {
return _input; return _input;
} }
if (_input[0] == '~') { if (_input[0] == '~') {
_input = etk::fs::getHomePath().getString() + "/" + _input.extract(1); _input = etk::path::getHomePath().getString() + "/" + _input.extract(1);
} }
// step 2 : remove all '//' // step 2 : remove all '//'
TK_DBG_MODE("Simplify(2) : '" << _input << "'"); TK_DBG_MODE("Simplify(2) : '" << _input << "'");
@ -192,7 +192,7 @@ etk::String etk::Path::getRelative() const {
if (isRelative() == true) { if (isRelative() == true) {
return m_data; return m_data;
} }
etk::String execPath = etk::fs::getExecutionPath().getString(); etk::String execPath = etk::path::getExecutionPath().getString();
etk::String currentPath = m_data; etk::String currentPath = m_data;
etk::Vector<etk::String> execPathSplit = execPath.split('/'); etk::Vector<etk::String> execPathSplit = execPath.split('/');
etk::Vector<etk::String> currentPathSplit = currentPath.split('/'); etk::Vector<etk::String> currentPathSplit = currentPath.split('/');
@ -235,7 +235,7 @@ etk::String etk::Path::getAbsolute() const {
if (isAbsolute() == true) { if (isAbsolute() == true) {
return m_data; return m_data;
} }
return (etk::fs::getExecutionPath() / m_data).getString(); return (etk::path::getExecutionPath() / m_data).getString();
} }
etk::String etk::Path::getAbsoluteWindows() const { etk::String etk::Path::getAbsoluteWindows() const {

View File

@ -6,7 +6,6 @@
#pragma once #pragma once
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/fs/Type.hpp>
#include <etk/String.hpp> #include <etk/String.hpp>
namespace etk { namespace etk {

View File

@ -7,11 +7,11 @@
#include <etk/stdTools.hpp> #include <etk/stdTools.hpp>
#include <etk/typeInfo.hpp> #include <etk/typeInfo.hpp>
#include <etk/fs/Permissions.hpp> #include <etk/path/Permissions.hpp>
#include <etk/typeInfo.hpp> #include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(etk::fs::Permissions); ETK_DECLARE_TYPE(etk::path::Permissions);
// Right Flags: // Right Flags:
@ -28,45 +28,45 @@ enum {
}; };
etk::fs::Permissions etk::fs::Permissions::genericFolder{right_user_execute|right_user_write|right_user_read|right_group_read|right_group_execute}; etk::path::Permissions etk::path::Permissions::genericFolder{right_user_execute|right_user_write|right_user_read|right_group_read|right_group_execute};
etk::fs::Permissions etk::fs::Permissions::genericFile{right_user_write|right_user_read|right_group_read}; etk::path::Permissions etk::path::Permissions::genericFile{right_user_write|right_user_read|right_group_read};
etk::fs::Permissions::Permissions(uint16_t _newRight) : etk::path::Permissions::Permissions(uint16_t _newRight) :
m_rights(_newRight&0x01FF) { m_rights(_newRight&0x01FF) {
} }
uint16_t etk::fs::Permissions::getRightValue() const { uint16_t etk::path::Permissions::getRightValue() const {
return m_rights; return m_rights;
} }
etk::fs::Permissions& etk::fs::Permissions::operator= (const etk::fs::Permissions &_obj ) { etk::path::Permissions& etk::path::Permissions::operator= (const etk::path::Permissions &_obj ) {
m_rights = _obj.m_rights; m_rights = _obj.m_rights;
return *this; return *this;
} }
etk::fs::Permissions& etk::fs::Permissions::operator= (const uint32_t _newVal) { etk::path::Permissions& etk::path::Permissions::operator= (const uint32_t _newVal) {
m_rights = _newVal&0x01FF; m_rights = _newVal&0x01FF;
return *this; return *this;
} }
void etk::fs::Permissions::clear() { void etk::path::Permissions::clear() {
m_rights = 0; m_rights = 0;
} }
bool etk::fs::Permissions::isUserReadable() const { bool etk::path::Permissions::isUserReadable() const {
return ((m_rights&right_user_read)!=0)?true:false; return ((m_rights&right_user_read)!=0)?true:false;
} }
bool etk::fs::Permissions::isUserWritable() const { bool etk::path::Permissions::isUserWritable() const {
return ((m_rights&right_user_write)!=0)?true:false; return ((m_rights&right_user_write)!=0)?true:false;
} }
bool etk::fs::Permissions::isUserRunable() const { bool etk::path::Permissions::isUserRunable() const {
return ((m_rights&right_user_execute)!=0)?true:false; return ((m_rights&right_user_execute)!=0)?true:false;
} }
void etk::fs::Permissions::setUserReadable(bool _newStatus) { void etk::path::Permissions::setUserReadable(bool _newStatus) {
// reset the flag : // reset the flag :
m_rights &= (0xFFFFFFFF - right_user_read); m_rights &= (0xFFFFFFFF - right_user_read);
if (_newStatus == true) { if (_newStatus == true) {
@ -74,7 +74,7 @@ void etk::fs::Permissions::setUserReadable(bool _newStatus) {
} }
} }
void etk::fs::Permissions::setUserWritable(bool _newStatus) { void etk::path::Permissions::setUserWritable(bool _newStatus) {
// reset the flag : // reset the flag :
m_rights &= (0xFFFFFFFF - right_user_write); m_rights &= (0xFFFFFFFF - right_user_write);
if (_newStatus == true) { if (_newStatus == true) {
@ -82,7 +82,7 @@ void etk::fs::Permissions::setUserWritable(bool _newStatus) {
} }
} }
void etk::fs::Permissions::setUserRunable(bool _newStatus) { void etk::path::Permissions::setUserRunable(bool _newStatus) {
// reset the flag : // reset the flag :
m_rights &= (0xFFFFFFFF - right_user_execute); m_rights &= (0xFFFFFFFF - right_user_execute);
if (_newStatus == true) { if (_newStatus == true) {
@ -90,19 +90,19 @@ void etk::fs::Permissions::setUserRunable(bool _newStatus) {
} }
} }
bool etk::fs::Permissions::isGroupReadable() const { bool etk::path::Permissions::isGroupReadable() const {
return ((m_rights&right_group_read)!=0)?true:false; return ((m_rights&right_group_read)!=0)?true:false;
} }
bool etk::fs::Permissions::isGroupWritable() const { bool etk::path::Permissions::isGroupWritable() const {
return ((m_rights&right_group_write)!=0)?true:false; return ((m_rights&right_group_write)!=0)?true:false;
} }
bool etk::fs::Permissions::isGroupRunable() const { bool etk::path::Permissions::isGroupRunable() const {
return ((m_rights&right_group_execute)!=0)?true:false; return ((m_rights&right_group_execute)!=0)?true:false;
} }
void etk::fs::Permissions::setGroupReadable(bool _newStatus) { void etk::path::Permissions::setGroupReadable(bool _newStatus) {
// reset the flag : // reset the flag :
m_rights &= (0xFFFFFFFF - right_group_read); m_rights &= (0xFFFFFFFF - right_group_read);
if (true == _newStatus) { if (true == _newStatus) {
@ -110,7 +110,7 @@ void etk::fs::Permissions::setGroupReadable(bool _newStatus) {
} }
} }
void etk::fs::Permissions::setGroupWritable(bool _newStatus) { void etk::path::Permissions::setGroupWritable(bool _newStatus) {
// reset the flag : // reset the flag :
m_rights &= (0xFFFFFFFF - right_group_write); m_rights &= (0xFFFFFFFF - right_group_write);
if (true == _newStatus) { if (true == _newStatus) {
@ -118,7 +118,7 @@ void etk::fs::Permissions::setGroupWritable(bool _newStatus) {
} }
} }
void etk::fs::Permissions::setGroupRunable(bool _newStatus) { void etk::path::Permissions::setGroupRunable(bool _newStatus) {
// reset the flag : // reset the flag :
m_rights &= (0xFFFFFFFF - right_group_execute); m_rights &= (0xFFFFFFFF - right_group_execute);
if (true == _newStatus) { if (true == _newStatus) {
@ -126,19 +126,19 @@ void etk::fs::Permissions::setGroupRunable(bool _newStatus) {
} }
} }
bool etk::fs::Permissions::isOtherReadable() const { bool etk::path::Permissions::isOtherReadable() const {
return ((m_rights&right_other_read) != 0)?true:false; return ((m_rights&right_other_read) != 0)?true:false;
} }
bool etk::fs::Permissions::isOtherWritable() const { bool etk::path::Permissions::isOtherWritable() const {
return ((m_rights&right_other_write) != 0)?true:false; return ((m_rights&right_other_write) != 0)?true:false;
} }
bool etk::fs::Permissions::isOtherRunable() const { bool etk::path::Permissions::isOtherRunable() const {
return ((m_rights&right_other_execute) != 0)?true:false; return ((m_rights&right_other_execute) != 0)?true:false;
} }
void etk::fs::Permissions::setOtherReadable(bool _newStatus) { void etk::path::Permissions::setOtherReadable(bool _newStatus) {
// reset the flag: // reset the flag:
m_rights &= (0xFFFFFFFF - right_other_read); m_rights &= (0xFFFFFFFF - right_other_read);
if (_newStatus == true) { if (_newStatus == true) {
@ -146,7 +146,7 @@ void etk::fs::Permissions::setOtherReadable(bool _newStatus) {
} }
} }
void etk::fs::Permissions::setOtherWritable(bool _newStatus) { void etk::path::Permissions::setOtherWritable(bool _newStatus) {
// reset the flag : // reset the flag :
m_rights &= (0xFFFFFFFF - right_other_write); m_rights &= (0xFFFFFFFF - right_other_write);
if (_newStatus == true) { if (_newStatus == true) {
@ -154,7 +154,7 @@ void etk::fs::Permissions::setOtherWritable(bool _newStatus) {
} }
} }
void etk::fs::Permissions::setOtherRunable(bool _newStatus) { void etk::path::Permissions::setOtherRunable(bool _newStatus) {
// reset the flag : // reset the flag :
m_rights &= (0xFFFFFFFF - right_other_execute); m_rights &= (0xFFFFFFFF - right_other_execute);
if (_newStatus == true) { if (_newStatus == true) {
@ -162,7 +162,7 @@ void etk::fs::Permissions::setOtherRunable(bool _newStatus) {
} }
} }
etk::String etk::fs::Permissions::getRight() const { etk::String etk::path::Permissions::getRight() const {
etk::String tmp; etk::String tmp;
if (isUserReadable() == true) { if (isUserReadable() == true) {
tmp += "r"; tmp += "r";
@ -213,7 +213,7 @@ etk::String etk::fs::Permissions::getRight() const {
} }
etk::Stream& etk::operator <<(etk::Stream &_os, const etk::fs::Permissions &_obj) { etk::Stream& etk::operator <<(etk::Stream &_os, const etk::path::Permissions &_obj) {
_os << _obj.getRight(); _os << _obj.getRight();
return _os; return _os;
}; };

View File

@ -11,7 +11,7 @@
#include <etk/String.hpp> #include <etk/String.hpp>
namespace etk { namespace etk {
namespace fs { namespace path {
/** /**
* @brief File System Right management * @brief File System Right management
*/ */
@ -155,7 +155,7 @@ namespace etk {
}; };
} }
//! @not_in_doc //! @not_in_doc
etk::Stream& operator <<(etk::Stream &_os, const etk::fs::Permissions &_obj); etk::Stream& operator <<(etk::Stream &_os, const etk::path::Permissions &_obj);
} }

View File

@ -3,7 +3,7 @@
* @copyright 2018, Edouard DUPIN, all right reserved * @copyright 2018, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
#include <etk/fs/fileSystem.hpp> #include <etk/path/fileSystem.hpp>
#include <etk/debug.hpp> #include <etk/debug.hpp>
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
@ -29,26 +29,26 @@ extern "C" {
#include <etk/io/File.hpp> #include <etk/io/File.hpp>
#include <etk/io/SeekMode.hpp> #include <etk/io/SeekMode.hpp>
bool etk::fs::copy(const etk::Path& _path1, const etk::Path& _path2) { bool etk::path::copy(const etk::Path& _path1, const etk::Path& _path2) {
return false; return false;
} }
bool etk::fs::copyDirectory(const etk::Path& _path1, const etk::Path& _path2, bool _recursive) { bool etk::path::copyDirectory(const etk::Path& _path1, const etk::Path& _path2, bool _recursive) {
return false; return false;
} }
bool etk::fs::copyFile(const etk::Path& _path1, const etk::Path& _path2) { bool etk::path::copyFile(const etk::Path& _path1, const etk::Path& _path2) {
return false; return false;
} }
bool etk::fs::move(const etk::Path& _path1, const etk::Path& _path2) { bool etk::path::move(const etk::Path& _path1, const etk::Path& _path2) {
TK_VERBOSE("Move : \"" << _path1 << "\" ==> \"" << _path2 << "\""); TK_VERBOSE("Move : \"" << _path1 << "\" ==> \"" << _path2 << "\"");
if (etk::fs::exist(_path2) == true) { if (etk::path::exist(_path2) == true) {
removes(_path2); removes(_path2);
} }
// create path to be sure it exist ... // create path to be sure it exist ...
etk::fs::makeDirectories(_path2.getParent()); etk::path::makeDirectories(_path2.getParent());
int32_t res = ::rename(_path1.getNative().c_str(), _path2.getNative().c_str()); int32_t res = ::rename(_path1.getNative().c_str(), _path2.getNative().c_str());
if (res != 0) { if (res != 0) {
TK_ERROR("Can not move the file: '" << _path1 << "' ==> '" << _path2 << "' errno" << errno << " (" << strerror(errno) << ")"); TK_ERROR("Can not move the file: '" << _path1 << "' ==> '" << _path2 << "' errno" << errno << " (" << strerror(errno) << ")");
@ -57,27 +57,27 @@ bool etk::fs::move(const etk::Path& _path1, const etk::Path& _path2) {
return true; return true;
} }
bool etk::fs::moveDirectory(const etk::Path& _path1, const etk::Path& _path2) { bool etk::path::moveDirectory(const etk::Path& _path1, const etk::Path& _path2) {
return etk::fs::move(_path1, _path2); return etk::path::move(_path1, _path2);
} }
bool etk::fs::moveFile(const etk::Path& _path1, const etk::Path& _path2) { bool etk::path::moveFile(const etk::Path& _path1, const etk::Path& _path2) {
return etk::fs::move(_path1, _path2); return etk::path::move(_path1, _path2);
} }
namespace detail { namespace detail {
bool removeDirectories(const etk::Path& _path, bool _recursive); bool removeDirectories(const etk::Path& _path, bool _recursive);
bool removes(const etk::Path& _path, bool _recursive) { bool removes(const etk::Path& _path, bool _recursive) {
TK_VERBOSE("remove: " << _path); TK_VERBOSE("remove: " << _path);
if (etk::fs::isDirectory(_path) == true) { if (etk::path::isDirectory(_path) == true) {
return detail::removeDirectories(_path, _recursive); return detail::removeDirectories(_path, _recursive);
} }
return etk::fs::removeFile(_path); return etk::path::removeFile(_path);
} }
bool removeDirectories(const etk::Path& _path, bool _recursive) { bool removeDirectories(const etk::Path& _path, bool _recursive) {
TK_VERBOSE("remove Directory: " << _path); TK_VERBOSE("remove Directory: " << _path);
if (_recursive == true) { if (_recursive == true) {
etk::Vector<etk::Path> elements = etk::fs::list(_path); etk::Vector<etk::Path> elements = etk::path::list(_path);
for (auto& it : elements) { for (auto& it : elements) {
detail::removes(it, _recursive); detail::removes(it, _recursive);
} }
@ -92,23 +92,23 @@ namespace detail {
} }
} }
bool etk::fs::remove(const etk::Path& _path) { bool etk::path::remove(const etk::Path& _path) {
return detail::removes(_path, false); return detail::removes(_path, false);
} }
bool etk::fs::removes(const etk::Path& _path) { bool etk::path::removes(const etk::Path& _path) {
return detail::removes(_path, true); return detail::removes(_path, true);
} }
bool etk::fs::removeDirectory(const etk::Path& _path) { bool etk::path::removeDirectory(const etk::Path& _path) {
return detail::removeDirectories(_path, false); return detail::removeDirectories(_path, false);
} }
bool etk::fs::removeDirectories(const etk::Path& _path) { bool etk::path::removeDirectories(const etk::Path& _path) {
return detail::removeDirectories(_path, true); return detail::removeDirectories(_path, true);
} }
bool etk::fs::removeFile(const etk::Path& _path) { bool etk::path::removeFile(const etk::Path& _path) {
TK_VERBOSE("remove File: " << _path); TK_VERBOSE("remove File: " << _path);
if (0 != unlink(_path.getNative().c_str()) ) { if (0 != unlink(_path.getNative().c_str()) ) {
return false; return false;
@ -116,9 +116,9 @@ bool etk::fs::removeFile(const etk::Path& _path) {
return true; return true;
} }
bool etk::fs::makeDirectory(const etk::Path& _path, etk::fs::Permissions _permission) { bool etk::path::makeDirectory(const etk::Path& _path, etk::path::Permissions _permission) {
TK_VERBOSE("Make directory : " << _path << " perm: " << _permission); TK_VERBOSE("Make directory : " << _path << " perm: " << _permission);
if (etk::fs::exist(_path) == true) { if (etk::path::exist(_path) == true) {
return true; return true;
} }
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
@ -136,9 +136,9 @@ bool etk::fs::makeDirectory(const etk::Path& _path, etk::fs::Permissions _permis
return true; return true;
} }
bool etk::fs::makeDirectories(const etk::Path& _path, etk::fs::Permissions _permission) { bool etk::path::makeDirectories(const etk::Path& _path, etk::path::Permissions _permission) {
TK_VERBOSE("Make dirrectories: " << _path << " perm: " << _permission); TK_VERBOSE("Make dirrectories: " << _path << " perm: " << _permission);
if (etk::fs::exist(_path) == true) { if (etk::path::exist(_path) == true) {
return true; return true;
} }
auto elements = _path.getNative().split('/'); auto elements = _path.getNative().split('/');
@ -149,16 +149,16 @@ bool etk::fs::makeDirectories(const etk::Path& _path, etk::fs::Permissions _perm
} }
for (auto& it: elements) { for (auto& it: elements) {
pathToCreate /= it; pathToCreate /= it;
if (etk::fs::makeDirectory(pathToCreate, _permission) == false) { if (etk::path::makeDirectory(pathToCreate, _permission) == false) {
return false; return false;
} }
} }
return true; return true;
} }
bool etk::fs::touch(const etk::Path& _path) { bool etk::path::touch(const etk::Path& _path) {
TK_VERBOSE("Touch FILE : " << _path); TK_VERBOSE("Touch FILE : " << _path);
if (etk::fs::exist(_path) == true ) { if (etk::path::exist(_path) == true ) {
int rc = utimensat(0, int rc = utimensat(0,
_path.getAbsoluteNative().c_str(), _path.getAbsoluteNative().c_str(),
NULL, NULL,
@ -176,14 +176,14 @@ bool etk::fs::touch(const etk::Path& _path) {
return file.close(); return file.close();
} }
bool etk::fs::exist(const etk::Path& _path) { bool etk::path::exist(const etk::Path& _path) {
if (::access( _path.getNative().c_str(), F_OK ) != -1 ) { if (::access( _path.getNative().c_str(), F_OK ) != -1 ) {
return true; return true;
} }
return false; return false;
} }
uint64_t etk::fs::fileSize(const etk::Path& _path) { uint64_t etk::path::fileSize(const etk::Path& _path) {
// Note : this is a proper methode to get the file size for Big files ... otherwithe the size is limited at 2^31 bytes // Note : this is a proper methode to get the file size for Big files ... otherwithe the size is limited at 2^31 bytes
// tmpStat Buffer : // tmpStat Buffer :
struct stat statProperty; struct stat statProperty;
@ -199,7 +199,7 @@ uint64_t etk::fs::fileSize(const etk::Path& _path) {
} }
bool etk::fs::isDirectory(const etk::Path& _path) { bool etk::path::isDirectory(const etk::Path& _path) {
struct stat st; struct stat st;
int32_t status = 0; int32_t status = 0;
if (stat(_path.getNative().c_str(), &st) != 0) { if (stat(_path.getNative().c_str(), &st) != 0) {
@ -210,7 +210,7 @@ bool etk::fs::isDirectory(const etk::Path& _path) {
return true; return true;
} }
bool etk::fs::isFile(const etk::Path& _path) { bool etk::path::isFile(const etk::Path& _path) {
struct stat st; struct stat st;
int32_t status = 0; int32_t status = 0;
if (stat(_path.getNative().c_str(), &st) != 0) { if (stat(_path.getNative().c_str(), &st) != 0) {
@ -221,7 +221,7 @@ bool etk::fs::isFile(const etk::Path& _path) {
return true; return true;
} }
bool etk::fs::isSymLink(const etk::Path& _path) { bool etk::path::isSymLink(const etk::Path& _path) {
struct stat st; struct stat st;
int32_t status = 0; int32_t status = 0;
if (stat(_path.getNative().c_str(), &st) != 0) { if (stat(_path.getNative().c_str(), &st) != 0) {
@ -233,8 +233,8 @@ bool etk::fs::isSymLink(const etk::Path& _path) {
} }
etk::fs::Permissions etk::fs::getPermission(const etk::Path& _path) { etk::path::Permissions etk::path::getPermission(const etk::Path& _path) {
etk::fs::Permissions permissions; etk::path::Permissions permissions;
// tmpStat Buffer : // tmpStat Buffer :
struct stat statProperty; struct stat statProperty;
if (-1 == stat(_path.getNative().c_str(), &statProperty)) { if (-1 == stat(_path.getNative().c_str(), &statProperty)) {
@ -246,25 +246,25 @@ etk::fs::Permissions etk::fs::getPermission(const etk::Path& _path) {
} }
etk::String etk::fs::getRelativeString(const etk::Path& _path) { etk::String etk::path::getRelativeString(const etk::Path& _path) {
return _path.getRelative(); return _path.getRelative();
} }
etk::String etk::fs::getAbsoluteString(const etk::Path& _path) { etk::String etk::path::getAbsoluteString(const etk::Path& _path) {
return _path.getAbsolute(); return _path.getAbsolute();
} }
etk::String etk::fs::getNativeString(const etk::Path& _path) { etk::String etk::path::getNativeString(const etk::Path& _path) {
return _path.getNative(); return _path.getNative();
} }
/* /*
etk::String etk::fs::getMimeType(const etk::Path& _path) { etk::String etk::path::getMimeType(const etk::Path& _path) {
return "*"; return "*";
} }
*/ */
etk::Path etk::fs::getTemporaryPath() { etk::Path etk::path::getTemporaryPath() {
static char const *folder = null; static char const *folder = null;
if (folder == null) { if (folder == null) {
#ifdef __TARGET_OS__Windows #ifdef __TARGET_OS__Windows
@ -298,18 +298,18 @@ namespace detail {
etk::Path getTemporaryProcessPath(const etk::String& _patern) { etk::Path getTemporaryProcessPath(const etk::String& _patern) {
etk::Path val; etk::Path val;
do { do {
val = etk::fs::getTemporaryPath() / _patern + etk::random::generateString(16); val = etk::path::getTemporaryPath() / _patern + etk::random::generateString(16);
} while (etk::fs::exist(val) == true); } while (etk::path::exist(val) == true);
return val; return val;
} }
} }
etk::Path etk::fs::getTemporaryProcessPath() { etk::Path etk::path::getTemporaryProcessPath() {
static etk::Path out = detail::getTemporaryProcessPath("etk.process."); static etk::Path out = detail::getTemporaryProcessPath("etk.process.");
return out; return out;
} }
etk::Path etk::fs::getTemporaryRandomPath() { etk::Path etk::path::getTemporaryRandomPath() {
return detail::getTemporaryProcessPath("etk.random."); return detail::getTemporaryProcessPath("etk.random.");
} }
@ -335,11 +335,11 @@ static etk::String getHomePathString() {
return data; return data;
} }
etk::Path etk::fs::getHomePath() { etk::Path etk::path::getHomePath() {
return etk::Path(getHomePathString()); return etk::Path(getHomePathString());
} }
etk::Path etk::fs::getExecutionPath() { etk::Path etk::path::getExecutionPath() {
static etk::Path g_path; static etk::Path g_path;
if (g_path.getNative() != "") { if (g_path.getNative() != "") {
return g_path; return g_path;
@ -358,7 +358,7 @@ etk::Path etk::fs::getExecutionPath() {
return g_path; return g_path;
} }
etk::Path etk::fs::realPath(const etk::Path& _path) { etk::Path etk::path::realPath(const etk::Path& _path) {
#if ! defined(__TARGET_OS__Windows) #if ! defined(__TARGET_OS__Windows)
char buf[8192]; char buf[8192];
memset(buf, 0, 8192); memset(buf, 0, 8192);
@ -370,7 +370,7 @@ etk::Path etk::fs::realPath(const etk::Path& _path) {
return _path; return _path;
} }
etk::Path etk::fs::getBinaryPath() { etk::Path etk::path::getBinaryPath() {
static etk::Path out; static etk::Path out;
if ( out.getNative() == "" ) { if ( out.getNative() == "" ) {
#if defined(__TARGET_OS__Windows) || defined(__TARGET_OS__MacOs) || defined(__TARGET_OS__IOs) #if defined(__TARGET_OS__Windows) || defined(__TARGET_OS__MacOs) || defined(__TARGET_OS__IOs)
@ -395,23 +395,23 @@ etk::Path etk::fs::getBinaryPath() {
} while (tmpValue.size() < 65536); } while (tmpValue.size() < 65536);
out = tmpValue; out = tmpValue;
#else #else
if (etk::fs::exist("/proc/self/exe") == true) { if (etk::path::exist("/proc/self/exe") == true) {
out = etk::fs::realPath("/proc/self/exe"); out = etk::path::realPath("/proc/self/exe");
} else if (etk::fs::exist("/proc/curproc/file") == true) { } else if (etk::path::exist("/proc/curproc/file") == true) {
out = etk::fs::realPath("/proc/curproc/file"); out = etk::path::realPath("/proc/curproc/file");
} else if (etk::fs::exist("/proc/curproc/exe") == true) { } else if (etk::path::exist("/proc/curproc/exe") == true) {
out = etk::fs::realPath("/proc/curproc/exe"); out = etk::path::realPath("/proc/curproc/exe");
} }
#endif #endif
} }
return out; return out;
} }
etk::String etk::fs::getBinaryName() { etk::String etk::path::getBinaryName() {
return getBinaryPath().getFileName(); return getBinaryPath().getFileName();
} }
etk::Path etk::fs::getDataPath() { etk::Path etk::path::getDataPath() {
#if defined(__TARGET_OS__Web) #if defined(__TARGET_OS__Web)
return "zz_generic_zz"; return "zz_generic_zz";
#elif defined(__TARGET_OS__Android) #elif defined(__TARGET_OS__Android)
@ -434,7 +434,7 @@ etk::Path etk::fs::getDataPath() {
return "NO_DATA_PATH"; return "NO_DATA_PATH";
} }
uint64_t etk::fs::getCreateTime(const etk::Path& _path) { uint64_t etk::path::getCreateTime(const etk::Path& _path) {
struct stat statProperty; struct stat statProperty;
if (-1 == stat(_path.getNative().c_str(), &statProperty)) { if (-1 == stat(_path.getNative().c_str(), &statProperty)) {
return 0; return 0;
@ -442,7 +442,7 @@ uint64_t etk::fs::getCreateTime(const etk::Path& _path) {
return statProperty.st_ctime; return statProperty.st_ctime;
} }
uint64_t etk::fs::getModifyTime(const etk::Path& _path) { uint64_t etk::path::getModifyTime(const etk::Path& _path) {
struct stat statProperty; struct stat statProperty;
if (-1 == stat(_path.getNative().c_str(), &statProperty)) { if (-1 == stat(_path.getNative().c_str(), &statProperty)) {
return 0; return 0;
@ -450,7 +450,7 @@ uint64_t etk::fs::getModifyTime(const etk::Path& _path) {
return statProperty.st_mtime; return statProperty.st_mtime;
} }
uint64_t etk::fs::getAccessTime(const etk::Path& _path) { uint64_t etk::path::getAccessTime(const etk::Path& _path) {
struct stat statProperty; struct stat statProperty;
if (-1 == stat(_path.getNative().c_str(), &statProperty)) { if (-1 == stat(_path.getNative().c_str(), &statProperty)) {
return 0; return 0;
@ -458,7 +458,7 @@ uint64_t etk::fs::getAccessTime(const etk::Path& _path) {
return statProperty.st_atime; return statProperty.st_atime;
} }
uint32_t etk::fs::getIdOwner(const etk::Path& _path) { uint32_t etk::path::getIdOwner(const etk::Path& _path) {
struct stat statProperty; struct stat statProperty;
if (-1 == stat(_path.getNative().c_str(), &statProperty)) { if (-1 == stat(_path.getNative().c_str(), &statProperty)) {
return 0; return 0;
@ -466,7 +466,7 @@ uint32_t etk::fs::getIdOwner(const etk::Path& _path) {
return statProperty.st_uid; return statProperty.st_uid;
} }
uint32_t etk::fs::getIdGroup(const etk::Path& _path) { uint32_t etk::path::getIdGroup(const etk::Path& _path) {
struct stat statProperty; struct stat statProperty;
if (-1 == stat(_path.getNative().c_str(), &statProperty)) { if (-1 == stat(_path.getNative().c_str(), &statProperty)) {
return 0; return 0;
@ -474,9 +474,9 @@ uint32_t etk::fs::getIdGroup(const etk::Path& _path) {
return statProperty.st_gid; return statProperty.st_gid;
} }
etk::Vector<etk::Path> etk::fs::list(const etk::Path& _path) { etk::Vector<etk::Path> etk::path::list(const etk::Path& _path) {
etk::Vector<etk::Path> out; etk::Vector<etk::Path> out;
if (etk::fs::isDirectory(_path) == false) { if (etk::path::isDirectory(_path) == false) {
return out; return out;
} }
DIR *dir = null; DIR *dir = null;

View File

@ -7,11 +7,11 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/fs/Path.hpp> #include <etk/path/Path.hpp>
#include <etk/fs/Permissions.hpp> #include <etk/path/Permissions.hpp>
namespace etk { namespace etk {
namespace fs { namespace path {
/** /**
* @brief Copy a path to an other (if possible...) * @brief Copy a path to an other (if possible...)
* @param[in] _path1 Path source. * @param[in] _path1 Path source.
@ -103,7 +103,7 @@ namespace etk {
* @return true Operation succeed. * @return true Operation succeed.
* @return false Operation Failed. * @return false Operation Failed.
*/ */
bool makeDirectory(const etk::Path& _path, etk::fs::Permissions _permission = etk::fs::Permissions::genericFolder); bool makeDirectory(const etk::Path& _path, etk::path::Permissions _permission = etk::path::Permissions::genericFolder);
/** /**
* @brief Make a directory (With all parents if needed) * @brief Make a directory (With all parents if needed)
* @param[in] _path Path to create. * @param[in] _path Path to create.
@ -111,7 +111,7 @@ namespace etk {
* @return true Operation succeed. * @return true Operation succeed.
* @return false Operation Failed. * @return false Operation Failed.
*/ */
bool makeDirectories(const etk::Path& _path, etk::fs::Permissions _permission = etk::fs::Permissions::genericFolder); bool makeDirectories(const etk::Path& _path, etk::path::Permissions _permission = etk::path::Permissions::genericFolder);
/** /**
* @brief update the Time of the file with the current time * @brief update the Time of the file with the current time
* @param[in] _path Path to touch. * @param[in] _path Path to touch.
@ -258,7 +258,7 @@ namespace etk {
* @param[in] _path Path of the requested information. * @param[in] _path Path of the requested information.
* @return Generic permission class. * @return Generic permission class.
*/ */
etk::fs::Permissions getPermission(const etk::Path& _path); etk::path::Permissions getPermission(const etk::Path& _path);
/** /**
* @brief List the content of a specific path. * @brief List the content of a specific path.
* @param[in] Path to parse. * @param[in] Path to parse.

View File

@ -6,7 +6,7 @@
#pragma once #pragma once
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/fs/Type.hpp>
#include <etk/String.hpp> #include <etk/String.hpp>
#include <etk/Map.hpp> #include <etk/Map.hpp>

View File

@ -6,11 +6,11 @@
#pragma once #pragma once
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/fs/Type.hpp>
#include <etk/String.hpp> #include <etk/String.hpp>
#include <etk/Map.hpp> #include <etk/Map.hpp>
#include <etk/uri/Query.hpp> #include <etk/uri/Query.hpp>
#include <etk/fs/Path.hpp> #include <etk/path/Path.hpp>
namespace etk { namespace etk {
/** /**

View File

@ -5,7 +5,7 @@
*/ */
#include <etk/uri/provider/ProviderFile.hpp> #include <etk/uri/provider/ProviderFile.hpp>
#include <etk/io/File.hpp> #include <etk/io/File.hpp>
#include <etk/fs/fileSystem.hpp> #include <etk/path/fileSystem.hpp>
#include <etk/debug.hpp> #include <etk/debug.hpp>
etk::uri::provider::ProviderFile::ProviderFile() { etk::uri::provider::ProviderFile::ProviderFile() {
@ -26,16 +26,16 @@ ememory::SharedPtr<etk::io::Interface> etk::uri::provider::ProviderFile::create(
bool etk::uri::provider::ProviderFile::exist(const etk::Uri& _uri) { bool etk::uri::provider::ProviderFile::exist(const etk::Uri& _uri) {
if (m_offset.isEmpty() == true) { if (m_offset.isEmpty() == true) {
return etk::fs::exist(_uri.getPath()); return etk::path::exist(_uri.getPath());
} }
return etk::fs::exist(m_offset / _uri.getPath()); return etk::path::exist(m_offset / _uri.getPath());
} }
etk::Vector<etk::Uri> etk::uri::provider::ProviderFile::list(const etk::Uri& _uri) { etk::Vector<etk::Uri> etk::uri::provider::ProviderFile::list(const etk::Uri& _uri) {
etk::Vector<etk::Path> tmp; etk::Vector<etk::Path> tmp;
etk::Vector<etk::Uri> out; etk::Vector<etk::Uri> out;
if (m_offset.isEmpty() == true) { if (m_offset.isEmpty() == true) {
tmp = etk::fs::list(_uri.getPath()); tmp = etk::path::list(_uri.getPath());
for (auto& elem: tmp) { for (auto& elem: tmp) {
etk::Uri newUri = _uri; etk::Uri newUri = _uri;
newUri.setPath(elem); newUri.setPath(elem);
@ -44,7 +44,7 @@ etk::Vector<etk::Uri> etk::uri::provider::ProviderFile::list(const etk::Uri& _ur
return out; return out;
} }
TK_VERBOSE("list path: " << m_offset / _uri.getPath()); TK_VERBOSE("list path: " << m_offset / _uri.getPath());
tmp = etk::fs::list(m_offset / _uri.getPath()); tmp = etk::path::list(m_offset / _uri.getPath());
int32_t offset = m_offset.getString().size()+1; int32_t offset = m_offset.getString().size()+1;
for (auto& elem: tmp) { for (auto& elem: tmp) {
etk::Uri newUri = _uri; etk::Uri newUri = _uri;

View File

@ -6,11 +6,11 @@
#pragma once #pragma once
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/fs/Type.hpp>
#include <etk/String.hpp> #include <etk/String.hpp>
#include <etk/Map.hpp> #include <etk/Map.hpp>
#include <etk/uri/Query.hpp> #include <etk/uri/Query.hpp>
#include <etk/fs/Path.hpp> #include <etk/path/Path.hpp>
#include <etk/io/Interface.hpp> #include <etk/io/Interface.hpp>
#include <etk/uri/provider/Interface.hpp> #include <etk/uri/provider/Interface.hpp>
#include <ememory/SharedPtr.hpp> #include <ememory/SharedPtr.hpp>

View File

@ -34,10 +34,9 @@ def configure(target, my_module):
'etk/Noise.cpp', 'etk/Noise.cpp',
'etk/Color.cpp', 'etk/Color.cpp',
'etk/RegEx.cpp', 'etk/RegEx.cpp',
'etk/fs/fileSystem.cpp', 'etk/path/fileSystem.cpp',
'etk/fs/Path.cpp', 'etk/path/Path.cpp',
'etk/fs/Permissions.cpp', 'etk/path/Permissions.cpp',
'etk/fs/Type.cpp',
'etk/io/OpenMode.cpp', 'etk/io/OpenMode.cpp',
'etk/io/SeekMode.cpp', 'etk/io/SeekMode.cpp',
'etk/io/Interface.cpp', 'etk/io/Interface.cpp',
@ -69,10 +68,9 @@ def configure(target, my_module):
'etk/Noise.hpp', 'etk/Noise.hpp',
'etk/Color.hpp', 'etk/Color.hpp',
'etk/RegEx.hpp', 'etk/RegEx.hpp',
'etk/fs/fileSystem.hpp', 'etk/path/fileSystem.hpp',
'etk/fs/Path.hpp', 'etk/path/Path.hpp',
'etk/fs/Permissions.hpp', 'etk/path/Permissions.hpp',
'etk/fs/Type.hpp',
'etk/io/OpenMode.hpp', 'etk/io/OpenMode.hpp',
'etk/io/SeekMode.hpp', 'etk/io/SeekMode.hpp',
'etk/io/Interface.hpp', 'etk/io/Interface.hpp',

View File

@ -8,140 +8,140 @@
#include <etest/etest.hpp> #include <etest/etest.hpp>
#include <test-debug/debug.hpp> #include <test-debug/debug.hpp>
#include <etk/fs/fileSystem.hpp> #include <etk/path/fileSystem.hpp>
TEST(TestFileSystem, checkHomePath) { TEST(TestFileSystem, checkHomePath) {
etk::String basicPath = getenv("HOME"); etk::String basicPath = getenv("HOME");
EXPECT_EQ(etk::fs::getHomePath(), basicPath); EXPECT_EQ(etk::path::getHomePath(), basicPath);
} }
TEST(TestFileSystem, checkTmpPath) { TEST(TestFileSystem, checkTmpPath) {
EXPECT_EQ(etk::fs::getTemporaryPath(), "/tmp"); EXPECT_EQ(etk::path::getTemporaryPath(), "/tmp");
} }
TEST(TestFileSystem, getBinaryName) { TEST(TestFileSystem, getBinaryName) {
EXPECT_EQ(etk::fs::getBinaryName(), "etk-test"); EXPECT_EQ(etk::path::getBinaryName(), "etk-test");
} }
TEST(TestFileSystem, getBinaryPath) { TEST(TestFileSystem, getBinaryPath) {
EXPECT_EQ(etk::fs::getBinaryPath().getString().split('/').size() > 2, true); EXPECT_EQ(etk::path::getBinaryPath().getString().split('/').size() > 2, true);
} }
TEST(TestFileSystem, randomProcessPath) { TEST(TestFileSystem, randomProcessPath) {
etk::Path path1 = etk::fs::getTemporaryProcessPath(); etk::Path path1 = etk::path::getTemporaryProcessPath();
etk::Path path2 = etk::fs::getTemporaryProcessPath(); etk::Path path2 = etk::path::getTemporaryProcessPath();
EXPECT_EQ(path1,path2); EXPECT_EQ(path1,path2);
} }
TEST(TestFileSystem, randomPath) { TEST(TestFileSystem, randomPath) {
etk::Path path1 = etk::fs::getTemporaryRandomPath(); etk::Path path1 = etk::path::getTemporaryRandomPath();
etk::Path path2 = etk::fs::getTemporaryRandomPath(); etk::Path path2 = etk::path::getTemporaryRandomPath();
EXPECT_NE(path1,path2); EXPECT_NE(path1,path2);
} }
TEST(TestFileSystem, create_and_remove_directory_relative) { TEST(TestFileSystem, create_and_remove_directory_relative) {
etk::Path path = "hello"; etk::Path path = "hello";
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
EXPECT_EQ(etk::fs::makeDirectory(path), true); EXPECT_EQ(etk::path::makeDirectory(path), true);
EXPECT_EQ(etk::fs::exist(path), true); EXPECT_EQ(etk::path::exist(path), true);
EXPECT_EQ(etk::fs::makeDirectory(path), true); EXPECT_EQ(etk::path::makeDirectory(path), true);
EXPECT_EQ(etk::fs::removeDirectory(path), true); EXPECT_EQ(etk::path::removeDirectory(path), true);
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
} }
TEST(TestFileSystem, createDirectory_relative_error) { TEST(TestFileSystem, createDirectory_relative_error) {
etk::Path path = "hello/sdfsdf"; etk::Path path = "hello/sdfsdf";
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
EXPECT_EQ(etk::fs::makeDirectory(path), false); EXPECT_EQ(etk::path::makeDirectory(path), false);
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
} }
TEST(TestFileSystem, create_and_remove_directories) { TEST(TestFileSystem, create_and_remove_directories) {
etk::Path pathRandom = etk::fs::getTemporaryRandomPath(); etk::Path pathRandom = etk::path::getTemporaryRandomPath();
etk::Path path = pathRandom / "eee" / "kjlk" / "kjhkjh"; etk::Path path = pathRandom / "eee" / "kjlk" / "kjhkjh";
TEST_DEBUG("path tmp: " << path); TEST_DEBUG("path tmp: " << path);
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
EXPECT_EQ(etk::fs::makeDirectories(path), true); EXPECT_EQ(etk::path::makeDirectories(path), true);
EXPECT_EQ(etk::fs::exist(path), true); EXPECT_EQ(etk::path::exist(path), true);
EXPECT_EQ(etk::fs::removeDirectories(pathRandom), true); EXPECT_EQ(etk::path::removeDirectories(pathRandom), true);
EXPECT_EQ(etk::fs::exist(pathRandom), false); EXPECT_EQ(etk::path::exist(pathRandom), false);
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
} }
TEST(TestFileSystem, create_and_remove_directories_error) { TEST(TestFileSystem, create_and_remove_directories_error) {
etk::Path pathRandom = etk::fs::getTemporaryRandomPath(); etk::Path pathRandom = etk::path::getTemporaryRandomPath();
etk::Path path = etk::Path("home") / "eee" / "kjlk" / "kjhkjh"; etk::Path path = etk::Path("home") / "eee" / "kjlk" / "kjhkjh";
TEST_DEBUG("path tmp: " << path); TEST_DEBUG("path tmp: " << path);
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
EXPECT_EQ(etk::fs::makeDirectories(path), false); EXPECT_EQ(etk::path::makeDirectories(path), false);
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
} }
/* /*
TEST(TestFileSystem, move_directory) { TEST(TestFileSystem, move_directory) {
etk::Path pathRandom = etk::fs::getTemporaryRandomPath(); etk::Path pathRandom = etk::path::getTemporaryRandomPath();
etk::Path path1 = pathRandom / "eee1"; etk::Path path1 = pathRandom / "eee1";
etk::Path path2 = pathRandom / "eee2"; etk::Path path2 = pathRandom / "eee2";
etk::Path offset = etk::Path("kjlk") / "kjhkjh"; etk::Path offset = etk::Path("kjlk") / "kjhkjh";
EXPECT_EQ(etk::fs::exist(path1), false); EXPECT_EQ(etk::path::exist(path1), false);
EXPECT_EQ(etk::fs::exist(path2), false); EXPECT_EQ(etk::path::exist(path2), false);
EXPECT_EQ(etk::fs::exist(path1 / offset), false); EXPECT_EQ(etk::path::exist(path1 / offset), false);
EXPECT_EQ(etk::fs::exist(path2 / offset), false); EXPECT_EQ(etk::path::exist(path2 / offset), false);
EXPECT_EQ(etk::fs::makeDirectories(path1 / offset), true); EXPECT_EQ(etk::path::makeDirectories(path1 / offset), true);
EXPECT_EQ(etk::fs::exist(path1), true); EXPECT_EQ(etk::path::exist(path1), true);
EXPECT_EQ(etk::fs::exist(path2), false); EXPECT_EQ(etk::path::exist(path2), false);
EXPECT_EQ(etk::fs::exist(path1 / offset), true); EXPECT_EQ(etk::path::exist(path1 / offset), true);
EXPECT_EQ(etk::fs::exist(path2 / offset), false); EXPECT_EQ(etk::path::exist(path2 / offset), false);
EXPECT_EQ(etk::fs::move(path1, path2), true); EXPECT_EQ(etk::path::move(path1, path2), true);
EXPECT_EQ(etk::fs::exist(path1), false); EXPECT_EQ(etk::path::exist(path1), false);
EXPECT_EQ(etk::fs::exist(path2), true); EXPECT_EQ(etk::path::exist(path2), true);
EXPECT_EQ(etk::fs::exist(path1 / offset), false); EXPECT_EQ(etk::path::exist(path1 / offset), false);
EXPECT_EQ(etk::fs::exist(path2 / offset), true); EXPECT_EQ(etk::path::exist(path2 / offset), true);
EXPECT_EQ(etk::fs::removeDirectories(pathRandom), true); EXPECT_EQ(etk::path::removeDirectories(pathRandom), true);
EXPECT_EQ(etk::fs::exist(pathRandom), false); EXPECT_EQ(etk::path::exist(pathRandom), false);
} }
*/ */
#include <unistd.h> #include <unistd.h>
TEST(TestFileSystem, touch) { TEST(TestFileSystem, touch) {
etk::Path pathRandom = etk::fs::getTemporaryRandomPath(); etk::Path pathRandom = etk::path::getTemporaryRandomPath();
etk::Path path = pathRandom / "eee" / "kjlk" / "kjhkjh.txt"; etk::Path path = pathRandom / "eee" / "kjlk" / "kjhkjh.txt";
TEST_DEBUG("path tmp: " << path); TEST_DEBUG("path tmp: " << path);
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
// Touch a file in a unexisting path // Touch a file in a unexisting path
EXPECT_EQ(etk::fs::touch(path), false); EXPECT_EQ(etk::path::touch(path), false);
EXPECT_EQ(etk::fs::makeDirectories(path.getParent()), true); EXPECT_EQ(etk::path::makeDirectories(path.getParent()), true);
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
// Touch a file in an existing path // Touch a file in an existing path
EXPECT_EQ(etk::fs::touch(path), true); EXPECT_EQ(etk::path::touch(path), true);
EXPECT_EQ(etk::fs::exist(path), true); EXPECT_EQ(etk::path::exist(path), true);
uint64_t touch1 = etk::fs::getModifyTime(path); uint64_t touch1 = etk::path::getModifyTime(path);
usleep(1000000); usleep(1000000);
// Tich a file already existing // Tich a file already existing
EXPECT_EQ(etk::fs::touch(path), true); EXPECT_EQ(etk::path::touch(path), true);
EXPECT_EQ(etk::fs::exist(path), true); EXPECT_EQ(etk::path::exist(path), true);
uint64_t touch2 = etk::fs::getModifyTime(path); uint64_t touch2 = etk::path::getModifyTime(path);
EXPECT_NE(touch1, touch2); EXPECT_NE(touch1, touch2);
EXPECT_EQ(etk::fs::removeDirectories(pathRandom), true); EXPECT_EQ(etk::path::removeDirectories(pathRandom), true);
EXPECT_EQ(etk::fs::exist(pathRandom), false); EXPECT_EQ(etk::path::exist(pathRandom), false);
EXPECT_EQ(etk::fs::exist(path), false); EXPECT_EQ(etk::path::exist(path), false);
} }
TEST(TestFileSystem, move_file) { TEST(TestFileSystem, move_file) {
etk::Path pathRandom = etk::fs::getTemporaryRandomPath(); etk::Path pathRandom = etk::path::getTemporaryRandomPath();
etk::Path path1 = pathRandom / "eee1.txt"; etk::Path path1 = pathRandom / "eee1.txt";
etk::Path path2 = pathRandom / "eee2.mov"; etk::Path path2 = pathRandom / "eee2.mov";
EXPECT_EQ(etk::fs::exist(path1), false); EXPECT_EQ(etk::path::exist(path1), false);
EXPECT_EQ(etk::fs::exist(path2), false); EXPECT_EQ(etk::path::exist(path2), false);
EXPECT_EQ(etk::fs::makeDirectories(pathRandom), true); EXPECT_EQ(etk::path::makeDirectories(pathRandom), true);
EXPECT_EQ(etk::fs::touch(path1), true); EXPECT_EQ(etk::path::touch(path1), true);
EXPECT_EQ(etk::fs::exist(path1), true); EXPECT_EQ(etk::path::exist(path1), true);
EXPECT_EQ(etk::fs::exist(path2), false); EXPECT_EQ(etk::path::exist(path2), false);
EXPECT_EQ(etk::fs::move(path1, path2), true); EXPECT_EQ(etk::path::move(path1, path2), true);
EXPECT_EQ(etk::fs::exist(path1), false); EXPECT_EQ(etk::path::exist(path1), false);
EXPECT_EQ(etk::fs::exist(path2), true); EXPECT_EQ(etk::path::exist(path2), true);
/* /*
EXPECT_EQ(etk::fs::removeDirectories(pathRandom), true); EXPECT_EQ(etk::path::removeDirectories(pathRandom), true);
EXPECT_EQ(etk::fs::exist(pathRandom), false); EXPECT_EQ(etk::path::exist(pathRandom), false);
*/ */
} }

View File

@ -8,8 +8,8 @@
#include <etest/etest.hpp> #include <etest/etest.hpp>
#include <test-debug/debug.hpp> #include <test-debug/debug.hpp>
#include <etk/fs/Path.hpp> #include <etk/path/Path.hpp>
#include <etk/fs/fileSystem.hpp> #include <etk/path/fileSystem.hpp>
TEST(TestPath, defaultContructor) { TEST(TestPath, defaultContructor) {
etk::Path path; etk::Path path;
@ -142,7 +142,7 @@ TEST(TestPath, getRelative) {
EXPECT_EQ(path.getRelative(), "plouf.pdf"); EXPECT_EQ(path.getRelative(), "plouf.pdf");
path = "/ici/plouf.pdf"; path = "/ici/plouf.pdf";
etk::String test; etk::String test;
auto elements = etk::fs::getExecutionPath().getString().split('/'); auto elements = etk::path::getExecutionPath().getString().split('/');
for (size_t iii=0; iii<elements.size(); ++iii) { for (size_t iii=0; iii<elements.size(); ++iii) {
if (elements[iii].size() == 0) { if (elements[iii].size() == 0) {
continue; continue;
@ -155,7 +155,7 @@ TEST(TestPath, getRelative) {
TEST(TestPath, getAbsolute) { TEST(TestPath, getAbsolute) {
etk::Path path("plouf.pdf"); etk::Path path("plouf.pdf");
EXPECT_EQ(path.getAbsolute(), (etk::fs::getExecutionPath() / "plouf.pdf").getString()); EXPECT_EQ(path.getAbsolute(), (etk::path::getExecutionPath() / "plouf.pdf").getString());
path = "/plouf.pdf"; path = "/plouf.pdf";
EXPECT_EQ(path.getAbsolute(), "/plouf.pdf"); EXPECT_EQ(path.getAbsolute(), "/plouf.pdf");
} }

View File

@ -8,10 +8,10 @@
#include <etest/etest.hpp> #include <etest/etest.hpp>
#include <test-debug/debug.hpp> #include <test-debug/debug.hpp>
#include <etk/fs/Permissions.hpp> #include <etk/path/Permissions.hpp>
TEST(TestPermission, defaultContructor) { TEST(TestPermission, defaultContructor) {
etk::fs::Permissions permission; etk::path::Permissions permission;
EXPECT_EQ(permission.isUserReadable(), false); EXPECT_EQ(permission.isUserReadable(), false);
EXPECT_EQ(permission.isUserWritable(), false); EXPECT_EQ(permission.isUserWritable(), false);
EXPECT_EQ(permission.isUserRunable(), false); EXPECT_EQ(permission.isUserRunable(), false);
@ -26,7 +26,7 @@ TEST(TestPermission, defaultContructor) {
TEST(TestPermission, fullright) { TEST(TestPermission, fullright) {
etk::fs::Permissions permission(0777); etk::path::Permissions permission(0777);
EXPECT_EQ(permission.isUserReadable(), true); EXPECT_EQ(permission.isUserReadable(), true);
EXPECT_EQ(permission.isUserWritable(), true); EXPECT_EQ(permission.isUserWritable(), true);
EXPECT_EQ(permission.isUserRunable(), true); EXPECT_EQ(permission.isUserRunable(), true);
@ -41,7 +41,7 @@ TEST(TestPermission, fullright) {
TEST(TestPermission, user) { TEST(TestPermission, user) {
etk::fs::Permissions permission(0700); etk::path::Permissions permission(0700);
EXPECT_EQ(permission.isUserReadable(), true); EXPECT_EQ(permission.isUserReadable(), true);
EXPECT_EQ(permission.isUserWritable(), true); EXPECT_EQ(permission.isUserWritable(), true);
EXPECT_EQ(permission.isUserRunable(), true); EXPECT_EQ(permission.isUserRunable(), true);
@ -56,7 +56,7 @@ TEST(TestPermission, user) {
TEST(TestPermission, group) { TEST(TestPermission, group) {
etk::fs::Permissions permission(0070); etk::path::Permissions permission(0070);
EXPECT_EQ(permission.isUserReadable(), false); EXPECT_EQ(permission.isUserReadable(), false);
EXPECT_EQ(permission.isUserWritable(), false); EXPECT_EQ(permission.isUserWritable(), false);
EXPECT_EQ(permission.isUserRunable(), false); EXPECT_EQ(permission.isUserRunable(), false);
@ -71,7 +71,7 @@ TEST(TestPermission, group) {
TEST(TestPermission, other) { TEST(TestPermission, other) {
etk::fs::Permissions permission(0007); etk::path::Permissions permission(0007);
EXPECT_EQ(permission.isUserReadable(), false); EXPECT_EQ(permission.isUserReadable(), false);
EXPECT_EQ(permission.isUserWritable(), false); EXPECT_EQ(permission.isUserWritable(), false);
EXPECT_EQ(permission.isUserRunable(), false); EXPECT_EQ(permission.isUserRunable(), false);

View File

@ -12,7 +12,7 @@
#include <etk/uri/provider/provider.hpp> #include <etk/uri/provider/provider.hpp>
#include <etk/uri/provider/ProviderFile.hpp> #include <etk/uri/provider/ProviderFile.hpp>
#include <etk/uri/provider/ProviderFileZip.hpp> #include <etk/uri/provider/ProviderFileZip.hpp>
#include <etk/fs/fileSystem.hpp> #include <etk/path/fileSystem.hpp>
#include <etk/algorithm.hpp> #include <etk/algorithm.hpp>
@ -100,8 +100,8 @@ bool uriSortCallback(const etk::Uri& _left, const etk::Uri& _right) {
TEST(TestUriProvider, checkDirectAccess) { TEST(TestUriProvider, checkDirectAccess) {
etk::uri::provider::clear(); etk::uri::provider::clear();
TEST_VERBOSE("data path: " << etk::fs::getDataPath()); TEST_VERBOSE("data path: " << etk::path::getDataPath());
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::fs::getDataPath())); etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::path::getDataPath()));
EXPECT_EQ(etk::uri::provider::exist("DATA"), true); EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA"); ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
EXPECT_NE(provider, null); EXPECT_NE(provider, null);
@ -133,8 +133,8 @@ etk::Vector<etk::Uri> listDirect2 = {
TEST(TestUriProvider, checkDirectAccess2) { TEST(TestUriProvider, checkDirectAccess2) {
etk::uri::provider::clear(); etk::uri::provider::clear();
TEST_VERBOSE("data path: " << etk::fs::getDataPath()); TEST_VERBOSE("data path: " << etk::path::getDataPath());
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::fs::getDataPath())); etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::path::getDataPath()));
EXPECT_EQ(etk::uri::provider::exist("DATA"), true); EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA"); ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
EXPECT_NE(provider, null); EXPECT_NE(provider, null);
@ -155,8 +155,8 @@ TEST(TestUriProvider, checkDirectAccess2) {
TEST(TestUriProvider, directExistFile) { TEST(TestUriProvider, directExistFile) {
etk::uri::provider::clear(); etk::uri::provider::clear();
TEST_VERBOSE("data path: " << etk::fs::getDataPath()); TEST_VERBOSE("data path: " << etk::path::getDataPath());
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::fs::getDataPath())); etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::path::getDataPath()));
EXPECT_EQ(etk::uri::provider::exist("DATA"), true); EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA"); ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
EXPECT_NE(provider, null); EXPECT_NE(provider, null);
@ -172,8 +172,8 @@ TEST(TestUriProvider, directExistFile) {
TEST(TestUriProvider, directReadFile) { TEST(TestUriProvider, directReadFile) {
etk::uri::provider::clear(); etk::uri::provider::clear();
TEST_VERBOSE("data path: " << etk::fs::getDataPath()); TEST_VERBOSE("data path: " << etk::path::getDataPath());
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::fs::getDataPath())); etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFile>(etk::path::getDataPath()));
EXPECT_EQ(etk::uri::provider::exist("DATA"), true); EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
etk::Uri element("DATA:///data/dir_B/file_B_1.txt"); etk::Uri element("DATA:///data/dir_B/file_B_1.txt");
ememory::SharedPtr<etk::io::Interface> ioElement = etk::uri::provider::get(element); ememory::SharedPtr<etk::io::Interface> ioElement = etk::uri::provider::get(element);
@ -196,8 +196,8 @@ etk::Vector<etk::Uri> listZip = {
TEST(TestUriProvider, checkZipAccess) { TEST(TestUriProvider, checkZipAccess) {
etk::uri::provider::clear(); etk::uri::provider::clear();
TEST_VERBOSE("data path: " << etk::fs::getDataPath()); TEST_VERBOSE("data path: " << etk::path::getDataPath());
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFileZip>(etk::fs::getDataPath() / "data_sample.zip", "data")); etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFileZip>(etk::path::getDataPath() / "data_sample.zip", "data"));
EXPECT_EQ(etk::uri::provider::exist("DATA"), true); EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA"); ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
EXPECT_NE(provider, null); EXPECT_NE(provider, null);
@ -219,8 +219,8 @@ etk::Vector<etk::Uri> listZip2 = {
TEST(TestUriProvider, checkZipAccess2) { TEST(TestUriProvider, checkZipAccess2) {
etk::uri::provider::clear(); etk::uri::provider::clear();
TEST_VERBOSE("data path: " << etk::fs::getDataPath()); TEST_VERBOSE("data path: " << etk::path::getDataPath());
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFileZip>(etk::fs::getDataPath() / "data_sample.zip", "data")); etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFileZip>(etk::path::getDataPath() / "data_sample.zip", "data"));
EXPECT_EQ(etk::uri::provider::exist("DATA"), true); EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA"); ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
EXPECT_NE(provider, null); EXPECT_NE(provider, null);
@ -236,8 +236,8 @@ TEST(TestUriProvider, checkZipAccess2) {
TEST(TestUriProvider, zipExistFile) { TEST(TestUriProvider, zipExistFile) {
etk::uri::provider::clear(); etk::uri::provider::clear();
TEST_VERBOSE("data path: " << etk::fs::getDataPath()); TEST_VERBOSE("data path: " << etk::path::getDataPath());
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFileZip>(etk::fs::getDataPath() / "data_sample.zip", "data")); etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFileZip>(etk::path::getDataPath() / "data_sample.zip", "data"));
EXPECT_EQ(etk::uri::provider::exist("DATA"), true); EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA"); ememory::SharedPtr<etk::uri::provider::Interface> provider = etk::uri::provider::getProvider("DATA");
EXPECT_NE(provider, null); EXPECT_NE(provider, null);
@ -253,8 +253,8 @@ TEST(TestUriProvider, zipExistFile) {
TEST(TestUriProvider, zipReadFile) { TEST(TestUriProvider, zipReadFile) {
etk::uri::provider::clear(); etk::uri::provider::clear();
TEST_VERBOSE("data path: " << etk::fs::getDataPath()); TEST_VERBOSE("data path: " << etk::path::getDataPath());
etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFileZip>(etk::fs::getDataPath() / "data_sample.zip", "data")); etk::uri::provider::add("DATA", ememory::makeShared<etk::uri::provider::ProviderFileZip>(etk::path::getDataPath() / "data_sample.zip", "data"));
EXPECT_EQ(etk::uri::provider::exist("DATA"), true); EXPECT_EQ(etk::uri::provider::exist("DATA"), true);
etk::Uri element("DATA:///dir_B/file_B_1.txt"); etk::Uri element("DATA:///dir_B/file_B_1.txt");
ememory::SharedPtr<etk::io::Interface> ioElement = etk::uri::provider::get(element); ememory::SharedPtr<etk::io::Interface> ioElement = etk::uri::provider::get(element);