diff options
author | Michi Henning <michi@zeroc.com> | 2005-03-02 02:06:05 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2005-03-02 02:06:05 +0000 |
commit | ad193ea9e13b334df57472f1b14d7cd4b0545f37 (patch) | |
tree | 0f69b35a7b3cc42283d70fc1587408e4616ab94a /cpp/src/IcePatch2/Util.cpp | |
parent | VC71 release crash work-around (diff) | |
download | ice-ad193ea9e13b334df57472f1b14d7cd4b0545f37.tar.bz2 ice-ad193ea9e13b334df57472f1b14d7cd4b0545f37.tar.xz ice-ad193ea9e13b334df57472f1b14d7cd4b0545f37.zip |
Fixed bug in IcePatch2: / couldn't be used as the data dir.
Diffstat (limited to 'cpp/src/IcePatch2/Util.cpp')
-rw-r--r-- | cpp/src/IcePatch2/Util.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp index c8f8ff2b087..7cc6b1442e7 100644 --- a/cpp/src/IcePatch2/Util.cpp +++ b/cpp/src/IcePatch2/Util.cpp @@ -247,11 +247,22 @@ IcePatch2::simplify(const string& path) result.erase(0, 2); } + if(result == "/." || + result.size() == 4 && isalpha(result[0]) && result[1] == ':' && result[2] == '/' && result[3] == '.') + { + return result.substr(0, result.size() - 1); + } + if(result.size() >= 2 && result.substr(result.size() - 2, 2) == "/.") { result.erase(result.size() - 2, 2); } + if(result == "/" || result.size() == 3 && isalpha(result[0]) && result[1] == ':' && result[2] == '/') + { + return result; + } + if(result.size() >= 1 && result[result.size() - 1] == '/') { result.erase(result.size() - 1); @@ -275,6 +286,17 @@ IcePatch2::isAbsolute(const string& pa) #endif } +bool +IcePatch2::isRoot(const string& pa) +{ + string path = simplify(pa); +#ifdef _WIN32 + return path == "/" || path.size() == 3 && isalpha(path[0]) && path[1] == ':' && path[2] == '/'; +#else + return path == "/"; +#endif +} + string IcePatch2::getSuffix(const string& pa) { @@ -417,13 +439,16 @@ IcePatch2::removeRecursive(const string& pa) removeRecursive(path + '/' + *p); } + if(!isRoot(path)) + { #ifdef _WIN32 - if(_rmdir(path.c_str()) == -1) + if(_rmdir(path.c_str()) == -1) #else - if(rmdir(path.c_str()) == -1) + if(rmdir(path.c_str()) == -1) #endif - { - throw "cannot remove directory `" + path + "':\n" + lastError(); + { + throw "cannot remove directory `" + path + "':\n" + lastError(); + } } } else @@ -443,7 +468,7 @@ IcePatch2::readDirectory(const string& pa) #ifdef _WIN32 struct _finddata_t data; - long h = _findfirst((path + "/*").c_str(), &data); + long h = _findfirst(simplify((path + "/*")).c_str(), &data); if(h == -1) { throw "cannot read directory `" + path + "':\n" + lastError(); @@ -698,7 +723,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G return true; } - const string path = basePath + '/' + relPath; + const string path = simplify(basePath + '/' + relPath); if(ignoreSuffix(path)) { |