summaryrefslogtreecommitdiff
path: root/cpp/src/IcePatch/Client.cpp
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2002-09-04 20:51:23 +0000
committerMarc Laukien <marc@zeroc.com>2002-09-04 20:51:23 +0000
commit9cc88d3f25857badfa73b48f247645ab2e39e3cf (patch)
tree122091da737ef05ba0cd78e369e0d1cc067f9f4a /cpp/src/IcePatch/Client.cpp
parentFix (diff)
downloadice-9cc88d3f25857badfa73b48f247645ab2e39e3cf.tar.bz2
ice-9cc88d3f25857badfa73b48f247645ab2e39e3cf.tar.xz
ice-9cc88d3f25857badfa73b48f247645ab2e39e3cf.zip
more IcePatch work
Diffstat (limited to 'cpp/src/IcePatch/Client.cpp')
-rw-r--r--cpp/src/IcePatch/Client.cpp182
1 files changed, 128 insertions, 54 deletions
diff --git a/cpp/src/IcePatch/Client.cpp b/cpp/src/IcePatch/Client.cpp
index a24bc493012..3d42e8378b3 100644
--- a/cpp/src/IcePatch/Client.cpp
+++ b/cpp/src/IcePatch/Client.cpp
@@ -11,6 +11,7 @@
#include <Ice/Application.h>
#include <IcePatch/FileDescFactory.h>
#include <IcePatch/Util.h>
+#include <IcePatch/ClientUtil.h>
#include <Glacier/Glacier.h>
#include <IceUtil/Base64.h>
#include <IceSSL/Plugin.h>
@@ -33,8 +34,11 @@ public:
void usage();
virtual int run(int, char*[]);
- static string pathToName(const string&);
- static void patch(const FileDescSeq&, const string&);
+private:
+
+ void patch(const DirectoryDescPtr&, const string&) const;
+
+ bool _remove;
};
};
@@ -191,13 +195,52 @@ IcePatch::Client::run(int argc, char* argv[])
}
}
+ //
+ // Check whether we have to patch at all.
+ //
+ Identity infoIdentity = pathToIdentity(".icepatch");
+ ObjectPrx infoObj = communicator()->stringToProxy(identityToString(infoIdentity) + ':' + endpoints);
+ InfoPrx info = InfoPrx::checkedCast(infoObj);
+ assert(info);
+ Long remoteStamp = info->getStamp();
+ Long localStamp = readStamp();
+ if(remoteStamp != localStamp)
+ {
+ localStamp = remoteStamp;
+ writeStamp(localStamp);
+ }
+ else if(!(properties->getPropertyAsInt("IcePatch.PatchAlways") > 0))
+ {
+ cout << "You are up-to-date. No patching is necessary." << endl;
+ return EXIT_SUCCESS;
+ }
+
+ //
+ // Check whether we want to remove orphaned files.
+ //
+ _remove = properties->getPropertyAsInt("IcePatch.RemoveOrphaned") > 0;
+ if(_remove)
+ {
+ char cwd[PATH_MAX];
+ getcwd(cwd, PATH_MAX);
+ cout << "WARNING: All orphaned files in `" << cwd << "' will be removed." << endl;
+ cout << "Do you want to proceed? (yes/no)" << endl;
+ string answer;
+ cin >> answer;
+ transform(answer.begin(), answer.end(), answer.begin(), tolower);
+ if(answer != "yes")
+ {
+ return EXIT_SUCCESS;
+ }
+ }
+
//
// Create and install the node description factory.
//
ObjectFactoryPtr factory = new FileDescFactory;
communicator()->addObjectFactory(factory, "::IcePatch::DirectoryDesc");
communicator()->addObjectFactory(factory, "::IcePatch::RegularDesc");
-
+
//
// Patch all subdirectories.
//
@@ -205,20 +248,30 @@ IcePatch::Client::run(int argc, char* argv[])
{
Identity identity = pathToIdentity(*p);
ObjectPrx topObj = communicator()->stringToProxy(identityToString(identity) + ':' + endpoints);
+
FilePrx top = FilePrx::checkedCast(topObj);
- assert(top);
+ if(!top)
+ {
+ cerr << appName() << ": `" << *p << "' does not exist" << endl;
+ return EXIT_FAILURE;
+ }
+
DirectoryDescPtr topDesc = DirectoryDescPtr::dynamicCast(top->describe());
- assert(topDesc);
- string path = identityToPath(topDesc->directory->ice_getIdentity());
+ if(!topDesc)
+ {
+ cerr << appName() << ": `" << *p << "' is not a directory" << endl;
+ return EXIT_FAILURE;
+ }
+
string::size_type pos = 0;
- while(pos < path.size())
+ while(pos < p->size())
{
- string::size_type pos2 = path.find('/', pos);
+ string::size_type pos2 = p->find('/', pos);
if(pos2 == string::npos)
{
- pos2 = path.size();
+ pos2 = p->size();
}
- string subPath = path.substr(0, pos2);
+ string subPath = p->substr(0, pos2);
FileInfo subPathInfo = getFileInfo(subPath, false);
if(subPathInfo.type == FileTypeNotExist)
{
@@ -227,9 +280,11 @@ IcePatch::Client::run(int argc, char* argv[])
}
pos = pos2 + 1;
}
- cout << pathToName(path) << endl;
+
+ cout << pathToName(*p) << endl;
cout << "|" << endl;
- patch(topDesc->directory->getContents(), "");
+
+ patch(topDesc, "");
}
}
catch(const FileAccessException& ex)
@@ -270,20 +325,6 @@ IcePatch::Client::run(int argc, char* argv[])
return EXIT_SUCCESS;
}
-string
-IcePatch::Client::pathToName(const string& path)
-{
- string::size_type pos = path.rfind('/');
- if(pos == string::npos)
- {
- return path;
- }
- else
- {
- return path.substr(pos + 1);
- }
-}
-
class MyProgressCB : public ProgressCB
{
public:
@@ -325,37 +366,49 @@ public:
};
void
-IcePatch::Client::patch(const FileDescSeq& fileDescSeq, const string& indent)
+IcePatch::Client::patch(const DirectoryDescPtr& dirDesc, const string& indent) const
{
+ FileDescSeq fileDescSeq = dirDesc->directory->getContents();
+
+ StringSeq orphaned;
+ if(_remove)
+ {
+ StringSeq fullDirectoryListing = readDirectory(identityToPath(dirDesc->directory->ice_getIdentity()));
+ orphaned.reserve(fullDirectoryListing);
+ for(StringSeq::const_iterator p = fullDirectoryListing.begin(); p != fullDirectoryListing.end(); ++p)
+ {
+ if(*p != ".icepatch" && getSuffix(*p) != "md5")
+ {
+ orphaned.push_back(*p);
+ }
+ }
+ }
+
for(unsigned int i = 0; i < fileDescSeq.size(); ++i)
{
string path;
- DirectoryDescPtr directoryDesc = DirectoryDescPtr::dynamicCast(fileDescSeq[i]);
- RegularDescPtr regularDesc;
- if(directoryDesc)
+ DirectoryDescPtr subDirDesc = DirectoryDescPtr::dynamicCast(fileDescSeq[i]);
+ RegularDescPtr regDesc;
+ if(subDirDesc)
{
- path = identityToPath(directoryDesc->directory->ice_getIdentity());
+ path = identityToPath(subDirDesc->directory->ice_getIdentity());
}
else
{
- regularDesc = RegularDescPtr::dynamicCast(fileDescSeq[i]);
- assert(regularDesc);
- path = identityToPath(regularDesc->regular->ice_getIdentity());
+ regDesc = RegularDescPtr::dynamicCast(fileDescSeq[i]);
+ assert(regDesc);
+ path = identityToPath(regDesc->regular->ice_getIdentity());
+ }
+
+ if(_remove)
+ {
+ orphaned.erase(remove(orphaned.begin(), orphaned.end(), path), orphaned.end());
}
- bool last = (i == fileDescSeq.size() - 1);
+ bool last = (i == fileDescSeq.size() - 1) && orphaned.empty();
- if(directoryDesc)
+ if(subDirDesc)
{
- string newIndent;
- if(last)
- {
- newIndent = indent + " ";
- }
- else
- {
- newIndent = indent + "| ";
- }
cout << indent << "+-" << pathToName(path) << ":";
FileInfo info = getFileInfo(path, false);
@@ -383,12 +436,21 @@ IcePatch::Client::patch(const FileDescSeq& fileDescSeq, const string& indent)
}
}
- cout << newIndent << "|" << endl;
- patch(directoryDesc->directory->getContents(), newIndent);
+ string newIndent;
+ if(last)
+ {
+ newIndent = indent + " ";
+ }
+ else
+ {
+ newIndent = indent + "| ";
+ }
+
+ patch(subDirDesc, newIndent);
}
else
{
- assert(regularDesc);
+ assert(regDesc);
cout << indent << "+-" << pathToName(path) << ":";
MyProgressCB progressCB;
@@ -398,14 +460,14 @@ IcePatch::Client::patch(const FileDescSeq& fileDescSeq, const string& indent)
{
case FileTypeNotExist:
{
- getRegular(regularDesc->regular, progressCB);
+ getRegular(regDesc->regular, progressCB);
break;
}
case FileTypeDirectory:
{
removeRecursive(path);
- getRegular(regularDesc->regular, progressCB);
+ getRegular(regDesc->regular, progressCB);
break;
}
@@ -420,10 +482,10 @@ IcePatch::Client::patch(const FileDescSeq& fileDescSeq, const string& indent)
md5 = getMD5(path);
}
- if(md5 != regularDesc->md5)
+ if(md5 != regDesc->md5)
{
removeRecursive(path);
- getRegular(regularDesc->regular, progressCB);
+ getRegular(regDesc->regular, progressCB);
}
else
{
@@ -433,10 +495,22 @@ IcePatch::Client::patch(const FileDescSeq& fileDescSeq, const string& indent)
break;
}
}
+ }
+ }
- if(last)
+ if(!orphaned.empty())
+ {
+ for(StringSeq::const_iterator p = orphaned.begin(); p != orphaned.end(); ++p)
+ {
+ cout << indent << "+-" << pathToName(*p) << ": removing orphaned file" << endl;
+ removeRecursive(*p);
+ try
+ {
+ removeRecursive(*p + ".md5");
+ }
+ catch(const FileAccessException&);
{
- cout << indent << endl;
+ // Ignore, the MD5 file might not exist.
}
}
}