From 4ffe6c34272127f822d6643273a471a0074e7743 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 16 Apr 2013 22:53:09 +0200 Subject: [PATCH] [DEBUG] node::touch and special int to string convertion --- etk/UString.cpp | 8 ++++---- etk/UString.h | 4 ++-- etk/os/FSNode.cpp | 37 +++++++++++++++++++++++++++++++++---- etk/os/FSNode.h | 17 ++++++++++++++++- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/etk/UString.cpp b/etk/UString.cpp index e52c7bb..ac066f6 100644 --- a/etk/UString.cpp +++ b/etk/UString.cpp @@ -136,11 +136,11 @@ etk::UString::UString(char inputData) } -etk::UString::UString(int inputData) +etk::UString::UString(int inputData, const char* mode) { char tmpVal[256]; // generate the UString : - sprintf(tmpVal, "%d", inputData); + sprintf(tmpVal, mode, inputData); // set the internal data : m_data.Clear(); m_data.PushBack('\0'); @@ -148,11 +148,11 @@ etk::UString::UString(int inputData) } -etk::UString::UString(unsigned int inputData) +etk::UString::UString(unsigned int inputData, const char* mode) { char tmpVal[256]; // generate the UString : - sprintf(tmpVal, "%d", inputData); + sprintf(tmpVal, mode, inputData); // set the internal data : m_data.Clear(); m_data.PushBack('\0'); diff --git a/etk/UString.h b/etk/UString.h index 416daa5..1d6ee07 100644 --- a/etk/UString.h +++ b/etk/UString.h @@ -27,8 +27,8 @@ namespace etk void Set(const char* inputData, int32_t len=-1); // basic convertion integer en string UString(char inputData); - UString(int inputData); - UString(unsigned int inputData); + UString(int inputData, const char* mode="%d"); + UString(unsigned int inputData, const char* mode="%d"); UString(float inputData); UString(double inputData); UString(const etk::UString &etkS); diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 888e6e2..486dc91 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -863,6 +863,7 @@ etk::UString etk::FSNode::GetRelativeFolder(void) const bool etk::FSNode::Touch(void) { + TK_DEBUG("Touch FILE : " << GetName()); //just open in write an close ==> this will update the time if (false==FileOpenAppend()) { return false; @@ -872,6 +873,21 @@ bool etk::FSNode::Touch(void) UpdateFileSystemProperty(); return ret; } + +bool etk::FSNode::Move(const etk::UString& path) +{ + etk::FSNode tmpDst(path); + if (tmpDst.Exist()==true) { + tmpDst.Remove(); + } + int32_t res = rename(GetName().c_str(), tmpDst.GetName().c_str()); + if (res!=0) { + return false; + } else { + return true; + } +} + bool etk::FSNode::Remove(void) { if (GetNodeType()==etk::FSN_FOLDER) { @@ -1288,6 +1304,7 @@ bool etk::FSNode::FileOpenRead(void) TK_CRITICAL("File Already open : " << *this); return true; } + TK_VERBOSE(" Read file : " << m_systemFileName); m_PointerFile=fopen(m_systemFileName.c_str(),"rb"); if(NULL == m_PointerFile) { TK_ERROR("Can not find the file " << *this ); @@ -1308,6 +1325,7 @@ bool etk::FSNode::FileOpenWrite(void) return true; } FSNODE_LOCAL_mkPath(GetNameFolder().c_str() , 0777); + TK_VERBOSE(" write file : " << m_systemFileName); m_PointerFile=fopen(m_systemFileName.c_str(),"wb"); if(NULL == m_PointerFile) { TK_ERROR("Can not find the file " << *this); @@ -1329,6 +1347,8 @@ bool etk::FSNode::FileOpenAppend(void) } FSNODE_LOCAL_mkPath(GetNameFolder().c_str() , 0777); + TK_VERBOSE(" append file : " << m_systemFileName); + m_PointerFile=fopen(m_systemFileName.c_str(),"ab"); if(NULL == m_PointerFile) { TK_ERROR("Can not find the file " << *this); @@ -1600,6 +1620,18 @@ bool etk::FSNodeExist(const etk::UString& path) return tmpNode.Exist(); } +bool etk::FSNodeMove(const etk::UString& path1, const etk::UString& path2) +{ + etk::FSNode tmpNode(path1); + if (false==tmpNode.Exist()) { + return false; + } + // no check error in every case + (void)etk::FSNodeRemove(path2); + //move the node + return tmpNode.Move(path2); +} + etk::FSNodeRight etk::FSNodeGetRight(const etk::UString& path) { etk::FSNode tmpNode(path); @@ -1630,12 +1662,9 @@ uint64_t etk::FSNodeGetTimeAccessed(const etk::UString& path) return tmpNode.TimeAccessed(); } -uint64_t etk::FSNodeTouch(const etk::UString& path) +bool etk::FSNodeTouch(const etk::UString& path) { etk::FSNode tmpNode(path); - if (false==tmpNode.Exist()) { - return false; - } return tmpNode.Touch(); } diff --git a/etk/os/FSNode.h b/etk/os/FSNode.h index 9a0a8cf..3975784 100644 --- a/etk/os/FSNode.h +++ b/etk/os/FSNode.h @@ -233,6 +233,13 @@ namespace etk * @return false : action not done */ bool Touch(void); + /** + * @brief Move the Node at a new path + * @param[in] path The new path + * @return true : action done + * @return false : action not done + */ + bool Move(const etk::UString& path); /** * @brief Get the node type (DATA/DIRECT...) * @return the requested type @@ -498,6 +505,14 @@ namespace etk * @return false : An error occured */ bool FSNodeExist(const etk::UString& path); + /** + * @brief Simple access for : chexk the exestance of an element + * @param[in] path Folder/File/Pipe path of the node sources + * @param[in] path Folder/File/Pipe path of the node destination + * @return true : Action done corectly + * @return false : An error occured + */ + bool FSNodeMove(const etk::UString& path1, const etk::UString& path2); /** * @brief Simple access for : Get right of the current Node * @param[in] path Folder/File/Pipe path of the node @@ -539,7 +554,7 @@ namespace etk * @return true : Action done corectly * @return false : An error occured */ - uint64_t FSNodeTouch(const etk::UString& path); + bool FSNodeTouch(const etk::UString& path); /** * @brief Simple access for : Basic write on the node (like console echo) * @param[in] path Folder/File/Pipe path of the node