summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IcePatch/Client.cpp15
-rw-r--r--cpp/src/IcePatch/Util.cpp48
2 files changed, 58 insertions, 5 deletions
diff --git a/cpp/src/IcePatch/Client.cpp b/cpp/src/IcePatch/Client.cpp
index 1e6cb7c14bb..aa54362f79f 100644
--- a/cpp/src/IcePatch/Client.cpp
+++ b/cpp/src/IcePatch/Client.cpp
@@ -26,7 +26,7 @@ public:
void usage();
virtual int run(int, char*[]);
- void printNodeDescSeq(const NodeDescSeq&, const string&);
+ void patch(const NodeDescSeq&, const string&);
};
};
@@ -98,7 +98,12 @@ IcePatch::Client::run(int argc, char* argv[])
communicator()->addObjectFactory(factory, "::IcePatch::FileDesc");
//
- // Display node structure.
+ // Remove orphaned MD5 and BZ2 files.
+ //
+ removeOrphanedRecursive(".");
+
+ //
+ // Patch all nodes.
//
Identity identity = pathToIdentity(".");
ObjectPrx topObj = communicator()->stringToProxy(identityToString(identity) + ':' + endpoints);
@@ -109,7 +114,7 @@ IcePatch::Client::run(int argc, char* argv[])
string path = identityToPath(topDesc->directory->ice_getIdentity());
cout << pathToName(path) << endl;
cout << "|" << endl;
- printNodeDescSeq(topDesc->directory->getContents(), "");
+ patch(topDesc->directory->getContents(), "");
}
catch (const NodeAccessException& ex)
{
@@ -142,7 +147,7 @@ public:
};
void
-IcePatch::Client::printNodeDescSeq(const NodeDescSeq& nodeDescSeq, const string& indent)
+IcePatch::Client::patch(const NodeDescSeq& nodeDescSeq, const string& indent)
{
if (nodeDescSeq.empty())
{
@@ -217,7 +222,7 @@ IcePatch::Client::printNodeDescSeq(const NodeDescSeq& nodeDescSeq, const string&
cout << "ok" << endl;
cout << newIndent << "|" << endl;
- printNodeDescSeq(directoryDesc->directory->getContents(), newIndent);
+ patch(directoryDesc->directory->getContents(), newIndent);
}
else
{
diff --git a/cpp/src/IcePatch/Util.cpp b/cpp/src/IcePatch/Util.cpp
index 1d11153c11a..0b59e8be821 100644
--- a/cpp/src/IcePatch/Util.cpp
+++ b/cpp/src/IcePatch/Util.cpp
@@ -106,6 +106,20 @@ IcePatch::getSuffix(const string& path)
}
}
+string
+IcePatch::removeSuffix(const string& path)
+{
+ string::size_type pos = path.rfind('.');
+ if (pos == string::npos)
+ {
+ return path;
+ }
+ else
+ {
+ return path.substr(0, pos);
+ }
+}
+
FileInfo
IcePatch::getFileInfo(const string& path)
{
@@ -698,6 +712,40 @@ IcePatch::createBZ2Recursive(const string& path)
}
void
+IcePatch::removeOrphanedRecursive(const string& path)
+{
+ assert(getFileInfo(path) == FileInfoDirectory);
+
+ StringSeq paths = readDirectory(path);
+ StringSeq::const_iterator p;
+ for (p = paths.begin(); p != paths.end(); ++p)
+ {
+ string suffix = getSuffix(*p);
+ if (suffix == ".md5" || suffix == ".bz2")
+ {
+ pair<StringSeq::const_iterator, StringSeq::const_iterator> r =
+ equal_range(paths.begin(), paths.end(), removeSuffix(*p));
+ if (r.first == r.second)
+ {
+ removeRecursive(*p);
+ }
+ }
+ else
+ {
+ if (getFileInfo(*p) == FileInfoDirectory)
+ {
+ removeOrphanedRecursive(*p);
+ }
+ }
+ }
+
+ if (readDirectory(path).empty())
+ {
+ removeRecursive(path);
+ }
+}
+
+void
IcePatch::getFile(const FilePrx& file, ProgressCB& progressCB)
{
string path = identityToPath(file->ice_getIdentity());