#At file:///home/msvensson/mysql/6.4-wl4350-win/
2881 Magnus Svensson 2008-10-24
WL#4350 Windows fixes
added:
storage/ndb/src/mgmsrv/DirIterator.cpp
modified:
storage/ndb/src/mgmsrv/CMakeLists.txt
storage/ndb/src/mgmsrv/ConfigManager.cpp
storage/ndb/src/mgmsrv/DirIterator.hpp
storage/ndb/src/mgmsrv/Makefile.am
per-file messages:
storage/ndb/src/mgmsrv/CMakeLists.txt
Add DirIterator.cpp
storage/ndb/src/mgmsrv/ConfigManager.cpp
Use binary + commit mode when writing binary config to file
Use proper directory separator when concatenating path and filename
Use 'extern "C"' to reference options declared in ndb_opts.c
storage/ndb/src/mgmsrv/DirIterator.cpp
Add suport for iterating files in a dir on Windows
storage/ndb/src/mgmsrv/DirIterator.hpp
Add suport for iterating files in a dir on Windows
storage/ndb/src/mgmsrv/Makefile.am
Add DireIterator.cpp
=== modified file 'storage/ndb/src/mgmsrv/CMakeLists.txt'
--- a/storage/ndb/src/mgmsrv/CMakeLists.txt 2008-10-23 15:46:17 +0000
+++ b/storage/ndb/src/mgmsrv/CMakeLists.txt 2008-10-24 12:41:10 +0000
@@ -42,5 +42,5 @@ ADD_EXECUTABLE(ndb_mgmd
main.cpp
Services.cpp
ConfigManager.cpp
- ${CMAKE_SOURCE_DIR}/sql/nt_servc.cc)
+ DirIterator.cpp)
TARGET_LINK_LIBRARIES(ndb_mgmd ndbconf)
=== modified file 'storage/ndb/src/mgmsrv/ConfigManager.cpp'
--- a/storage/ndb/src/mgmsrv/ConfigManager.cpp 2008-10-21 12:41:59 +0000
+++ b/storage/ndb/src/mgmsrv/ConfigManager.cpp 2008-10-24 12:41:10 +0000
@@ -13,6 +13,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
#include "ConfigManager.hpp"
#include "MgmtSrvr.hpp"
@@ -37,7 +38,7 @@ require(bool v)
}
#endif
-extern const char* opt_connect_str;
+extern "C" const char* opt_connect_str;
ConfigManager::ConfigManager(const MgmtSrvr::MgmtOpts& opts) :
MgmtThread("ConfigManager"),
@@ -360,7 +361,7 @@ ConfigManager::prepareConfigChange(const
/* Write config to temporary file */
BaseString prep_config_name(m_config_name);
prep_config_name.append(".tmp");
- FILE * f = fopen(prep_config_name.c_str(), "w");
+ FILE * f = fopen(prep_config_name.c_str(), IF_WIN("wbc", "w"));
if(f == NULL)
{
g_eventLogger->error("Failed to open file '%s' while preparing, errno: %d",
@@ -386,6 +387,13 @@ ConfigManager::prepareConfigChange(const
return false;
}
+#ifdef __WIN__
+ /*
+ File is opened with the commit flag "c" so
+ that the contents of the file buffer are written
+ directly to disk when fflush is called
+ */
+#else
if (fsync(fileno(f)))
{
g_eventLogger->error("Failed to sync file '%s' while preparing, errno: %d",
@@ -394,6 +402,7 @@ ConfigManager::prepareConfigChange(const
unlink(prep_config_name.c_str());
return false;
}
+#endif
fclose(f);
m_prepared_config = new Config(config->m_configValues);
@@ -1503,8 +1512,8 @@ ConfigManager::saved_config_exists(BaseS
if (max_version == 0)
return false;
- config_name.assfmt("%s/ndb_%u_config.bin.%u",
- m_datadir, m_node_id, max_version);
+ config_name.assfmt("%s%sndb_%u_config.bin.%u",
+ m_datadir, DIR_SEPARATOR, m_node_id, max_version);
return true;
}
=== added file 'storage/ndb/src/mgmsrv/DirIterator.cpp'
--- a/storage/ndb/src/mgmsrv/DirIterator.cpp 1970-01-01 00:00:00 +0000
+++ b/storage/ndb/src/mgmsrv/DirIterator.cpp 2008-10-24 12:41:10 +0000
@@ -0,0 +1,122 @@
+/* Copyright (C) 2008 Sun Microsystems, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include "DirIterator.hpp"
+#include <stdio.h>
+
+#ifndef __WIN__
+
+#include <dirent.h>
+
+class DirIteratorImpl {
+ DIR* m_dirp;
+
+public:
+ DirIteratorImpl():
+ m_dirp(NULL) {};
+
+ ~DirIteratorImpl() {
+ closedir(m_dirp);
+ }
+
+ int open(const char* path){
+ if ((m_dirp = opendir(path)) == NULL){
+ return -1;
+ }
+ return 0;
+ }
+
+ const char* next_file(void){
+ struct dirent* dp;
+ while ((dp = readdir(m_dirp)) != NULL &&
+ dp->d_type != DT_REG)
+ ;
+ return dp ? dp->d_name : NULL;
+ }
+};
+
+#else
+
+#include <BaseString.hpp>
+
+class DirIteratorImpl {
+ bool m_first;
+ WIN32_FIND_DATA m_find_data;
+ HANDLE m_find_handle;
+
+ bool is_dir(const WIN32_FIND_DATA find_data) const {
+ return (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
+ }
+
+public:
+ DirIteratorImpl():
+ m_first(true),
+ m_find_handle(INVALID_HANDLE_VALUE) {};
+
+ ~DirIteratorImpl() {
+ FindClose(m_find_handle);
+ }
+
+ int open(const char* path){
+ BaseString path_buf;
+ path_buf.assfmt("%s\\*", path);
+ m_find_handle = FindFirstFile(path_buf.c_str(), &m_find_data);
+ if(m_find_handle == INVALID_HANDLE_VALUE)
+ {
+ if (GetLastError() == ERROR_FILE_NOT_FOUND)
+ m_first= false; // Will do a seek in 'next_file' and return NULL
+ else
+ return -1;
+ }
+ return 0;
+ }
+
+ const char* next_file(void){
+ while(m_first || FindNextFile(m_find_handle, &m_find_data))
+ {
+ m_first= false;
+
+ if (!is_dir(m_find_data))
+ return m_find_data.cFileName;
+ }
+ return NULL;
+ }
+
+};
+
+#endif
+
+
+DirIterator::DirIterator() :
+ m_impl(*new DirIteratorImpl())
+{
+};
+
+DirIterator::~DirIterator()
+{
+ delete &m_impl;
+}
+
+
+int DirIterator::open(const char* path)
+{
+ return m_impl.open(path);
+}
+
+const char* DirIterator::next_file(void)
+{
+ return m_impl.next_file();
+}
+
=== modified file 'storage/ndb/src/mgmsrv/DirIterator.hpp'
--- a/storage/ndb/src/mgmsrv/DirIterator.hpp 2008-10-21 12:41:59 +0000
+++ b/storage/ndb/src/mgmsrv/DirIterator.hpp 2008-10-24 12:41:10 +0000
@@ -16,31 +16,14 @@
#ifndef DirIterator_HPP
#define DirIterator_HPP
-#include <dirent.h>
-
class DirIterator {
- DIR* m_dirp;
+ class DirIteratorImpl& m_impl;
public:
- DirIterator():
- m_dirp(NULL) {};
- ~DirIterator() {
- closedir(m_dirp);
- }
-
- int open(const char* path){
- if ((m_dirp= opendir(path)) == NULL){
- return -1;
- }
- return 0;
- }
+ DirIterator();
+ ~DirIterator();
- const char* next_file(void){
- struct dirent* dp;
- while ((dp= readdir(m_dirp)) != NULL &&
- dp->d_type != DT_REG)
- ;
- return dp ? dp->d_name : NULL;
- }
+ int open(const char* path);
+ const char* next_file(void);
};
#endif
=== modified file 'storage/ndb/src/mgmsrv/Makefile.am'
--- a/storage/ndb/src/mgmsrv/Makefile.am 2008-10-21 12:41:59 +0000
+++ b/storage/ndb/src/mgmsrv/Makefile.am 2008-10-24 12:41:10 +0000
@@ -29,7 +29,8 @@ ndb_mgmd_SOURCES = \
ConfigInfo.cpp \
InitConfigFileParser.cpp \
Config.cpp \
- ConfigManager.cpp
+ ConfigManager.cpp \
+ DirIterator.cpp
noinst_PROGRAMS = testConfig
| Thread |
|---|
| • bzr commit into mysql-5.1 branch (msvensson:2881) WL#4350 | Magnus Svensson | 24 Oct |