diff options
author | Marc Laukien <marc@zeroc.com> | 2004-11-24 22:42:53 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2004-11-24 22:42:53 +0000 |
commit | 43a041505e6a7d2e36dd0bbe3cf4ac6658b0f3ac (patch) | |
tree | 404249bd9a9cddcf662508d823a063232ed247b5 /cpp/src/IcePatch2/Client.cpp | |
parent | fix (diff) | |
download | ice-43a041505e6a7d2e36dd0bbe3cf4ac6658b0f3ac.tar.bz2 ice-43a041505e6a7d2e36dd0bbe3cf4ac6658b0f3ac.tar.xz ice-43a041505e6a7d2e36dd0bbe3cf4ac6658b0f3ac.zip |
more icepatch2
Diffstat (limited to 'cpp/src/IcePatch2/Client.cpp')
-rw-r--r-- | cpp/src/IcePatch2/Client.cpp | 316 |
1 files changed, 184 insertions, 132 deletions
diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp index c5627a191d2..7b1de496c3b 100644 --- a/cpp/src/IcePatch2/Client.cpp +++ b/cpp/src/IcePatch2/Client.cpp @@ -33,6 +33,26 @@ private: }; +class DecompressorDestroyer +{ +public: + + DecompressorDestroyer(DecompressorPtr decompressor) : + _decompressor(decompressor) + { + } + + ~DecompressorDestroyer() + { + _decompressor->destroy(); + _decompressor->getThreadControl().join(); + } + +private: + + const DecompressorPtr _decompressor; +}; + int IcePatch2::Client::run(int argc, char* argv[]) { @@ -126,7 +146,7 @@ IcePatch2::Client::run(int argc, char* argv[]) { try { - loadFileInfoSeq(dataDir + ".sum", infoSeq); + loadFileInfoSeq(dataDir, infoSeq); } catch(const string& ex) { @@ -146,15 +166,13 @@ IcePatch2::Client::run(int argc, char* argv[]) thorough = true; } } - + if(thorough) { getFileInfoSeq(".", infoSeq, false, false, false); - saveFileInfoSeq(dataDir + ".sum", infoSeq); + saveFileInfoSeq(dataDir, infoSeq); } - sort(infoSeq.begin(), infoSeq.end(), FileInfoCompare()); - const char* endpointsProperty = "IcePatch2.Endpoints"; const string endpoints = properties->getProperty(endpointsProperty); if(endpoints.empty()) @@ -201,21 +219,22 @@ IcePatch2::Client::run(int argc, char* argv[]) { FileInfoSeq fileSeq = fileServer->getFileInfo1Seq(node0); - sort(fileSeq.begin(), fileSeq.end(), FileInfoCompare()); + sort(fileSeq.begin(), fileSeq.end(), FileInfoLess()); + fileSeq.erase(unique(fileSeq.begin(), fileSeq.end(), FileInfoEqual()), fileSeq.end()); set_difference(tree0.nodes[node0].files.begin(), tree0.nodes[node0].files.end(), fileSeq.begin(), fileSeq.end(), back_inserter(removeFiles), - FileInfoCompare()); + FileInfoLess()); set_difference(fileSeq.begin(), fileSeq.end(), tree0.nodes[node0].files.begin(), tree0.nodes[node0].files.end(), back_inserter(updateFiles), - FileInfoCompare()); + FileInfoLess()); } for(unsigned int i = 0; i < progress.size(); ++i) @@ -231,172 +250,210 @@ IcePatch2::Client::run(int argc, char* argv[]) cout << endl; - sort(removeFiles.begin(), removeFiles.end(), FileInfoCompare()); - sort(updateFiles.begin(), updateFiles.end(), FileInfoCompare()); + sort(removeFiles.begin(), removeFiles.end(), FileInfoLess()); + sort(updateFiles.begin(), updateFiles.end(), FileInfoLess()); FileInfoSeq::const_iterator p; - p = removeFiles.begin(); - while(p != removeFiles.end()) + if(!removeFiles.empty()) { - cout << "remove: " << p->path << endl; - - if(!dry) + p = removeFiles.begin(); + while(p != removeFiles.end()) { - try + cout << "remove: " << getBasename(p->path) << endl; + + if(!dry) { - removeRecursive(p->path); + try + { + removeRecursive(p->path); + } + catch(const string&) + { + } } - catch(const string&) + + string dir = p->path + '/'; + + do { + ++p; } + while(p != removeFiles.end() && p->path.size() > dir.size() && + p->path.compare(0, dir.size(), dir) == 0); } - string dir = p->path + '/'; - - do + if(!dry) { - ++p; + FileInfoSeq newInfoSeq; + newInfoSeq.reserve(infoSeq.size()); + + set_difference(infoSeq.begin(), + infoSeq.end(), + removeFiles.begin(), + removeFiles.end(), + back_inserter(newInfoSeq), + FileInfoLess()); + + infoSeq.swap(newInfoSeq); + + saveFileInfoSeq(dataDir, infoSeq); } - while(p != removeFiles.end() && p->path.size() > dir.size() && p->path.compare(0, dir.size(), dir) == 0); } - Long total = 0; - Long updated = 0; - - for(p = updateFiles.begin(); p != updateFiles.end(); ++p) + if(!updateFiles.empty()) { - if(p->size > 0) // Regular, non-empty file? + string pathLog = dataDir + ".log"; + ofstream fileLog; + + if(!dry) { - total += p->size; + fileLog.open(pathLog.c_str()); + if(!fileLog) + { + cerr << argv[0] << ": cannot open `" + pathLog + "' for writing: " + strerror(errno); + return EXIT_FAILURE; + } } - } - - for(p = updateFiles.begin(); p != updateFiles.end(); ++p) - { - cout << "update: " << p->path << ' ' << flush; - - if(p->size < 0) // Directory? + + Long total = 0; + Long updated = 0; + + for(p = updateFiles.begin(); p != updateFiles.end(); ++p) { - if(!dry) + if(p->size > 0) // Regular, non-empty file? { - createDirectoryRecursive(p->path); + total += p->size; } } - else // Regular file. + + DecompressorPtr decompressor = new Decompressor; + DecompressorDestroyer decompressorDestroyer(decompressor); + decompressor->start(); + + for(p = updateFiles.begin(); p != updateFiles.end(); ++p) { - string pathBZ2 = p->path + ".bz2"; - ofstream fileBZ2; + cout << "update: " << getBasename(p->path) << ' ' << flush; - if(!dry) + if(p->size < 0) // Directory? { - string dir = getDirname(pathBZ2); - if(!dir.empty()) + if(!dry) { - createDirectoryRecursive(dir); + createDirectoryRecursive(p->path); + fileLog << *p << endl; } + } + else // Regular file. + { + string pathBZ2 = p->path + ".bz2"; + ofstream fileBZ2; - try - { - removeRecursive(pathBZ2); - } - catch(...) + if(!dry) { - } + string dir = getDirname(pathBZ2); + if(!dir.empty()) + { + createDirectoryRecursive(dir); + } - fileBZ2.open(pathBZ2.c_str(), ios::binary); - if(!fileBZ2) - { - cerr << argv[0] << ": cannot open `" + pathBZ2 + "' for writing: " + strerror(errno); - return EXIT_FAILURE; + try + { + removeRecursive(pathBZ2); + } + catch(...) + { + } + + fileBZ2.open(pathBZ2.c_str(), ios::binary); + if(!fileBZ2) + { + cerr << argv[0] << ": cannot open `" + pathBZ2 + "' for writing: " + strerror(errno); + return EXIT_FAILURE; + } } - } - Int pos = 0; - string progress; + Int pos = 0; + string progress; - while(pos < p->size) - { - ByteSeq bytes; - - try + while(pos < p->size) { - bytes = fileServer->getFileCompressed(p->path, pos, chunk); - } - catch(const FileAccessException& ex) - { - cerr << argv[0] << ": server error for `" << p->path << "':" << ex.reason << endl; - return EXIT_FAILURE; - } + ByteSeq bytes; - if(bytes.empty()) - { - cerr << argv[0] << ": size mismatch for `" << p->path << "'" << endl; - return EXIT_FAILURE; - } - - if(!dry) - { - fileBZ2.write(reinterpret_cast<char*>(&bytes[0]), bytes.size()); + try + { + bytes = fileServer->getFileCompressed(p->path, pos, chunk); + } + catch(const FileAccessException& ex) + { + cerr << argv[0] << ": server error for `" << p->path << "':" << ex.reason << endl; + return EXIT_FAILURE; + } - if(!fileBZ2) + if(bytes.empty()) { - cerr << argv[0] << ": cannot write `" + pathBZ2 + "': " + strerror(errno); + cerr << argv[0] << ": size mismatch for `" << p->path << "'" << endl; return EXIT_FAILURE; } - } - pos += bytes.size(); - updated += bytes.size(); + if(!dry) + { + fileBZ2.write(reinterpret_cast<char*>(&bytes[0]), bytes.size()); - for(unsigned int i = 0; i < progress.size(); ++i) - { - cout << '\b'; + if(!fileBZ2) + { + cerr << argv[0] << ": cannot write `" + pathBZ2 + "': " + strerror(errno); + return EXIT_FAILURE; + } + } + + pos += bytes.size(); + updated += bytes.size(); + + for(unsigned int i = 0; i < progress.size(); ++i) + { + cout << '\b'; + } + ostringstream s; + s << pos << '/' << p->size << " (" << updated << '/' << total << ')'; + progress = s.str(); + cout << progress << flush; } - ostringstream s; - s << pos << '/' << p->size << " (" << updated << '/' << total << ')'; - progress = s.str(); - cout << progress << flush; - } - if(!dry) - { - fileBZ2.close(); - uncompressFile(p->path); - remove(pathBZ2); + if(!dry) + { + fileBZ2.close(); + fileLog << *p << endl; + + decompressor->checkForException(); + decompressor->add(p->path); + } } - } - cout << endl; - } + cout << endl; + } - // - // After a complete and successful patch, we write a new - // summary file. - // - if(!dry) - { - FileInfoSeq newInfoSeq1; - newInfoSeq1.reserve(infoSeq.size()); + decompressor->destroy(); + decompressor->getThreadControl().join(); + decompressor->checkForException(); + + if(!dry) + { + fileLog.close(); + + FileInfoSeq newInfoSeq; + newInfoSeq.reserve(infoSeq.size()); - set_difference(infoSeq.begin(), - infoSeq.end(), - removeFiles.begin(), - removeFiles.end(), - back_inserter(newInfoSeq1), - FileInfoCompare()); - - FileInfoSeq newInfoSeq2; - newInfoSeq2.reserve(newInfoSeq1.size() + updateFiles.size()); - - set_union(newInfoSeq1.begin(), - newInfoSeq1.end(), - updateFiles.begin(), - updateFiles.end(), - back_inserter(newInfoSeq2), - FileInfoCompare()); - - saveFileInfoSeq(dataDir + ".sum", newInfoSeq2); + set_union(infoSeq.begin(), + infoSeq.end(), + updateFiles.begin(), + updateFiles.end(), + back_inserter(newInfoSeq), + FileInfoLess()); + + infoSeq.swap(newInfoSeq); + + saveFileInfoSeq(dataDir, infoSeq); + } } } catch(const string& ex) @@ -404,11 +461,6 @@ IcePatch2::Client::run(int argc, char* argv[]) cerr << argv[0] << ": " << ex << endl; return EXIT_FAILURE; } - catch(const char* ex) - { - cerr << argv[0] << ": " << ex << endl; - return EXIT_FAILURE; - } return EXIT_SUCCESS; } |