[DEV] add copy and remove in URI interface
This commit is contained in:
parent
38829891c6
commit
669fb6968d
14
etk/uri/provider/Interface.cpp
Normal file
14
etk/uri/provider/Interface.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#include <etk/uri/provider/Interface.hpp>
|
||||
|
||||
uint64_t etk::uri::provider::Interface::fileSize(const etk::Uri& _uri) {
|
||||
auto fileIO = create(_uri);
|
||||
if (fileIO == null) {
|
||||
return 0;
|
||||
}
|
||||
return fileIO->size();
|
||||
}
|
@ -50,10 +50,52 @@ namespace etk {
|
||||
* @return false This is something else...
|
||||
*/
|
||||
virtual bool isSymLink(const etk::Uri& _uri) = 0;
|
||||
/**
|
||||
* @brief Get the File size
|
||||
* @param[in] _uri URI of the file
|
||||
* @return the requested size
|
||||
*/
|
||||
virtual uint64_t fileSize(const etk::Uri& _uri);
|
||||
virtual etk::Vector<etk::Uri> list(const etk::Uri& _uri) = 0;
|
||||
virtual etk::Vector<etk::Uri> listRecursive(const etk::Uri& _uri) = 0;
|
||||
/**
|
||||
* @brief Check if an URI Can be moved.
|
||||
* @param[in] _uri Uri to check.
|
||||
* @return true if it is possible, false ortherwise
|
||||
*/
|
||||
virtual bool canMove() { return false; }
|
||||
/**
|
||||
* @brief Move an element for a source to a destination.
|
||||
* @param[in] _uriSource Source Uri.
|
||||
* @param[in] _uriDestination Destination Uri.
|
||||
* @return true if moved, false ortherwise
|
||||
*/
|
||||
virtual bool move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) { return false; }
|
||||
/**
|
||||
* @brief Check if an URI Can be copy.
|
||||
* @param[in] _uri Uri to check.
|
||||
* @return true if it is possible, false ortherwise
|
||||
*/
|
||||
virtual bool canCopy() { return false; }
|
||||
/**
|
||||
* @brief Copy an element for a source to a destination.
|
||||
* @param[in] _uriSource Source Uri.
|
||||
* @param[in] _uriDestination Destination Uri.
|
||||
* @return true if copied, false ortherwise
|
||||
*/
|
||||
virtual bool copy(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) { return false; }
|
||||
/**
|
||||
* @brief Check if an URI Can be removed.
|
||||
* @param[in] _uri Uri to check.
|
||||
* @return true if it is possible, false ortherwise
|
||||
*/
|
||||
virtual bool canRemove() { return false; }
|
||||
/**
|
||||
* @brief Remove an element.
|
||||
* @param[in] _uri Uri to remove.
|
||||
* @return true if removed, false ortherwise
|
||||
*/
|
||||
virtual bool remove(const etk::Uri& _uri) { return false; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -105,3 +105,19 @@ bool etk::uri::provider::ProviderFile::canMove() {
|
||||
bool etk::uri::provider::ProviderFile::move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) {
|
||||
return etk::path::move(_uriSource.getPath(), _uriDestination.getPath());
|
||||
}
|
||||
|
||||
bool etk::uri::provider::ProviderFile::canCopy() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool etk::uri::provider::ProviderFile::copy(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) {
|
||||
return etk::path::copy(_uriSource.getPath(), _uriDestination.getPath());
|
||||
}
|
||||
|
||||
bool etk::uri::provider::ProviderFile::canRemove() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool etk::uri::provider::ProviderFile::remove(const etk::Uri& _uri) {
|
||||
return etk::path::remove(_uri.getPath());
|
||||
}
|
||||
|
@ -25,8 +25,12 @@ namespace etk {
|
||||
bool isSymLink(const etk::Uri& _uri) override;
|
||||
etk::Vector<etk::Uri> list(const etk::Uri& _uri) override;
|
||||
etk::Vector<etk::Uri> listRecursive(const etk::Uri& _uri) override;
|
||||
virtual bool canMove() override;
|
||||
virtual bool move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) override;
|
||||
bool canMove() override;
|
||||
bool move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) override;
|
||||
bool canCopy() override;
|
||||
bool copy(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) override;
|
||||
bool canRemove() override;
|
||||
bool remove(const etk::Uri& _uri) override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,17 @@ bool etk::uri::isSymLink(const etk::Uri& _uri) {
|
||||
return etk::uri::provider::getProviders()[scheme]->isSymLink(_uri);
|
||||
}
|
||||
|
||||
uint64_t etk::uri::fileSize(const etk::Uri& _uri) {
|
||||
etk::String scheme = _uri.getScheme();
|
||||
if (scheme.empty() == true) {
|
||||
scheme = "FILE";
|
||||
}
|
||||
if (etk::uri::provider::getProviders().exist(scheme) == false) {
|
||||
return 0;
|
||||
}
|
||||
return etk::uri::provider::getProviders()[scheme]->fileSize(_uri);
|
||||
}
|
||||
|
||||
etk::Vector<etk::Uri> etk::uri::list(const etk::Uri& _uri) {
|
||||
etk::String scheme = _uri.getScheme();
|
||||
if (scheme.empty() == true) {
|
||||
@ -132,6 +143,64 @@ bool etk::uri::move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination)
|
||||
return etk::uri::provider::getProviders()[scheme]->move(_uriSource, _uriDestination);
|
||||
}
|
||||
|
||||
bool etk::uri::canCopy(const etk::Uri& _uri) {
|
||||
etk::String scheme = _uri.getScheme();
|
||||
if (scheme.empty() == true) {
|
||||
scheme = "FILE";
|
||||
}
|
||||
if (etk::uri::provider::getProviders().exist(scheme) == false) {
|
||||
return false;
|
||||
}
|
||||
return etk::uri::provider::getProviders()[scheme]->canCopy();
|
||||
}
|
||||
|
||||
bool etk::uri::copy(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) {
|
||||
etk::String scheme = _uriSource.getScheme();
|
||||
if (scheme.empty() == true) {
|
||||
scheme = "FILE";
|
||||
}
|
||||
etk::String scheme2 = _uriDestination.getScheme();
|
||||
if (scheme2.empty() == true) {
|
||||
scheme2 = "FILE";
|
||||
}
|
||||
if (scheme != scheme2) {
|
||||
TK_ERROR("Can not copy 2 uri between 2 model of resource... " << _uriSource << " => " << _uriDestination);
|
||||
return false;
|
||||
}
|
||||
if (etk::uri::provider::getProviders().exist(scheme) == false) {
|
||||
return false;
|
||||
}
|
||||
if (etk::uri::provider::getProviders()[scheme]->canCopy() == false) {
|
||||
return false;
|
||||
}
|
||||
return etk::uri::provider::getProviders()[scheme]->copy(_uriSource, _uriDestination);
|
||||
}
|
||||
|
||||
bool etk::uri::canRemove(const etk::Uri& _uri) {
|
||||
etk::String scheme = _uri.getScheme();
|
||||
if (scheme.empty() == true) {
|
||||
scheme = "FILE";
|
||||
}
|
||||
if (etk::uri::provider::getProviders().exist(scheme) == false) {
|
||||
return false;
|
||||
}
|
||||
return etk::uri::provider::getProviders()[scheme]->canRemove();
|
||||
}
|
||||
|
||||
bool etk::uri::remove(const etk::Uri& _uri) {
|
||||
etk::String scheme = _uri.getScheme();
|
||||
if (scheme.empty() == true) {
|
||||
scheme = "FILE";
|
||||
}
|
||||
if (etk::uri::provider::getProviders().exist(scheme) == false) {
|
||||
return false;
|
||||
}
|
||||
if (etk::uri::provider::getProviders()[scheme]->canRemove() == false) {
|
||||
return false;
|
||||
}
|
||||
return etk::uri::provider::getProviders()[scheme]->remove(_uri);
|
||||
}
|
||||
|
||||
bool etk::uri::writeAll(const etk::Uri& _uri, const etk::String& _data) {
|
||||
auto fileIo = etk::uri::get(_uri);
|
||||
if (fileIo == null) {
|
||||
|
@ -43,6 +43,12 @@ namespace etk {
|
||||
* @return false This is something else...
|
||||
*/
|
||||
bool isSymLink(const etk::Uri& _uri);
|
||||
/**
|
||||
* @brief Get the File size
|
||||
* @param[in] _uri URI of the file
|
||||
* @return the requested size
|
||||
*/
|
||||
uint64_t fileSize(const etk::Uri& _uri);
|
||||
/**
|
||||
* @brief Get the list of sub-element in the Uri
|
||||
* @param[in] _uri Uri requested as parent.
|
||||
@ -74,6 +80,31 @@ namespace etk {
|
||||
* @return true if moved, false ortherwise
|
||||
*/
|
||||
bool move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination);
|
||||
/**
|
||||
* @brief Check if an URI Can be copy.
|
||||
* @param[in] _uri Uri to check.
|
||||
* @return true if it is possible, false ortherwise
|
||||
*/
|
||||
bool canCopy(const etk::Uri& _uri);
|
||||
/**
|
||||
* @brief Copy an element for a source to a destination.
|
||||
* @param[in] _uriSource Source Uri.
|
||||
* @param[in] _uriDestination Destination Uri.
|
||||
* @return true if copied, false ortherwise
|
||||
*/
|
||||
bool copy(const etk::Uri& _uriSource, const etk::Uri& _uriDestination);
|
||||
/**
|
||||
* @brief Check if an URI Can be removed.
|
||||
* @param[in] _uri Uri to check.
|
||||
* @return true if it is possible, false ortherwise
|
||||
*/
|
||||
bool canRemove(const etk::Uri& _uri);
|
||||
/**
|
||||
* @brief Remove an element.
|
||||
* @param[in] _uri Uri to remove.
|
||||
* @return true if removed, false ortherwise
|
||||
*/
|
||||
bool remove(const etk::Uri& _uri);
|
||||
/**
|
||||
* @brief Write all a string in a uri (if possible)
|
||||
* @param[in] _uri Uri destination.
|
||||
|
@ -59,6 +59,7 @@ def configure(target, my_module):
|
||||
'etk/uri/uri.cpp',
|
||||
'etk/uri/Query.cpp',
|
||||
'etk/uri/provider/provider.cpp',
|
||||
'etk/uri/provider/Interface.cpp',
|
||||
'etk/uri/provider/ProviderFile.cpp',
|
||||
'etk/uri/provider/ProviderFileZip.cpp',
|
||||
])
|
||||
|
@ -34,6 +34,15 @@ namespace {
|
||||
bool exist(const etk::Uri& _uri) override {
|
||||
return false;
|
||||
}
|
||||
bool isDirectory(const etk::Uri& _uri) override {
|
||||
return false;
|
||||
}
|
||||
bool isFile(const etk::Uri& _uri) override {
|
||||
return false;
|
||||
}
|
||||
bool isSymLink(const etk::Uri& _uri) override {
|
||||
return false;
|
||||
}
|
||||
etk::Vector<etk::Uri> list(const etk::Uri& _uri) override {
|
||||
etk::Vector<etk::Uri> out;
|
||||
return out;
|
||||
@ -52,6 +61,15 @@ namespace {
|
||||
bool exist(const etk::Uri& _uri) override {
|
||||
return false;
|
||||
}
|
||||
bool isDirectory(const etk::Uri& _uri) override {
|
||||
return false;
|
||||
}
|
||||
bool isFile(const etk::Uri& _uri) override {
|
||||
return false;
|
||||
}
|
||||
bool isSymLink(const etk::Uri& _uri) override {
|
||||
return false;
|
||||
}
|
||||
etk::Vector<etk::Uri> list(const etk::Uri& _uri) override {
|
||||
etk::Vector<etk::Uri> out;
|
||||
return out;
|
||||
|
Loading…
x
Reference in New Issue
Block a user