[DEV] add create the path when moving a file

This commit is contained in:
Edouard DUPIN 2017-03-26 21:03:13 +02:00
parent cd0a7f3570
commit 72de271078

View File

@ -213,7 +213,7 @@ static int32_t FSNODE_LOCAL_mkPath(const char* _path, mode_t _mode) {
char *sp;
int status;
char *copypath = strdup(_path);
if (nullptr==copypath) {
if (copypath == nullptr) {
return -1;
}
status = 0;
@ -1379,8 +1379,12 @@ bool etk::FSNode::move(const std::string& _path) {
tmpDst.remove();
}
TK_DEBUG("Move : \"" << getFileSystemName() << "\" ==> \"" << tmpDst.getFileSystemName() << "\"");
// create path to be sure it exist ...
TK_VERBOSE("create path: '" << tmpDst.getNameFolder() << "'");
FSNODE_LOCAL_mkPath(tmpDst.getNameFolder().c_str() , 0755);
int32_t res = rename(getFileSystemName().c_str(), tmpDst.getFileSystemName().c_str());
if (res!=0) {
TK_ERROR("Can not move the file: '" << getFileSystemName() << "' ==> '" << tmpDst.getFileSystemName() << "'");
return false;
} else {
return true;
@ -2004,7 +2008,7 @@ bool etk::FSNode::fileOpenWrite() {
TK_CRITICAL("File Already open : " << *this);
return true;
}
FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777);
FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0744);
TK_VERBOSE("Write file : " << m_systemFileName);
m_PointerFile = fopen(m_systemFileName.c_str(),"wb");
if(m_PointerFile == nullptr) {
@ -2025,7 +2029,7 @@ bool etk::FSNode::fileOpenAppend() {
TK_CRITICAL("File Already open : " << *this);
return true;
}
FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777);
FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0744);
TK_VERBOSE("Append file : " << m_systemFileName);