List:Commits« Previous MessageNext Message »
From:Magnus Svensson Date:October 24 2008 12:06pm
Subject:bzr commit into mysql-5.1 branch (msvensson:2881) WL#4350
View as plain text  
#At file:///home/msvensson/mysql/6.4-wl4350/

 2881 Magnus Svensson	2008-10-24
      WL#4350 Rewrite ConfigRetriever::getConfig(const char*) so it works on all platforms
modified:
  storage/ndb/include/mgmcommon/ConfigRetriever.hpp
  storage/ndb/src/common/mgmcommon/ConfigRetriever.cpp

=== modified file 'storage/ndb/include/mgmcommon/ConfigRetriever.hpp'
--- a/storage/ndb/include/mgmcommon/ConfigRetriever.hpp	2008-10-21 12:41:59 +0000
+++ b/storage/ndb/include/mgmcommon/ConfigRetriever.hpp	2008-10-24 10:06:10 +0000
@@ -91,9 +91,10 @@ private:
     CR_RETRY = 2
   };
   ErrorType latestErrorType;
-  
+
   void setError(ErrorType, const char * errorMsg);
-  
+  void setError(ErrorType, BaseString err);
+
   Uint32      _ownNodeId;
   bool m_end_session;
 

=== modified file 'storage/ndb/src/common/mgmcommon/ConfigRetriever.cpp'
--- a/storage/ndb/src/common/mgmcommon/ConfigRetriever.cpp	2008-10-24 09:37:49 +0000
+++ b/storage/ndb/src/common/mgmcommon/ConfigRetriever.cpp	2008-10-24 10:06:10 +0000
@@ -183,47 +183,45 @@ ConfigRetriever::getConfig(NdbMgmHandle 
 }
 
 ndb_mgm_configuration *
-ConfigRetriever::getConfig(const char * filename){
-#ifndef NDB_WIN32	
-
-  struct stat sbuf;
-  const int res = stat(filename, &sbuf);
-  if(res != 0){
-    char buf[255];
-    BaseString::snprintf(buf, sizeof(buf), "Could not find file: \"%s\"", filename);
-    setError(CR_ERROR, buf);
+ConfigRetriever::getConfig(const char * filename)
+{
+  if (access(filename, F_OK))
+  {
+    BaseString err;
+    err.assfmt("Could not find file: '%s'", filename);
+    setError(CR_ERROR, err);
     return 0;
   }
-  const Uint32 bytes = sbuf.st_size;
-  
-  Uint32 * buf2 = new Uint32[bytes/4+1];
-  
+
   FILE * f = fopen(filename, "rb");
-  if(f == 0){
+  if(f == 0)
+  {
     setError(CR_ERROR, "Failed to open file");
-    delete []buf2;
     return 0;
   }
-  Uint32 sz = fread(buf2, 1, bytes, f);
-  fclose(f);
-  if(sz != bytes){
-    setError(CR_ERROR, "Failed to read file");
-    delete []buf2;
-    return 0;
+
+  size_t read_sz;
+  char read_buf[512];
+  UtilBuffer config_buf;
+  while ((read_sz = fread(read_buf, 1, sizeof(read_buf), f)) != 0)
+  {
+    if (config_buf.append(read_buf, read_sz) != 0)
+    {
+      setError(CR_ERROR, "Out of memory when appending read data");
+      fclose(f);
+      return 0;
+    }
   }
-  
+  fclose(f);
+
   ConfigValuesFactory cvf;
-  if(!cvf.unpack(buf2, bytes)){
+  if(!cvf.unpack(config_buf))
+  {
     setError(CR_ERROR,  "Error while unpacking");
-    delete []buf2;
     return 0;
   }
-  delete [] buf2;
   return (ndb_mgm_configuration*)cvf.getConfigValues();
-#else
-  return 0;
-#endif
-}			   
+}
 
 void
 ConfigRetriever::setError(ErrorType et, const char * s){
@@ -232,6 +230,11 @@ ConfigRetriever::setError(ErrorType et, 
 }
 
 void
+ConfigRetriever::setError(ErrorType et, BaseString err){
+  setError(et, err.c_str());
+}
+
+void
 ConfigRetriever::resetError(){
   setError(CR_NO_ERROR,0);
 }

Thread
bzr commit into mysql-5.1 branch (msvensson:2881) WL#4350Magnus Svensson24 Oct