diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/slice/IcePatch/Node.ice | 1 | ||||
-rw-r--r-- | cpp/src/IcePatch/.depend | 5 | ||||
-rw-r--r-- | cpp/src/IcePatch/Client.cpp | 42 | ||||
-rw-r--r-- | cpp/src/IcePatch/Makefile | 3 | ||||
-rw-r--r-- | cpp/src/IcePatch/NodeI.cpp | 38 | ||||
-rw-r--r-- | cpp/src/IcePatch/NodeUtil.cpp | 250 | ||||
-rw-r--r-- | cpp/src/IcePatch/NodeUtil.h | 25 |
7 files changed, 340 insertions, 24 deletions
diff --git a/cpp/slice/IcePatch/Node.ice b/cpp/slice/IcePatch/Node.ice index e1e4e6be590..3fc7e124b05 100644 --- a/cpp/slice/IcePatch/Node.ice +++ b/cpp/slice/IcePatch/Node.ice @@ -53,6 +53,7 @@ interface File extends Node class FileDesc extends NodeDesc { File* file; + Ice::ByteSeq md5; }; }; diff --git a/cpp/src/IcePatch/.depend b/cpp/src/IcePatch/.depend index ab4c45857e2..b7d05a268e6 100644 --- a/cpp/src/IcePatch/.depend +++ b/cpp/src/IcePatch/.depend @@ -1,6 +1,7 @@ Node.o: Node.cpp ../../include/Ice/Stream.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/BuiltinSequences.h ../../include/IcePatch/Node.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ObjectFactory.h -Client.o: Client.cpp ../../include/Ice/Application.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../IcePatch/NodeDescFactory.h ../../include/IcePatch/Node.h +NodeUtil.o: NodeUtil.cpp ../IcePatch/NodeUtil.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/Node.h +Client.o: Client.cpp ../../include/Ice/Application.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../IcePatch/NodeDescFactory.h ../../include/IcePatch/Node.h ../IcePatch/NodeUtil.h NodeDescFactory.o: NodeDescFactory.cpp ../IcePatch/NodeDescFactory.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/Node.h Server.o: Server.cpp ../../include/Ice/Application.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../IcePatch/NodeLocator.h ../IcePatch/NodeI.h ../../include/IcePatch/Node.h -NodeI.o: NodeI.cpp ../IcePatch/NodeI.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/Node.h +NodeI.o: NodeI.cpp ../IcePatch/NodeI.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/Node.h ../IcePatch/NodeUtil.h NodeLocator.o: NodeLocator.cpp ../IcePatch/NodeLocator.h ../IcePatch/NodeI.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/Node.h diff --git a/cpp/src/IcePatch/Client.cpp b/cpp/src/IcePatch/Client.cpp index 79480906f34..4af72481f07 100644 --- a/cpp/src/IcePatch/Client.cpp +++ b/cpp/src/IcePatch/Client.cpp @@ -10,6 +10,7 @@ #include <Ice/Application.h> #include <IcePatch/NodeDescFactory.h> +#include <IcePatch/NodeUtil.h> using namespace std; using namespace Ice; @@ -98,12 +99,20 @@ IcePatch::Client::run(int argc, char* argv[]) communicator()->addObjectFactory(factory, "::IcePatch::DirectoryDesc"); communicator()->addObjectFactory(factory, "::IcePatch::FileDesc"); - // - // Display node structure. - // - ObjectPrx topObj = communicator()->stringToProxy("IcePatch/.:" + endpoints); - NodePrx top = NodePrx::checkedCast(topObj); - printNodeDesc(top->describe()); + try + { + // + // Display node structure. + // + ObjectPrx topObj = communicator()->stringToProxy("IcePatch/.:" + endpoints); + NodePrx top = NodePrx::checkedCast(topObj); + printNodeDesc(top->describe()); + } + catch (const NodeAccessException& ex) + { + cerr << ex << ":\n" << ex.reason << endl; + return EXIT_FAILURE; + } return EXIT_SUCCESS; } @@ -113,13 +122,14 @@ IcePatch::Client::printNodeDesc(const NodeDescPtr& nodeDesc) { string name; DirectoryDescPtr directoryDesc = DirectoryDescPtr::dynamicCast(nodeDesc); + FileDescPtr fileDesc; if (directoryDesc) { name = directoryDesc->directory->ice_getIdentity().name; } else { - FileDescPtr fileDesc = FileDescPtr::dynamicCast(nodeDesc); + fileDesc = FileDescPtr::dynamicCast(nodeDesc); assert(fileDesc); name = fileDesc->file->ice_getIdentity().name; } @@ -134,8 +144,14 @@ IcePatch::Client::printNodeDesc(const NodeDescPtr& nodeDesc) if (directoryDesc) { + cout << endl; printNodeDescSeq(directoryDesc->directory->getContents(), ""); } + else + { + assert(fileDesc); + cout << " (" << MD5ToString(fileDesc->md5) << ')' << endl; + } } void @@ -152,13 +168,14 @@ IcePatch::Client::printNodeDescSeq(const NodeDescSeq& nodeDescSeq, const string& { string name; DirectoryDescPtr directoryDesc = DirectoryDescPtr::dynamicCast(nodeDescSeq[i]); + FileDescPtr fileDesc; if (directoryDesc) { name = directoryDesc->directory->ice_getIdentity().name; } else { - FileDescPtr fileDesc = FileDescPtr::dynamicCast(nodeDescSeq[i]); + fileDesc = FileDescPtr::dynamicCast(nodeDescSeq[i]); assert(fileDesc); name = fileDesc->file->ice_getIdentity().name; } @@ -169,10 +186,12 @@ IcePatch::Client::printNodeDescSeq(const NodeDescSeq& nodeDescSeq, const string& name.erase(0, pos + 1); } - cout << indent << "+-" << name << endl; + cout << indent << "+-" << name; if (directoryDesc) { + cout << endl; + string newIndent; if (i < nodeDescSeq.size() - 1) { @@ -185,6 +204,11 @@ IcePatch::Client::printNodeDescSeq(const NodeDescSeq& nodeDescSeq, const string& printNodeDescSeq(directoryDesc->directory->getContents(), newIndent); } + else + { + assert(fileDesc); + cout << " (" << MD5ToString(fileDesc->md5) << ')' << endl; + } } cout << indent << " " << endl; diff --git a/cpp/src/IcePatch/Makefile b/cpp/src/IcePatch/Makefile index f8ad9be4ad5..1f377f7c427 100644 --- a/cpp/src/IcePatch/Makefile +++ b/cpp/src/IcePatch/Makefile @@ -15,7 +15,8 @@ SERVER = $(top_srcdir)/bin/icepatch TARGETS = $(CLIENT) $(SERVER) -OBJS = Node.o +OBJS = Node.o \ + NodeUtil.o COBJS = Client.o \ NodeDescFactory.o diff --git a/cpp/src/IcePatch/NodeI.cpp b/cpp/src/IcePatch/NodeI.cpp index e5b39645ed4..d0c8635b456 100644 --- a/cpp/src/IcePatch/NodeI.cpp +++ b/cpp/src/IcePatch/NodeI.cpp @@ -9,6 +9,7 @@ // ********************************************************************** #include <IcePatch/NodeI.h> +#include <IcePatch/NodeUtil.h> #include <dirent.h> using namespace std; @@ -91,22 +92,33 @@ IcePatch::DirectoryI::getContents(const Ice::Current& current) { string name = namelist[i]->d_name; - if (name != ".." && name != ".") + if (name == ".." || name == ".") { - identity.name = path + '/' + name; - NodePrx node = NodePrx::uncheckedCast(_adapter->createProxy(identity)); - try - { - result.push_back(node->describe()); - } - catch (const ObjectNotExistException&) + continue; + } + + string::size_type pos; + if ((pos = name.rfind(".md5")) != string::npos) + { + if (name.size() == pos + 4) { - // - // Ignore. This can for example happen if the node - // locator cannot call stat() on the file. - // + continue; } } + + identity.name = path + '/' + name; + NodePrx node = NodePrx::uncheckedCast(_adapter->createProxy(identity)); + try + { + result.push_back(node->describe()); + } + catch (const ObjectNotExistException&) + { + // + // Ignore. This can for example happen if the node + // locator cannot call stat() on the file. + // + } } for (i = 0; i < n; ++i) @@ -140,6 +152,8 @@ IcePatch::FileI::describe(const Ice::Current& current) { FileDescPtr desc = new FileDesc; desc->file = FilePrx::uncheckedCast(_adapter->createProxy(current.identity)); + string path = normalizePath(current.identity.name); + desc->md5 = getMD5(path); return desc; } diff --git a/cpp/src/IcePatch/NodeUtil.cpp b/cpp/src/IcePatch/NodeUtil.cpp new file mode 100644 index 00000000000..046f98c1afb --- /dev/null +++ b/cpp/src/IcePatch/NodeUtil.cpp @@ -0,0 +1,250 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <IcePatch/NodeUtil.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <fcntl.h> +#include <openssl/md5.h> + +using namespace std; +using namespace Ice; +using namespace IcePatch; + +ByteSeq +IcePatch::getMD5(const std::string& path) +{ + // + // Stat the file to get a MD5 hash value for. + // + struct stat buf; + if (stat(path.c_str(), &buf) == -1) + { + NodeAccessException ex; + ex.reason = "cannot stat `" + path + "':" + strerror(errno); + throw ex; + } + else + { + if (!S_ISREG(buf.st_mode)) + { + NodeAccessException ex; + ex.reason = "`" + path + "' is not a regular file"; + throw ex; + } + } + + // + // Stat the .md5 file. If it doesn't exist, or if it's outdated, + // set a flag to create a new MD5 hash value. + // + struct stat bufmd5; + string pathmd5 = path + ".md5"; + unsigned char md5[16]; + bool createmd5 = false; + if (stat(pathmd5.c_str(), &bufmd5) == -1) + { + if (errno == ENOENT) + { + createmd5 = true; + } + else + { + NodeAccessException ex; + ex.reason = "cannot stat `" + path + "':" + strerror(errno); + throw ex; + } + } + else + { + if (!S_ISREG(bufmd5.st_mode)) + { + NodeAccessException ex; + ex.reason = "`" + path + "' is not a regular file"; + throw ex; + } + + if (bufmd5.st_size != 16) + { + NodeAccessException ex; + ex.reason = "`" + path + "' isn't 16 bytes in size"; + throw ex; + } + + if (bufmd5.st_mtime <= buf.st_mtime) + { + createmd5 = true; + } + } + + if (createmd5) + { + // + // Open the original file and create a MD5 hash value + // + { + int fd = open(path.c_str(), O_RDONLY); + + if (fd == -1) + { + NodeAccessException ex; + ex.reason = "cannot open `" + path + "' for reading:" + strerror(errno); + throw ex; + } + + unsigned char* fileBuf = new unsigned char[buf.st_size]; + + try + { + int sz = read(fd, fileBuf, buf.st_size); + + if (sz == -1) + { + NodeAccessException ex; + ex.reason = "cannot read `" + path + "':" + strerror(errno); + throw ex; + } + + if (sz < buf.st_size) + { + NodeAccessException ex; + ex.reason = "could not read all bytes from `" + path + "'"; + throw ex; + } + + MD5(fileBuf, sz, md5); + + close(fd); + delete [] fileBuf; + } + catch (...) + { + close(fd); + delete [] fileBuf; + throw; + } + } + + // + // Write the MD5 hash value to the corresponding .md5 file. + // + { + int fd = open(pathmd5.c_str(), O_WRONLY | O_CREAT); + + if (fd == -1) + { + NodeAccessException ex; + ex.reason = "cannot open `" + pathmd5 + "' for writing:" + strerror(errno); + throw ex; + } + + try + { + int sz = write(fd, md5, 16); + + if (sz == -1) + { + NodeAccessException ex; + ex.reason = "cannot read `" + path + "':" + strerror(errno); + throw ex; + } + + if (sz < 16) + { + NodeAccessException ex; + ex.reason = "could not write 16 bytes to `" + path + "'"; + throw ex; + } + + close(fd); + } + catch (...) + { + close(fd); + throw; + } + } + } + else + { + // + // Read the MD5 hash value from the .md5 file. + // + int fd = open(pathmd5.c_str(), O_RDONLY); + + if (fd == -1) + { + NodeAccessException ex; + ex.reason = "cannot open `" + path + "' for reading:" + strerror(errno); + throw ex; + } + + try + { + int sz = read(fd, md5, 16); + + if (sz == -1) + { + NodeAccessException ex; + ex.reason = "cannot read `" + path + "':" + strerror(errno); + throw ex; + } + + if (sz < 16) + { + NodeAccessException ex; + ex.reason = "could not read 16 bytes from `" + path + "'"; + throw ex; + } + + close(fd); + } + catch (...) + { + close(fd); + throw; + } + } + + // + // Convert array to byte sequence. + // + ByteSeq result; + result.resize(16); + for (int i = 0; i < 16; ++i) + { + result[i] = md5[i]; + } + return result; +} + +std::string +IcePatch::MD5ToString(const Ice::ByteSeq& md5) +{ + if (md5.size() != 16) + { + return "illegal MD5 hash code"; + } + + ostringstream out; + + for (int i = 0; i < 16; ++i) + { + int b = static_cast<int>(md5[i]); + if (b < 0) + { + b += 256; + } + out << hex << b; + } + + return out.str(); +} diff --git a/cpp/src/IcePatch/NodeUtil.h b/cpp/src/IcePatch/NodeUtil.h new file mode 100644 index 00000000000..f2de80252b2 --- /dev/null +++ b/cpp/src/IcePatch/NodeUtil.h @@ -0,0 +1,25 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef ICE_PATCH_NODE_UTIL_H +#define ICE_PATCH_NODE_UTIL_H + +#include <Ice/Ice.h> +#include <IcePatch/Node.h> + +namespace IcePatch +{ + +Ice::ByteSeq getMD5(const std::string&); +std::string MD5ToString(const Ice::ByteSeq&); + +} + +#endif |