diff options
author | Marc Laukien <marc@zeroc.com> | 2004-12-06 21:00:28 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2004-12-06 21:00:28 +0000 |
commit | d0be319d1296891a164b7f62d3917024f43f5399 (patch) | |
tree | 832fc4f21223778a745cfdf124c9969f73377164 /cpp/src | |
parent | fixes (diff) | |
download | ice-d0be319d1296891a164b7f62d3917024f43f5399.tar.bz2 ice-d0be319d1296891a164b7f62d3917024f43f5399.tar.xz ice-d0be319d1296891a164b7f62d3917024f43f5399.zip |
patcher enhancements
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/PropertyNames.cpp | 4 | ||||
-rw-r--r-- | cpp/src/Ice/PropertyNames.h | 2 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Calc.cpp | 55 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Client.cpp | 77 | ||||
-rwxr-xr-x | cpp/src/IcePatch2/ClientUtil.cpp | 71 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Util.cpp | 226 |
6 files changed, 283 insertions, 152 deletions
diff --git a/cpp/src/Ice/PropertyNames.cpp b/cpp/src/Ice/PropertyNames.cpp index 57b49022dcd..a9bfe8f8572 100644 --- a/cpp/src/Ice/PropertyNames.cpp +++ b/cpp/src/Ice/PropertyNames.cpp @@ -7,7 +7,7 @@ // // ********************************************************************** -// Generated by makeprops.py from file `../../config/PropertyNames.def', Mon Nov 29 15:12:16 2004 +// Generated by makeprops.py from file `../config/PropertyNames.def', Mon Dec 6 12:29:15 2004 // IMPORTANT: Do not edit this file -- any edits made here will be lost! @@ -171,9 +171,9 @@ const char* IceInternal::PropertyNames::IcePatch2Props[] = "IcePatch2.Admin.ThreadPool.StackSize", "IcePatch2.ChunkSize", "IcePatch2.Directory", - "IcePatch2.DryRun", "IcePatch2.Endpoints", "IcePatch2.PublishedEndpoints", + "IcePatch2.Remove", "IcePatch2.Thorough", "IcePatch2.ThreadPool.Size", "IcePatch2.ThreadPool.SizeMax", diff --git a/cpp/src/Ice/PropertyNames.h b/cpp/src/Ice/PropertyNames.h index e1d8e52841b..ad96a31770c 100644 --- a/cpp/src/Ice/PropertyNames.h +++ b/cpp/src/Ice/PropertyNames.h @@ -7,7 +7,7 @@ // // ********************************************************************** -// Generated by makeprops.py from file `../../config/PropertyNames.def', Mon Nov 29 15:12:16 2004 +// Generated by makeprops.py from file `../config/PropertyNames.def', Mon Dec 6 12:29:15 2004 // IMPORTANT: Do not edit this file -- any edits made here will be lost! diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp index df8fe85fbe0..7400b3791b0 100644 --- a/cpp/src/IcePatch2/Calc.cpp +++ b/cpp/src/IcePatch2/Calc.cpp @@ -17,6 +17,32 @@ using namespace std; using namespace Ice; using namespace IcePatch2; +class CalcCB : public GetFileInfoSeqCB +{ +public: + + virtual bool + remove(const string& path) + { + cout << "removing: " << path << endl; + return true; + } + + virtual bool + checksum(const string& path) + { + cout << "checksum: " << path << endl; + return true; + } + + virtual bool + compress(const string& path) + { + cout << "compress: " << path << endl; + return true; + } +}; + void usage(const char* appName) { @@ -25,7 +51,8 @@ usage(const char* appName) "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" - "-z, --bzip2 Compress files.\n" + "-z, --compress Always compress files.\n" + "-Z, --no-compress Never compress files.\n" "-V, --verbose Verbose mode.\n" ; } @@ -34,7 +61,7 @@ int main(int argc, char* argv[]) { string dataDir; - bool compress = false; + int mode = 1; bool verbose = false; int i; @@ -50,9 +77,13 @@ main(int argc, char* argv[]) cout << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } - else if(strcmp(argv[i], "-z") == 0 || strcmp(argv[i], "--bzip2") == 0) + else if(strcmp(argv[i], "-z") == 0 || strcmp(argv[i], "--compress") == 0) + { + mode = 2; + } + else if(strcmp(argv[i], "-Z") == 0 || strcmp(argv[i], "--no-compress") == 0) { - compress = true; + mode = 0; } else if(strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--verbose") == 0) { @@ -93,21 +124,33 @@ main(int argc, char* argv[]) { char cwd[_MAX_PATH]; if(_getcwd(cwd, _MAX_PATH) == NULL) +y { + throw "cannot get the current directory:\n" + lastError(); + } + + dataDir = string(cwd) + '/' + dataDir; + } #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; } +#endif FileInfoSeq infoSeq; - getFileInfoSeq(dataDir, infoSeq, true, compress, verbose); + + CalcCB calcCB; + if(!getFileInfoSeq(dataDir, mode, verbose ? &calcCB : 0, infoSeq)) + { + return EXIT_FAILURE; + } + saveFileInfoSeq(dataDir, infoSeq); } catch(const string& ex) diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp index db24c1cc0ea..d36cdb6d8f0 100644 --- a/cpp/src/IcePatch2/Client.cpp +++ b/cpp/src/IcePatch2/Client.cpp @@ -31,6 +31,7 @@ public: #ifndef _WIN32 tcgetattr(0, &_savedTerm); _savedFlags = fcntl(0, F_GETFL); + _block = true; #endif } @@ -58,27 +59,31 @@ public: } } while(answer != "yes"); - cout << "Calculating checksums -- please wait, this might take awhile..." << endl; return true; } virtual bool - fileListStart() + checksumStart() { -#ifndef _WIN32 - termios term; - memcpy(&term, &_savedTerm, sizeof(termios)); - term.c_lflag &= ~(ECHO | ICANON); - term.c_cc[VTIME] = 0; - term.c_cc[VMIN] = 1; - tcsetattr(0, TCSANOW, &term); - - int flags = _savedFlags; - flags |= O_NONBLOCK; - fcntl(0, F_SETFL, flags); -#endif + return !keyPressed(); + } - cout << "[Press any key to abort]" << endl; + virtual bool + checksumProgress(const string& path) + { + cout << "Calculating checksum for " << getBasename(path) << endl; + return !keyPressed(); + } + + virtual bool + checksumEnd() + { + return !keyPressed(); + } + + virtual bool + fileListStart() + { _lastProgress = "0%"; cout << "Getting list of files to patch: " << _lastProgress << flush; return !keyPressed(); @@ -138,32 +143,59 @@ public: private: +#ifdef _WIN32 + bool keyPressed() { bool pressed = false; -#ifdef _WIN32 while(_kbhit()) { pressed = true; _getch(); } + return pressed; + } + #else + + bool + keyPressed() + { + if(_block) + { + termios term; + memcpy(&term, &_savedTerm, sizeof(termios)); + term.c_lflag &= ~(ECHO | ICANON); + term.c_cc[VTIME] = 0; + term.c_cc[VMIN] = 1; + tcsetattr(0, TCSANOW, &term); + + int flags = _savedFlags; + flags |= O_NONBLOCK; + fcntl(0, F_SETFL, flags); + + _block = false; + + cout << "[Press any key to abort]" << endl; + } + + bool pressed = false; char c; while(read(0, &c, 1) > 0) { pressed = true; } -#endif return pressed; } - string _lastProgress; - -#ifndef _WIN32 termios _savedTerm; int _savedFlags; + bool _block; + #endif + + string _lastProgress; }; class Client : public Application @@ -219,11 +251,6 @@ Client::run(int argc, char* argv[]) } } - if(properties->getPropertyAsInt("IcePatch2.Thorough") > 0) - { - cout << "Calculating checksums -- please wait, this might take awhile..." << endl; - } - bool aborted = false; try diff --git a/cpp/src/IcePatch2/ClientUtil.cpp b/cpp/src/IcePatch2/ClientUtil.cpp index d24669c72c8..321f77fd861 100755 --- a/cpp/src/IcePatch2/ClientUtil.cpp +++ b/cpp/src/IcePatch2/ClientUtil.cpp @@ -144,7 +144,8 @@ IcePatch2::Patcher::Patcher(const CommunicatorPtr& communicator, const PatcherFe _feedback(feedback), _dataDir(normalize(communicator->getProperties()->getProperty("IcePatch2.Directory"))), _thorough(communicator->getProperties()->getPropertyAsInt("IcePatch2.Thorough") > 0), - _chunkSize(communicator->getProperties()->getPropertyAsIntWithDefault("IcePatch2.ChunkSize", 100000)) + _chunkSize(communicator->getProperties()->getPropertyAsIntWithDefault("IcePatch2.ChunkSize", 100000)), + _remove(communicator->getProperties()->getPropertyAsIntWithDefault("IcePatch2.Remove", 1)) { if(_dataDir.empty()) { @@ -199,6 +200,38 @@ IcePatch2::Patcher::~Patcher() { } +class PatcherGetFileInfoSeqCB : public GetFileInfoSeqCB +{ +public: + + PatcherGetFileInfoSeqCB(const PatcherFeedbackPtr& feedback) : + _feedback(feedback) + { + } + + virtual bool + remove(const string&) + { + return true; + } + + virtual bool + checksum(const string& path) + { + return _feedback->checksumProgress(path); + } + + virtual bool compress(const string&) + { + assert(false); // Nothing must get compressed when we are patching. + return true; + } + +private: + + const PatcherFeedbackPtr _feedback; +}; + bool IcePatch2::Patcher::prepare() { @@ -224,7 +257,22 @@ IcePatch2::Patcher::prepare() if(thorough) { - getFileInfoSeq(_dataDir, _localFiles, false, false, false); + if(!_feedback->checksumStart()) + { + return false; + } + + PatcherGetFileInfoSeqCB cb(_feedback); + if(!getFileInfoSeq(_dataDir, 0, &cb, _localFiles)) + { + return false; + } + + if(!_feedback->checksumEnd()) + { + return false; + } + saveFileInfoSeq(_dataDir, _localFiles); } @@ -381,10 +429,25 @@ IcePatch2::Patcher::finish() bool IcePatch2::Patcher::removeFiles(const FileInfoSeq& files) { + if(_remove < 1) + { + return true; + } + for(FileInfoSeq::const_reverse_iterator p = files.rbegin(); p != files.rend(); ++p) { - remove(_dataDir + '/' + p->path); - _log << '-' << *p << endl; + try + { + remove(_dataDir + '/' + p->path); + _log << '-' << *p << endl; + } + catch(...) + { + if(_remove < 2) // We ignore errors if IcePatch2.Remove >= 2. + { + throw; + } + } } FileInfoSeq newLocalFiles; diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp index c9bcbaa3a15..ca866606839 100644 --- a/cpp/src/IcePatch2/Util.cpp +++ b/cpp/src/IcePatch2/Util.cpp @@ -652,11 +652,10 @@ IcePatch2::decompressFile(const string& pa) fclose(stdioFileBZ2); } -static void -getFileInfoSeqInternal(const string& basePath, const string& relativePath, FileInfoSeq& infoSeq, - bool size, bool compress, bool verbose) +static bool +getFileInfoSeqInt(const string& basePath, const string& relPath, int mode, GetFileInfoSeqCB* cb, FileInfoSeq& infoSeq) { - const string path = basePath + '/' + relativePath; + const string path = basePath + '/' + relPath; if(ignoreSuffix(path)) { @@ -664,13 +663,12 @@ getFileInfoSeqInternal(const string& basePath, const string& relativePath, FileI if(ignoreSuffix(pathWithoutSuffix)) { - if(verbose) + if(cb && !cb->remove(relPath)) { - cout << path << ": removing " << getSuffix(path) << " file for " - << getSuffix(pathWithoutSuffix) << " file" << endl; + return false; } - remove(path); + remove(path); // Removing file with suffix for another file that already has a suffix. } else { @@ -679,11 +677,12 @@ getFileInfoSeqInternal(const string& basePath, const string& relativePath, FileI { if(errno == ENOENT) { - if(verbose) + if(cb && !cb->remove(relPath)) { - cout << path << ": removing orphaned " << getSuffix(path) << " file" << endl; + return false; } - remove(path); + + remove(path); // Removing orphaned file. } else { @@ -692,152 +691,151 @@ getFileInfoSeqInternal(const string& basePath, const string& relativePath, FileI } else if(buf.st_size == 0) { - if(verbose) + if(cb && !cb->remove(relPath)) { - cout << path << ": removing " << getSuffix(path) << " file for empty file" << endl; + return false; } - remove(path); + + remove(path); // Removing file with suffix for empty file. } } - - return; - } - - struct stat buf; - if(stat(path.c_str(), &buf) == -1) - { - throw "cannot stat `" + path + "':\n" + lastError(); } - - if(S_ISDIR(buf.st_mode)) + else { - FileInfo info; - info.path = relativePath; - info.size = -1; - - ByteSeq bytes(relativePath.size()); - copy(relativePath.begin(), relativePath.end(), bytes.begin()); - - ByteSeq bytesSHA(20); - if(!bytes.empty()) + struct stat buf; + if(stat(path.c_str(), &buf) == -1) { - SHA1(reinterpret_cast<unsigned char*>(&bytes[0]), bytes.size(), - reinterpret_cast<unsigned char*>(&bytesSHA[0])); + throw "cannot stat `" + path + "':\n" + lastError(); } - else + + if(S_ISDIR(buf.st_mode)) { - fill(bytesSHA.begin(), bytesSHA.end(), 0); - } - info.checksum.swap(bytesSHA); + FileInfo info; + info.path = relPath; + info.size = -1; - infoSeq.push_back(info); + ByteSeq bytes(relPath.size()); + copy(relPath.begin(), relPath.end(), bytes.begin()); - StringSeq content = readDirectory(path); - for(StringSeq::const_iterator p = content.begin(); p != content.end() ; ++p) - { - getFileInfoSeqInternal(basePath, normalize(relativePath + '/' + *p), infoSeq, size, compress, verbose); - } - } - else if(S_ISREG(buf.st_mode)) - { - FileInfo info; - info.path = relativePath; - info.size = 0; + ByteSeq bytesSHA(20); + if(!bytes.empty()) + { + SHA1(reinterpret_cast<unsigned char*>(&bytes[0]), bytes.size(), + reinterpret_cast<unsigned char*>(&bytesSHA[0])); + } + else + { + fill(bytesSHA.begin(), bytesSHA.end(), 0); + } + info.checksum.swap(bytesSHA); - ByteSeq bytes(relativePath.size() + buf.st_size); - copy(relativePath.begin(), relativePath.end(), bytes.begin()); + infoSeq.push_back(info); - if(buf.st_size != 0) - { - if(verbose) + StringSeq content = readDirectory(path); + for(StringSeq::const_iterator p = content.begin(); p != content.end() ; ++p) { - if(compress) + if(!getFileInfoSeqInt(basePath, normalize(relPath + '/' + *p), mode, cb, infoSeq)) { - cout << path << ": calculating checksum and compressing file" << endl; - } - else - { - cout << path << ": calculating checksum" << endl; + return false; } } + } + else if(S_ISREG(buf.st_mode)) + { + FileInfo info; + info.path = relPath; + info.size = 0; + + ByteSeq bytes(relPath.size() + buf.st_size); + copy(relPath.begin(), relPath.end(), bytes.begin()); + if(buf.st_size != 0) + { #ifdef _WIN32 - int fd = open(path.c_str(), _O_RDONLY | _O_BINARY); + int fd = open(path.c_str(), _O_RDONLY | _O_BINARY); #else - int fd = open(path.c_str(), O_RDONLY); + int fd = open(path.c_str(), O_RDONLY); #endif - if(fd == -1) - { - throw "cannot open `" + path + "' for reading:\n" + lastError(); - } + if(fd == -1) + { + throw "cannot open `" + path + "' for reading:\n" + lastError(); + } + + if(read(fd, &bytes[relPath.size()], buf.st_size) == -1) + { + close(fd); + throw "cannot read from `" + path + "':\n" + lastError(); + } - if(read(fd, &bytes[relativePath.size()], buf.st_size) == -1) - { close(fd); - throw "cannot read from `" + path + "':\n" + lastError(); - } - close(fd); + // + // mode == 0: Never compress. + // mode == 1: Compress if necessary. + // mode >= 2: Always compress. + // + if(mode > 0) + { + string pathBZ2 = path + ".bz2"; + struct stat bufBZ2; - if(compress) - { - string pathBZ2 = path + ".bz2"; - compressBytesToFile(pathBZ2, bytes, relativePath.size()); + if(mode >= 2 || stat(pathBZ2.c_str(), &bufBZ2) == -1 || buf.st_mtime >= bufBZ2.st_mtime) + { + if(cb && !cb->compress(relPath)) + { + return false; + } + + compressBytesToFile(pathBZ2, bytes, relPath.size()); + + if(stat(pathBZ2.c_str(), &bufBZ2) == -1) + { + throw "cannot stat `" + pathBZ2 + "':\n" + lastError(); + } + } + + info.size = bufBZ2.st_size; + } } - if(size) + if(cb && !cb->checksum(relPath)) { - string pathBZ2 = path + ".bz2"; - - struct stat bufBZ2; - if(stat(pathBZ2.c_str(), &bufBZ2) == -1) - { - throw "cannot stat `" + pathBZ2 + "':\n" + lastError(); - } + return false; + } - info.size = bufBZ2.st_size; + ByteSeq bytesSHA(20); + if(!bytes.empty()) + { + SHA1(reinterpret_cast<unsigned char*>(&bytes[0]), bytes.size(), + reinterpret_cast<unsigned char*>(&bytesSHA[0])); } - } - else - { - if(verbose) + else { - cout << path << ": calculating checksum for empty file" << endl; + fill(bytesSHA.begin(), bytesSHA.end(), 0); } - } + info.checksum.swap(bytesSHA); - ByteSeq bytesSHA(20); - if(!bytes.empty()) - { - SHA1(reinterpret_cast<unsigned char*>(&bytes[0]), bytes.size(), - reinterpret_cast<unsigned char*>(&bytesSHA[0])); - } - else - { - fill(bytesSHA.begin(), bytesSHA.end(), 0); - } - info.checksum.swap(bytesSHA); - - infoSeq.push_back(info); - } - else - { - if(verbose) - { - cout << path << ": ignoring unknown file type" << endl; + infoSeq.push_back(info); } } + + return true; } -void -IcePatch2::getFileInfoSeq(const string& pa, FileInfoSeq& infoSeq, bool size, bool compress, bool verbose) +bool +IcePatch2::getFileInfoSeq(const string& pa, int mode, GetFileInfoSeqCB* cb, FileInfoSeq& infoSeq) { const string path = normalize(pa); - getFileInfoSeqInternal(path, ".", infoSeq, size, compress, verbose); + if(!getFileInfoSeqInt(path, ".", mode, cb, infoSeq)) + { + return false; + } sort(infoSeq.begin(), infoSeq.end(), FileInfoLess()); infoSeq.erase(unique(infoSeq.begin(), infoSeq.end(), FileInfoEqual()), infoSeq.end()); + + return true; } void |