diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/.depend | 6 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Client.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Server.cpp | 29 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Util.cpp | 122 |
4 files changed, 97 insertions, 62 deletions
diff --git a/cpp/src/Ice/.depend b/cpp/src/Ice/.depend index 8b71f6996db..f7063a4f2c8 100644 --- a/cpp/src/Ice/.depend +++ b/cpp/src/Ice/.depend @@ -86,12 +86,12 @@ ThreadPool.o: ThreadPool.cpp ../Ice/ThreadPool.h ../../include/IceUtil/Shared.h TraceLevels.o: TraceLevels.cpp ../Ice/TraceLevels.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../Ice/TraceLevelsF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Ice/Config.h ../../include/Ice/PropertiesF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/Ice/Properties.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionIF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/ConnectionF.h ../../include/Ice/Identity.h ../../include/Ice/StreamF.h ../../include/Ice/BuiltinSequences.h TraceUtil.o: TraceUtil.cpp ../../include/IceUtil/StaticMutex.h ../../include/IceUtil/Config.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/IceUtil/Exception.h ../../include/IceUtil/StringUtil.h ../Ice/TraceUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/Ice/Config.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../Ice/TraceLevelsF.h ../Ice/Instance.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/RecMutex.h ../../include/Ice/InstanceF.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../../include/Ice/StatsF.h ../Ice/DefaultsAndOverridesF.h ../Ice/RouterInfoF.h ../Ice/LocatorInfoF.h ../Ice/ReferenceFactoryF.h ../../include/Ice/ProxyFactoryF.h ../Ice/ThreadPoolF.h ../../include/Ice/ConnectionFactoryF.h ../../include/Ice/ConnectionMonitorF.h ../Ice/ObjectFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../Ice/EndpointFactoryManagerF.h ../../include/Ice/DynamicLibraryF.h ../../include/Ice/PluginF.h ../../include/Ice/Object.h ../../include/IceUtil/GCShared.h ../../include/IceUtil/GCRecMutex.h ../../include/Ice/IncomingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ConnectionF.h ../../include/Ice/Identity.h ../../include/Ice/StreamF.h ../../include/Ice/Proxy.h ../../include/Ice/ConnectionIF.h ../../include/Ice/EndpointF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../Ice/TraceLevels.h ../../include/Ice/Logger.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../Ice/Protocol.h ../../include/Ice/IdentityUtil.h Transceiver.o: Transceiver.cpp ../Ice/Transceiver.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../Ice/TransceiverF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Ice/Config.h -UdpEndpoint.o: UdpEndpoint.cpp ../Ice/UdpEndpoint.h ../Ice/Endpoint.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/Ice/EndpointF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Ice/Config.h ../../include/Ice/InstanceF.h ../Ice/TransceiverF.h ../Ice/ConnectorF.h ../Ice/AcceptorF.h ../../include/Ice/EndpointFactory.h ../../include/Ice/EndpointFactoryF.h ../Ice/Network.h ../Ice/UdpTransceiver.h ../Ice/TraceLevelsF.h ../../include/Ice/LoggerF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/Ice/StatsF.h ../Ice/Transceiver.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/LocalException.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionIF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/ConnectionF.h ../../include/Ice/Identity.h ../../include/Ice/StreamF.h ../../include/Ice/BuiltinSequences.h ../Ice/Instance.h ../../include/IceUtil/RecMutex.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../Ice/DefaultsAndOverridesF.h ../Ice/RouterInfoF.h ../Ice/LocatorInfoF.h ../Ice/ReferenceFactoryF.h ../Ice/ThreadPoolF.h ../../include/Ice/ConnectionFactoryF.h ../../include/Ice/ConnectionMonitorF.h ../Ice/ObjectFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../Ice/EndpointFactoryManagerF.h ../../include/Ice/DynamicLibraryF.h ../../include/Ice/PluginF.h ../Ice/DefaultsAndOverrides.h ../Ice/Protocol.h -UdpTransceiver.o: UdpTransceiver.cpp ../Ice/UdpTransceiver.h ../../include/Ice/InstanceF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../Ice/TraceLevelsF.h ../../include/Ice/LoggerF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StatsF.h ../Ice/Transceiver.h ../Ice/TransceiverF.h ../Ice/Instance.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/IceUtil/RecMutex.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../Ice/DefaultsAndOverridesF.h ../Ice/RouterInfoF.h ../Ice/LocatorInfoF.h ../Ice/ReferenceFactoryF.h ../../include/Ice/ProxyFactoryF.h ../Ice/ThreadPoolF.h ../../include/Ice/ConnectionFactoryF.h ../../include/Ice/ConnectionMonitorF.h ../Ice/ObjectFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../Ice/EndpointFactoryManagerF.h ../../include/Ice/DynamicLibraryF.h ../../include/Ice/PluginF.h ../Ice/TraceLevels.h ../../include/Ice/LoggerUtil.h ../../include/Ice/Stats.h ../../include/Ice/Buffer.h ../Ice/Network.h ../../include/Ice/LocalException.h ../../include/Ice/Proxy.h ../../include/Ice/ConnectionIF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/ConnectionF.h ../../include/Ice/Identity.h ../../include/Ice/StreamF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Properties.h +UdpEndpoint.o: UdpEndpoint.cpp ../Ice/UdpEndpoint.h ../Ice/Endpoint.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/Ice/EndpointF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Ice/Config.h ../../include/Ice/InstanceF.h ../Ice/TransceiverF.h ../Ice/ConnectorF.h ../Ice/AcceptorF.h ../../include/Ice/EndpointFactory.h ../../include/Ice/EndpointFactoryF.h ../Ice/Network.h ../Ice/UdpTransceiver.h ../Ice/TraceLevelsF.h ../../include/Ice/LoggerF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/Ice/StatsF.h ../Ice/Transceiver.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/Buffer.h ../../include/Ice/LocalException.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionIF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/ConnectionF.h ../../include/Ice/Identity.h ../../include/Ice/StreamF.h ../../include/Ice/BuiltinSequences.h ../Ice/Instance.h ../../include/IceUtil/RecMutex.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../Ice/DefaultsAndOverridesF.h ../Ice/RouterInfoF.h ../Ice/LocatorInfoF.h ../Ice/ReferenceFactoryF.h ../Ice/ThreadPoolF.h ../../include/Ice/ConnectionFactoryF.h ../../include/Ice/ConnectionMonitorF.h ../Ice/ObjectFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../Ice/EndpointFactoryManagerF.h ../../include/Ice/DynamicLibraryF.h ../../include/Ice/PluginF.h ../Ice/DefaultsAndOverrides.h ../Ice/Protocol.h +UdpTransceiver.o: UdpTransceiver.cpp ../Ice/UdpTransceiver.h ../../include/Ice/InstanceF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../Ice/TraceLevelsF.h ../../include/Ice/LoggerF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StatsF.h ../Ice/Transceiver.h ../Ice/TransceiverF.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../Ice/Instance.h ../../include/IceUtil/RecMutex.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../Ice/DefaultsAndOverridesF.h ../Ice/RouterInfoF.h ../Ice/LocatorInfoF.h ../Ice/ReferenceFactoryF.h ../../include/Ice/ProxyFactoryF.h ../Ice/ThreadPoolF.h ../../include/Ice/ConnectionFactoryF.h ../../include/Ice/ConnectionMonitorF.h ../Ice/ObjectFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../Ice/EndpointFactoryManagerF.h ../../include/Ice/DynamicLibraryF.h ../../include/Ice/PluginF.h ../Ice/TraceLevels.h ../../include/Ice/LoggerUtil.h ../../include/Ice/Stats.h ../../include/Ice/Buffer.h ../Ice/Network.h ../../include/Ice/LocalException.h ../../include/Ice/Proxy.h ../../include/Ice/ConnectionIF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/OutgoingAsyncF.h ../../include/Ice/Current.h ../../include/Ice/ConnectionF.h ../../include/Ice/Identity.h ../../include/Ice/StreamF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Properties.h UnknownEndpoint.o: UnknownEndpoint.cpp ../Ice/UnknownEndpoint.h ../Ice/Endpoint.h ../../include/IceUtil/Shared.h ../../include/IceUtil/Config.h ../../include/Ice/EndpointF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Ice/Config.h ../../include/Ice/InstanceF.h ../Ice/TransceiverF.h ../Ice/ConnectorF.h ../Ice/AcceptorF.h ../../include/Ice/EndpointFactory.h ../../include/Ice/EndpointFactoryF.h ../../include/Ice/BasicStream.h ../../include/Ice/ObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalObject.h ../../include/Ice/Buffer.h ../Ice/Instance.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/IceUtil/ThreadException.h ../../include/IceUtil/RecMutex.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../../include/Ice/LoggerF.h ../../include/Ice/StatsF.h ../Ice/TraceLevelsF.h ../Ice/DefaultsAndOverridesF.h ../Ice/RouterInfoF.h ../Ice/LocatorInfoF.h ../Ice/ReferenceFactoryF.h ../../include/Ice/ProxyFactoryF.h ../Ice/ThreadPoolF.h ../../include/Ice/ConnectionFactoryF.h ../../include/Ice/ConnectionMonitorF.h ../Ice/ObjectFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../Ice/EndpointFactoryManagerF.h ../../include/Ice/DynamicLibraryF.h ../../include/Ice/PluginF.h BuiltinSequences.cpp: ../../slice/Ice/BuiltinSequences.ice CommunicatorF.cpp: ../../slice/Ice/CommunicatorF.ice -Communicator.cpp: ../../slice/Ice/Communicator.ice ../../slice/Ice/LoggerF.ice ../../slice/Ice/StatsF.ice ../../slice/Ice/ObjectAdapterF.ice ../../slice/Ice/PropertiesF.ice ../../slice/Ice/ObjectFactoryF.ice ../../slice/Ice/RouterF.ice ../../slice/Ice/LocatorF.ice ../../slice/Ice/PluginF.ice +Communicator.cpp: ../../slice/Ice/Communicator.ice ../../slice/Ice/LoggerF.ice ../../slice/Ice/StatsF.ice ../../slice/Ice/ObjectAdapterF.ice ../../slice/Ice/PropertiesF.ice ../../slice/Ice/ObjectFactoryF.ice ../../slice/Ice/RouterF.ice ../../slice/Ice/LocatorF.ice ../../slice/Ice/PluginF.ice ../../slice/Ice/Current.ice ../../slice/Ice/ConnectionF.ice ../../slice/Ice/Identity.ice ConnectionF.cpp: ../../slice/Ice/ConnectionF.ice Connection.cpp: ../../slice/Ice/Connection.ice ../../slice/Ice/Identity.ice Current.cpp: ../../slice/Ice/Current.ice ../../slice/Ice/ObjectAdapterF.ice ../../slice/Ice/ConnectionF.ice ../../slice/Ice/Identity.ice diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp index 8c9581061f2..c7018787e20 100644 --- a/cpp/src/IcePatch2/Client.cpp +++ b/cpp/src/IcePatch2/Client.cpp @@ -303,7 +303,7 @@ Client::usage(const string& appName) "-v, --version Display the Ice version.\n" "-t, --thorough Recalculate all checksums."; - cerr << "Usage: " << appName << " [options] [DIR]" << endl; + cerr << "Usage: " << appName << " [options] DIR" << endl; cerr << options << endl; } diff --git a/cpp/src/IcePatch2/Server.cpp b/cpp/src/IcePatch2/Server.cpp index 7f30e1169d5..013f66c0c11 100644 --- a/cpp/src/IcePatch2/Server.cpp +++ b/cpp/src/IcePatch2/Server.cpp @@ -16,6 +16,9 @@ # include <direct.h> #endif +#include <sys/types.h> +#include <sys/stat.h> + using namespace std; using namespace Ice; using namespace IcePatch2; @@ -122,28 +125,16 @@ IcePatch2::PatcherService::start(int argc, char* argv[]) } } + if(!isDir(dataDir)) + { + throw "`" + dataDir + "' is not a directory"; + } + FileInfoSeq infoSeq; try { -#ifdef _WIN32 - if(dataDir[0] != '/' && !(dataDir.size() > 1 && isalpha(dataDir[0]) && dataDir[1] == ':')) - { - char cwd[_MAX_PATH]; - if(_getcwd(cwd, _MAX_PATH) == NULL) -#else - if(dataDir[0] != '/') - { - char cwd[PATH_MAX]; - if(getcwd(cwd, PATH_MAX) == NULL) -#endif - { - throw "cannot get the current directory:\n" + lastError(); - } - - dataDir = string(cwd) + '/' + dataDir; - } - + dataDir = normalize(dataDir); loadFileInfoSeq(dataDir, infoSeq); } catch(const string& ex) @@ -243,7 +234,7 @@ IcePatch2::PatcherService::usage(const string& appName) "--nochdir Do not change the current working directory." ); #endif - cerr << "Usage: " << appName << " [options] [DIR]" << endl; + cerr << "Usage: " << appName << " [options] DIR" << endl; cerr << options << endl; } diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp index 0bf6c71106c..5f2f92b5e14 100644 --- a/cpp/src/IcePatch2/Util.cpp +++ b/cpp/src/IcePatch2/Util.cpp @@ -210,10 +210,56 @@ IcePatch2::stringToBytes(const string& str) return bytes; } +bool +IcePatch2::isDir(const string& path) +{ + struct stat buf; + if(stat(path.c_str(), &buf) == -1) + { + throw "cannot stat `" + path + "':\n" + lastError(); + } + return S_ISDIR(buf.st_mode); +} + string IcePatch2::normalize(const string& path) { - string result = path; + assert(!path.empty()); + + static IceUtil::StaticMutex mutex = ICE_STATIC_MUTEX_INITIALIZER; + +#ifdef _WIN32 + static char cwd[_MAX_PATH]; +#else + static char cwd[PATH_MAX]; +#endif + + { + IceUtil::StaticMutex::Lock sync(mutex); + + if(*cwd == '\0') + { +#ifdef _WIN32 + if(_getcwd(cwd, _MAX_PATH) == NULL) +#else + if(getcwd(cwd, PATH_MAX) == NULL) +#endif + { + throw "cannot get the current directory:\n" + lastError(); + } + } + } + + string result; +#ifdef _WIN32 + if(path[0] != '/' && path[0] != '\\' && !(path.size() > 1 && isalpha(path[0]) && path[1] == ':')) +#else + if(path[0] != '/') +#endif + { + result = cwd + '/'; + } + result += path; string::size_type pos; @@ -236,23 +282,41 @@ IcePatch2::normalize(const string& path) pos = 0; while((pos = result.find("/./", pos)) != string::npos) { - result.erase(pos, 2); + result.erase(pos, 2); // Remove redundant current directory components. } + if(result.size() > 1 && result[result.size() - 1] == '/') + { + result.erase(result.size() - 1, 1); + } + + while(result.size() > 2 && result.substr(0, 2) == "./") + { + result.erase(0, 2); + } + + + if(result.substr(0, 2) == "./") { result.erase(0, 2); } - if(result.size() >= 2 && result.substr(result.size() - 2, 2) == "/.") + if(result == "/.") + { + return "/"; + } + + while(result.size() > 2 && result.substr(result.size() - 2, 2) == "/.") { result.erase(result.size() - 2, 2); } - if(result.size() >= 1 && result[result.size() - 1] == '/') + if(result.size() > 1 && result[result.size() - 1] == '/') { result.erase(result.size() - 1); } + cerr << "normalize: returning " << result << endl; return result; } @@ -261,32 +325,20 @@ string IcePatch2::getSuffix(const string& pa) { const string path = normalize(pa); - - string::size_type pos = path.rfind('.'); - if(pos == string::npos) - { - return string(); - } - else - { - return path.substr(pos + 1); - } + string::size_type slashPos = path.rfind('/'); + slashPos = slashPos == string::npos ? 0 : slashPos + 1; + string::size_type dotPos = path.find('.', slashPos); + return dotPos == string::npos ? string() : path.substr(dotPos + 1); } string IcePatch2::getWithoutSuffix(const string& pa) { const string path = normalize(pa); - - string::size_type pos = path.rfind('.'); - if(pos == string::npos) - { - return path; - } - else - { - return path.substr(0, pos); - } + string::size_type slashPos = path.rfind('/'); + slashPos = slashPos == string::npos ? 0 : slashPos + 1; + string::size_type dotPos = path.rfind('.', slashPos); + return dotPos == string::npos ? path : path.substr(0, dotPos); } bool @@ -302,32 +354,24 @@ string IcePatch2::getBasename(const string& pa) { const string path = normalize(pa); - - string::size_type pos = path.rfind('/'); - if(pos == string::npos) + if(path == "/") { return path; } - else - { - return path.substr(pos + 1); - } + string::size_type slashPos = path.rfind('/'); + return slashPos == string::npos ? path : path.substr(slashPos + 1); } string IcePatch2::getDirname(const string& pa) { const string path = normalize(pa); - - string::size_type pos = path.rfind('/'); - if(pos == string::npos) + if(path == "/") { - return string(); - } - else - { - return path.substr(0, pos); + return path; } + string::size_type slashPos = path.rfind('/'); + return slashPos == string::npos ? string() : path.substr(0, slashPos); } void |