[DEBUG] add check on nullptr for file error prevention
This commit is contained in:
parent
f3d93713c0
commit
27bb43e322
@ -1940,14 +1940,14 @@ std::string etk::FSNode::fileGetExtention() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint64_t etk::FSNode::fileSize() {
|
uint64_t etk::FSNode::fileSize() {
|
||||||
if (etk::typeNode_file != m_typeNode) {
|
if (m_typeNode != etk::typeNode_file) {
|
||||||
TK_ERROR("Request size of a non file node : " << m_typeNode);
|
TK_ERROR("Request size of a non file node : " << m_typeNode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_ZIP_DATA
|
#ifdef HAVE_ZIP_DATA
|
||||||
if( etk::FSNType_data == m_type
|
if( m_type == etk::FSNType_data
|
||||||
|| etk::FSNType_themeData == m_type) {
|
|| m_type == etk::FSNType_themeData) {
|
||||||
if (true == loadDataZip()) {
|
if (loadDataZip() == true) {
|
||||||
return m_zipContent->getTheoricSize();
|
return m_zipContent->getTheoricSize();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -1956,7 +1956,7 @@ uint64_t etk::FSNode::fileSize() {
|
|||||||
// 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;
|
||||||
if (-1 == stat(m_systemFileName.c_str(), &statProperty)) {
|
if (stat(m_systemFileName.c_str(), &statProperty) == -1) {
|
||||||
//Normal case when the file does not exist ... ==> the it was in unknow mode ...
|
//Normal case when the file does not exist ... ==> the it was in unknow mode ...
|
||||||
TK_ERROR("mlkmlkmlkmlkmlkmlk");
|
TK_ERROR("mlkmlkmlkmlkmlkmlk");
|
||||||
return 0;
|
return 0;
|
||||||
@ -1971,9 +1971,9 @@ uint64_t etk::FSNode::fileSize() {
|
|||||||
|
|
||||||
bool etk::FSNode::fileOpenRead() {
|
bool etk::FSNode::fileOpenRead() {
|
||||||
#ifdef HAVE_ZIP_DATA
|
#ifdef HAVE_ZIP_DATA
|
||||||
if( etk::FSNType_data == m_type
|
if( m_type == etk::FSNType_data
|
||||||
|| etk::FSNType_themeData == m_type) {
|
|| m_type == etk::FSNType_themeData) {
|
||||||
if (false==loadDataZip()) {
|
if (loadDataZip() == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::unique_lock<std::mutex> lock(getNodeMutex());
|
std::unique_lock<std::mutex> lock(getNodeMutex());
|
||||||
@ -1981,13 +1981,13 @@ bool etk::FSNode::fileOpenRead() {
|
|||||||
return m_zipContent->getTheoricSize() == m_zipContent->size();
|
return m_zipContent->getTheoricSize() == m_zipContent->size();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (nullptr != m_PointerFile) {
|
if (m_PointerFile != nullptr) {
|
||||||
TK_CRITICAL("File Already open : " << *this);
|
TK_CRITICAL("File Already open : " << *this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
TK_VERBOSE(" Read file : " << m_systemFileName);
|
TK_VERBOSE(" Read file : " << m_systemFileName);
|
||||||
m_PointerFile = fopen(m_systemFileName.c_str(),"rb");
|
m_PointerFile = fopen(m_systemFileName.c_str(),"rb");
|
||||||
if(nullptr == m_PointerFile) {
|
if(m_PointerFile == nullptr) {
|
||||||
TK_ERROR("Can not find the file " << *this );
|
TK_ERROR("Can not find the file " << *this );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2000,14 +2000,14 @@ bool etk::FSNode::fileOpenWrite() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (nullptr != m_PointerFile) {
|
if (m_PointerFile != nullptr) {
|
||||||
TK_CRITICAL("File Already open : " << *this);
|
TK_CRITICAL("File Already open : " << *this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777);
|
FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777);
|
||||||
TK_VERBOSE(" write file : " << m_systemFileName);
|
TK_VERBOSE("Write file : " << m_systemFileName);
|
||||||
m_PointerFile = fopen(m_systemFileName.c_str(),"wb");
|
m_PointerFile = fopen(m_systemFileName.c_str(),"wb");
|
||||||
if(nullptr == m_PointerFile) {
|
if(m_PointerFile == nullptr) {
|
||||||
TK_ERROR("Can not find the file " << *this);
|
TK_ERROR("Can not find the file " << *this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2021,16 +2021,16 @@ bool etk::FSNode::fileOpenAppend() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (nullptr != m_PointerFile) {
|
if (m_PointerFile != nullptr) {
|
||||||
TK_CRITICAL("File Already open : " << *this);
|
TK_CRITICAL("File Already open : " << *this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777);
|
FSNODE_LOCAL_mkPath(getNameFolder().c_str() , 0777);
|
||||||
|
|
||||||
TK_VERBOSE(" append file : " << m_systemFileName);
|
TK_VERBOSE("Append file : " << m_systemFileName);
|
||||||
|
|
||||||
m_PointerFile = fopen(m_systemFileName.c_str(),"ab");
|
m_PointerFile = fopen(m_systemFileName.c_str(),"ab");
|
||||||
if(nullptr == m_PointerFile) {
|
if(m_PointerFile == nullptr) {
|
||||||
TK_ERROR("Can not find the file " << *this);
|
TK_ERROR("Can not find the file " << *this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2164,6 +2164,10 @@ int64_t etk::FSNode::fileRead(void* _data, int64_t _blockSize, int64_t _nbBlock)
|
|||||||
return _nbBlock;
|
return _nbBlock;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (m_PointerFile == nullptr) {
|
||||||
|
TK_ERROR("Can not read in a file that is not open : " << *this);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return fread(_data, _blockSize, _nbBlock, m_PointerFile);
|
return fread(_data, _blockSize, _nbBlock, m_PointerFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2189,6 +2193,10 @@ int64_t etk::FSNode::fileWrite(const void * _data, int64_t _blockSize, int64_t _
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (m_PointerFile == nullptr) {
|
||||||
|
TK_ERROR("Can not write in a file that is not open : " << *this);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return fwrite(_data, _blockSize, _nbBlock, m_PointerFile);
|
return fwrite(_data, _blockSize, _nbBlock, m_PointerFile);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user