summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2008-06-06 12:46:58 -0230
committerBenoit Foucher <benoit@zeroc.com>2008-06-06 17:54:49 +0200
commita9169f12e8417b91a7dcfea3b678d09ed2697b62 (patch)
tree2e072cc1d8319a7ce213590e9e15c719f5b29ab9 /cpp/src
parent- Fixed bug 3242 (diff)
downloadice-a9169f12e8417b91a7dcfea3b678d09ed2697b62.tar.bz2
ice-a9169f12e8417b91a7dcfea3b678d09ed2697b62.tar.xz
ice-a9169f12e8417b91a7dcfea3b678d09ed2697b62.zip
Bug 3014 - isAbsolute incorrect
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceGrid/Activator.cpp3
-rw-r--r--cpp/src/IceGrid/PlatformInfo.cpp3
-rw-r--r--cpp/src/IceGrid/ServerI.cpp5
-rw-r--r--cpp/src/IcePatch2/Calc.cpp5
-rw-r--r--cpp/src/IcePatch2/ClientUtil.cpp3
-rw-r--r--cpp/src/IcePatch2/FileServerI.cpp3
-rw-r--r--cpp/src/IcePatch2/Server.cpp3
-rw-r--r--cpp/src/IcePatch2/Util.cpp20
-rw-r--r--cpp/src/IcePatch2/Util.h1
-rw-r--r--cpp/src/IceUtil/FileUtil.cpp53
-rw-r--r--cpp/src/IceUtil/Makefile3
-rw-r--r--cpp/src/IceUtil/Makefile.mak3
-rw-r--r--cpp/src/Slice/Preprocessor.cpp5
-rw-r--r--cpp/src/Slice/Util.cpp21
-rw-r--r--cpp/src/iceserviceinstall/ServiceInstaller.cpp33
15 files changed, 83 insertions, 81 deletions
diff --git a/cpp/src/IceGrid/Activator.cpp b/cpp/src/IceGrid/Activator.cpp
index 501f8110741..d585a11eb15 100644
--- a/cpp/src/IceGrid/Activator.cpp
+++ b/cpp/src/IceGrid/Activator.cpp
@@ -9,6 +9,7 @@
#include <IceUtil/DisableWarnings.h>
#include <IceUtil/ArgVector.h>
+#include <IceUtil/FileUtil.h>
#include <Ice/Ice.h>
#include <IceGrid/Activator.h>
#include <IceGrid/Admin.h>
@@ -345,7 +346,7 @@ Activator::activate(const string& name,
string pwd = IcePatch2::simplify(pwdPath);
#ifdef _WIN32
- if(!IcePatch2::isAbsolute(path))
+ if(!IceUtilInternal::isAbsolutePath(path))
{
if(path.find('/') == string::npos)
{
diff --git a/cpp/src/IceGrid/PlatformInfo.cpp b/cpp/src/IceGrid/PlatformInfo.cpp
index d8f6c6c0cd4..b2550730d6e 100644
--- a/cpp/src/IceGrid/PlatformInfo.cpp
+++ b/cpp/src/IceGrid/PlatformInfo.cpp
@@ -8,6 +8,7 @@
// **********************************************************************
#include <IceUtil/StringUtil.h>
+#include <IceUtil/FileUtil.h>
#include <Ice/Communicator.h>
#include <Ice/Properties.h>
#include <Ice/LocalException.h>
@@ -278,7 +279,7 @@ PlatformInfo::PlatformInfo(const string& prefix,
_cwd = string(cwd);
_dataDir = properties->getProperty(prefix + ".Data");
- if(!IcePatch2::isAbsolute(_dataDir))
+ if(!IceUtilInternal::isAbsolutePath(_dataDir))
{
_dataDir = _cwd + '/' + _dataDir;
}
diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp
index c9b7afad093..c033ff18817 100644
--- a/cpp/src/IceGrid/ServerI.cpp
+++ b/cpp/src/IceGrid/ServerI.cpp
@@ -18,6 +18,7 @@
#include <IcePatch2/Util.h>
#include <IcePatch2/OS.h>
+#include <IceUtil/FileUtil.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -2027,7 +2028,7 @@ ServerI::updateImpl(const InternalServerDescriptorPtr& descriptor)
for(Ice::StringSeq::const_iterator p = _desc->logs.begin(); p != _desc->logs.end(); ++p)
{
string path = IcePatch2::simplify(*p);
- if(IcePatch2::isAbsolute(path))
+ if(IceUtilInternal::isAbsolutePath(path))
{
_logs.push_back(path);
}
@@ -2714,7 +2715,7 @@ ServerI::getFilePath(const string& filename) const
else if(!filename.empty() && filename[0] == '#')
{
string path = IcePatch2::simplify(filename.substr(1));
- if(!IcePatch2::isAbsolute(path))
+ if(!IceUtilInternal::isAbsolutePath(path))
{
path = _node->getPlatformInfo().getCwd() + "/" + path;
}
diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp
index 46d4d11d51c..9ed422548da 100644
--- a/cpp/src/IcePatch2/Calc.cpp
+++ b/cpp/src/IcePatch2/Calc.cpp
@@ -10,6 +10,7 @@
#include <IceUtil/Options.h>
#include <IceUtil/Unicode.h>
#include <IceUtil/StringUtil.h>
+#include <IceUtil/FileUtil.h>
#include <IcePatch2/Util.h>
#include <OS.h>
@@ -195,14 +196,14 @@ main(int argc, char* argv[])
throw "cannot get the current directory:\n" + IceUtilInternal::lastErrorToString();
}
- if(!isAbsolute(absDataDir))
+ if(!IceUtilInternal::isAbsolutePath(absDataDir))
{
absDataDir = simplify(cwd + '/' + absDataDir);
}
for(p = fileSeq.begin(); p != fileSeq.end(); ++p)
{
- if(!isAbsolute(*p))
+ if(!IceUtilInternal::isAbsolutePath(*p))
{
*p = cwd + '/' + *p;
}
diff --git a/cpp/src/IcePatch2/ClientUtil.cpp b/cpp/src/IcePatch2/ClientUtil.cpp
index 88d5f907633..072e35e0ed2 100644
--- a/cpp/src/IcePatch2/ClientUtil.cpp
+++ b/cpp/src/IcePatch2/ClientUtil.cpp
@@ -9,6 +9,7 @@
#include <IceUtil/Unicode.h>
#include <IceUtil/StringUtil.h>
+#include <IceUtil/FileUtil.h>
#define ICE_PATCH2_API_EXPORTS
#include <IcePatch2/ClientUtil.h>
#include <IcePatch2/Util.h>
@@ -611,7 +612,7 @@ IcePatch2::Patcher::init(const FileServerPrx& server)
const_cast<Int&>(_chunkSize) *= 1024;
}
- if(!isAbsolute(_dataDir))
+ if(!IceUtilInternal::isAbsolutePath(_dataDir))
{
string cwd;
if(OS::getcwd(cwd) != 0)
diff --git a/cpp/src/IcePatch2/FileServerI.cpp b/cpp/src/IcePatch2/FileServerI.cpp
index 49c6423df41..ac46286e001 100644
--- a/cpp/src/IcePatch2/FileServerI.cpp
+++ b/cpp/src/IcePatch2/FileServerI.cpp
@@ -8,6 +8,7 @@
// **********************************************************************
#include <IceUtil/DisableWarnings.h>
+#include <IceUtil/FileUtil.h>
#include <IceUtil/ScopedArray.h>
#include <IceUtil/Unicode.h>
#include <IcePatch2/FileServerI.h>
@@ -64,7 +65,7 @@ void
IcePatch2::FileServerI::getFileCompressed_async(const AMD_FileServer_getFileCompressedPtr& cb,
const string& pa, Int pos, Int num, const Current&) const
{
- if(isAbsolute(pa))
+ if(IceUtilInternal::isAbsolutePath(pa))
{
FileAccessException ex;
ex.reason = "illegal absolute path `" + pa + "'";
diff --git a/cpp/src/IcePatch2/Server.cpp b/cpp/src/IcePatch2/Server.cpp
index b5a7a5f828d..c7aeeb9c3cc 100644
--- a/cpp/src/IcePatch2/Server.cpp
+++ b/cpp/src/IcePatch2/Server.cpp
@@ -9,6 +9,7 @@
#include <IceUtil/Options.h>
#include <IceUtil/StringUtil.h>
+#include <IceUtil/FileUtil.h>
#include <Ice/Service.h>
#include <IcePatch2/FileServerI.h>
#include <IcePatch2/Util.h>
@@ -118,7 +119,7 @@ IcePatch2::PatcherService::start(int argc, char* argv[])
try
{
- if(!isAbsolute(dataDir))
+ if(!IceUtilInternal::isAbsolutePath(dataDir))
{
string cwd;
if(OS::getcwd(cwd) != 0)
diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp
index 86901d6857e..2b572c27e57 100644
--- a/cpp/src/IcePatch2/Util.cpp
+++ b/cpp/src/IcePatch2/Util.cpp
@@ -309,26 +309,6 @@ IcePatch2::simplify(const string& path)
}
bool
-IcePatch2::isAbsolute(const string& pa)
-{
- if(pa.empty())
- {
- return false;
- }
-
- unsigned i = 0;
- while(isspace(pa[i]))
- {
- ++i;
- }
-#ifdef _WIN32
- return pa[i] == '\\' || pa[i] == '/' || pa.size() > i + 1 && isalpha(pa[i]) && pa[i + 1] == ':';
-#else
- return pa[i] == '/';
-#endif
-}
-
-bool
IcePatch2::isRoot(const string& pa)
{
string path = simplify(pa);
diff --git a/cpp/src/IcePatch2/Util.h b/cpp/src/IcePatch2/Util.h
index f34d3b0e0e8..a703aedfb44 100644
--- a/cpp/src/IcePatch2/Util.h
+++ b/cpp/src/IcePatch2/Util.h
@@ -27,7 +27,6 @@ ICE_PATCH2_API Ice::ByteSeq stringToBytes(const std::string&);
ICE_PATCH2_API std::string simplify(const std::string&);
-ICE_PATCH2_API bool isAbsolute(const std::string&);
ICE_PATCH2_API bool isRoot(const std::string&);
ICE_PATCH2_API std::string getSuffix(const std::string&);
diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp
new file mode 100644
index 00000000000..c387115fee1
--- /dev/null
+++ b/cpp/src/IceUtil/FileUtil.cpp
@@ -0,0 +1,53 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2008 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <IceUtil/FileUtil.h>
+
+using namespace std;
+
+//
+// Detemine if path is an absolute path
+//
+bool
+IceUtilInternal::isAbsolutePath(const string& path)
+{
+ size_t i = 0;
+ size_t size = path.size();
+
+ // Skip whitespace
+ while(i < size && isspace(path[i]))
+ {
+ ++i;
+ }
+
+#ifdef _WIN32
+ // We need at least 3 non whitespace character to have
+ // and absolute path
+ if(i + 3 > size)
+ {
+ return false;
+ }
+
+ // Check for X:\ path ('\' may have been converted to '/')
+ if((path[i] >= 'A' && path[i] <= 'Z') || (path[i] >= 'a' && path[i] <= 'z'))
+ {
+ return path[i + 1] == ':' && (path[i + 2] == '\\' || path[i + 2] == '/');
+ }
+
+ // Check for UNC path
+ return (path[i] == '\\' && path[i + 1] == '\\') || path[i] == '/';
+#else
+ if(i >= size)
+ {
+ return false;
+ }
+
+ return path[i] == '/';
+#endif
+}
diff --git a/cpp/src/IceUtil/Makefile b/cpp/src/IceUtil/Makefile
index 033414933b6..1224452b529 100644
--- a/cpp/src/IceUtil/Makefile
+++ b/cpp/src/IceUtil/Makefile
@@ -21,7 +21,7 @@ OBJS = ArgVector.o \
CountDownLatch.o \
CtrlCHandler.o \
Exception.o \
- Shared.o \
+ FileUtil.o \
InputUtil.o \
Options.o \
OutputUtil.o \
@@ -29,6 +29,7 @@ OBJS = ArgVector.o \
RWRecMutex.o \
RecMutex.o \
StaticMutex.o \
+ Shared.o \
StringUtil.o \
Thread.o \
ThreadException.o \
diff --git a/cpp/src/IceUtil/Makefile.mak b/cpp/src/IceUtil/Makefile.mak
index 9aeb96e3332..745b3cf3411 100644
--- a/cpp/src/IceUtil/Makefile.mak
+++ b/cpp/src/IceUtil/Makefile.mak
@@ -20,13 +20,14 @@ OBJS = ArgVector.obj \
CountDownLatch.obj \
CtrlCHandler.obj \
Exception.obj \
- Shared.obj \
+ FileUtil.obj \
InputUtil.obj \
Options.obj \
OutputUtil.obj \
Random.obj \
RWRecMutex.obj \
RecMutex.obj \
+ Shared.obj \
StaticMutex.obj \
StringUtil.obj \
Thread.obj \
diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp
index fb7bef59d16..763b8a7a855 100644
--- a/cpp/src/Slice/Preprocessor.cpp
+++ b/cpp/src/Slice/Preprocessor.cpp
@@ -12,6 +12,7 @@
#include <Slice/Util.h>
#include <Slice/SignalHandler.h>
#include <IceUtil/StringUtil.h>
+#include <IceUtil/FileUtil.h>
#include <IceUtil/UUID.h>
#include <IceUtil/Unicode.h>
#include <algorithm>
@@ -295,7 +296,7 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin
{
end += 4;
string file = IceUtilInternal::trim(unprocessed.substr(pos, end - pos));
- if(isAbsolute(file))
+ if(IceUtilInternal::isAbsolutePath(file))
{
if(file == absoluteFileName)
{
@@ -313,7 +314,7 @@ Slice::Preprocessor::printMakefileDependencies(Language lang, const vector<strin
if(file.compare(0, p->length(), *p) == 0)
{
string s = includePaths[p - fullIncludePaths.begin()] + file.substr(p->length());
- if(isAbsolute(newFile) || s.size() < newFile.size())
+ if(IceUtilInternal::isAbsolutePath(newFile) || s.size() < newFile.size())
{
newFile = s;
}
diff --git a/cpp/src/Slice/Util.cpp b/cpp/src/Slice/Util.cpp
index a74c865ea7c..551aa0a4d46 100644
--- a/cpp/src/Slice/Util.cpp
+++ b/cpp/src/Slice/Util.cpp
@@ -9,6 +9,7 @@
#include <Slice/Util.h>
#include <IceUtil/Unicode.h>
+#include <IceUtil/FileUtil.h>
#include <climits>
#include <unistd.h> // For readlink()
@@ -64,25 +65,11 @@ normalizePath(const string& path)
return result;
}
-bool
-Slice::isAbsolute(const string& path)
-{
-#ifdef _WIN32
- if(path[0] == '\\' || path[0] == '/' || path.size() > 1 && isalpha(path[0]) && path[1] == ':')
-#else
- if(path[0] == '/')
-#endif
- {
- return true;
- }
- return false;
-}
-
string
Slice::fullPath(const string& path)
{
#ifdef _WIN32
- if(!isAbsolute(path))
+ if(!IceUtilInternal::isAbsolutePath(path))
{
wchar_t cwdbuf[_MAX_PATH];
if(_wgetcwd(cwdbuf, _MAX_PATH) != NULL)
@@ -93,7 +80,7 @@ Slice::fullPath(const string& path)
return normalizePath(path);
#else
string result = path;
- if(!isAbsolute(result))
+ if(!IceUtilInternal::isAbsolutePath(result))
{
char cwdbuf[PATH_MAX];
if(::getcwd(cwdbuf, PATH_MAX) != NULL)
@@ -125,7 +112,7 @@ Slice::fullPath(const string& path)
{
buf[len] = '\0';
string linkpath = buf;
- if(!isAbsolute(linkpath)) // Path relative to the location of the link
+ if(!IceUtilInternal::isAbsolutePath(linkpath)) // Path relative to the location of the link
{
string::size_type pos = subpath.rfind('/');
assert(pos != string::npos);
diff --git a/cpp/src/iceserviceinstall/ServiceInstaller.cpp b/cpp/src/iceserviceinstall/ServiceInstaller.cpp
index 2824971fc5b..ebbff53ba0e 100644
--- a/cpp/src/iceserviceinstall/ServiceInstaller.cpp
+++ b/cpp/src/iceserviceinstall/ServiceInstaller.cpp
@@ -15,6 +15,7 @@
#include <ServiceInstaller.h>
#include <IceUtil/StringUtil.h>
+#include <IceUtil/FileUtil.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -50,34 +51,6 @@ fixDirSeparator(const string& path)
return result;
}
-bool
-isAbsolutePath(const string& path)
-{
- size_t i = 0;
- size_t size = path.size();
-
- // Skip whitespace
- while(i < size && isspace(path[i]))
- {
- ++i;
- }
-
- // We need at least 3 non whitespace character to have
- // and absolute path
- if(i + 3 > size)
- {
- return false;
- }
-
- // Check for X:\ path
- if((path[i] >= 'A' && path[i] <= 'Z') || (path[i] >= 'a' && path[i] <= 'z'))
- {
- return path[i + 1] == ':' && path[i + 2] == '\\';
- }
-
- // Check for UNC path
- return path[i] == '\\' && path[i + 1] == '\\';
-}
}
IceServiceInstaller::IceServiceInstaller(int serviceType, const string& configFile,
@@ -210,7 +183,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
{
throw "IceGrid.Registry.Data must be set in " + _configFile;
}
- if(!isAbsolutePath(registryDataDir))
+ if(!IceUtilInternal::isAbsolutePath(registryDataDir))
{
throw "'" + registryDataDir + "' is a relative path; IceGrid.Registry.Data must be an absolute path";
}
@@ -227,7 +200,7 @@ IceServiceInstaller::install(const PropertiesPtr& properties)
{
throw "IceGrid.Node.Data must be set in " + _configFile;
}
- if(!isAbsolutePath(nodeDataDir))
+ if(!IceUtilInternal::isAbsolutePath(nodeDataDir))
{
throw "'" + nodeDataDir + "' is a relative path; IceGrid.Node.Data must be an absolute path";
}