diff --git a/bin/release/redis-2.8.12.zip b/bin/release/redis-2.8.12.zip index 46bc5fdc..6cb95765 100644 Binary files a/bin/release/redis-2.8.12.zip and b/bin/release/redis-2.8.12.zip differ diff --git a/src/Win32_Interop/Win32_CommandLine.cpp b/src/Win32_Interop/Win32_CommandLine.cpp index fac79106..ffc66ebd 100644 --- a/src/Win32_Interop/Win32_CommandLine.cpp +++ b/src/Win32_Interop/Win32_CommandLine.cpp @@ -32,6 +32,8 @@ // definition. #undef solves the warning messages. #undef close +#include + #include #include #include @@ -40,22 +42,25 @@ #include using namespace std; +#pragma comment (lib, "Shlwapi.lib") ArgumentMap g_argMap; string stripQuotes(string s) { - if (s.at(0) == '\'' && s.at(s.length() - 1) == '\'') { - if (s.length() > 2) { - return s.substr(1, s.length() - 2); - } else { - return string(""); + if (s.length() >= 2) { + if (s.at(0) == '\'' && s.at(s.length() - 1) == '\'') { + if (s.length() > 2) { + return s.substr(1, s.length() - 2); + } else { + return string(""); + } } - } - if (s.at(0) == '\"' && s.at(s.length() - 1) == '\"') { - if (s.length() > 2) { - return s.substr(1, s.length() - 2); - } else { - return string(""); + if (s.at(0) == '\"' && s.at(s.length() - 1) == '\"') { + if (s.length() > 2) { + return s.substr(1, s.length() - 2); + } else { + return string(""); + } } } return s; @@ -439,7 +444,36 @@ std::vector split(const std::string &s, char delim) { return elems; } -void ParseConfFile(string confFile, ArgumentMap& argMap) { +vector Tokenize(string line) { + vector tokens; + stringstream token; + for (string::iterator sit = line.begin(); sit != line.end(); sit++) { + char c = *(sit); + if (isspace(c) && token.str().length() > 0) { + tokens.push_back(token.str()); + token.str(""); + } else if (c == '\'' || c == '\"') { + char endQuote = c; + while (++sit != line.end()) { + if (*sit == endQuote) break; + token << *sit; + } + string path = token.str(); + replace(path.begin(), path.end(), '/', '\\'); + tokens.push_back(path); + token.str(""); + } else { + token << c; + } + } + if (token.str().length() > 0) { + tokens.push_back(token.str()); + } + + return tokens; +} + +void ParseConfFile(string confFile, string cwd, ArgumentMap& argMap) { ifstream config; string line; string value; @@ -447,25 +481,31 @@ void ParseConfFile(string confFile, ArgumentMap& argMap) { #ifdef _DEBUG cout << "processing " << confFile << endl; #endif + char fullConfFilePath[MAX_PATH]; + if (PathIsRelativeA(confFile.c_str())) { + if (NULL == PathCombineA(fullConfFilePath, cwd.c_str(), confFile.c_str())) { + throw std::system_error(GetLastError(), system_category(), "PathCombineA failed"); + } + } else { + strcpy(fullConfFilePath, confFile.c_str()); + } - config.open(confFile); + config.open(fullConfFilePath); if (config.fail()) { stringstream ss; - char buffer[MAX_PATH]; - ::GetCurrentDirectoryA(MAX_PATH, buffer); - ss << "Failed to open the .conf file: " << confFile << " CWD=" << buffer; + ss << "Failed to open the .conf file: " << confFile << " CWD=" << cwd.c_str(); throw runtime_error(ss.str()); } while (!config.eof()) { getline(config, line); - vector tokens = split(line, ' '); + vector tokens = Tokenize(line); if (tokens.size() > 0) { string parameter = tokens.at(0); if (parameter.at(0) == '#') { continue; } else if (parameter.compare(cInclude) == 0) { - ParseConfFile(tokens.at(1), argMap); + ParseConfFile(tokens.at(1), cwd, argMap); } else if (g_redisArgMap.find(parameter) == g_redisArgMap.end()) { stringstream err; err << "unknown conf file parameter : " + parameter; @@ -529,7 +569,12 @@ void ParseCommandLineArguments(int argc, char** argv) { } } - if (confFile) ParseConfFile(confFilePath, g_argMap); + char cwd[MAX_PATH]; + if (0 == ::GetCurrentDirectoryA(MAX_PATH, cwd)) { + throw std::system_error(GetLastError(), system_category(), "ParseCommandLineArguments: GetCurrentDirectoryA failed"); + } + + if (confFile) ParseConfFile(confFilePath, cwd, g_argMap); #ifdef _DEBUG cout << "arguments seen:" << endl; diff --git a/src/Win32_Interop/Win32_CommandLine.h b/src/Win32_Interop/Win32_CommandLine.h index f92f6cb1..39d2fbd5 100644 --- a/src/Win32_Interop/Win32_CommandLine.h +++ b/src/Win32_Interop/Win32_CommandLine.h @@ -35,7 +35,7 @@ using namespace std; typedef map>> ArgumentMap; extern ArgumentMap g_argMap; -void ParseConfFile(string confFile, ArgumentMap& argMap); +void ParseConfFile(string confFile, string cwd, ArgumentMap& argMap); void ParseCommandLineArguments(int argc, char** argv); const string cQFork = "qfork";