diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IcePatch2/Client.cpp | 60 | ||||
-rw-r--r-- | cpp/src/IcePatch2/Util.cpp | 68 |
2 files changed, 49 insertions, 79 deletions
diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp index 2d8f9d9352c..f8bf5578bd2 100644 --- a/cpp/src/IcePatch2/Client.cpp +++ b/cpp/src/IcePatch2/Client.cpp @@ -108,7 +108,7 @@ IcePatch2::Client::run(int argc, char* argv[]) char cwd[_MAX_PATH]; if(_getcwd(cwd, _MAX_PATH) == NULL) #else - char cwd[PATH_MAX]; + char cwd[PATH_MAX]; if(getcwd(cwd, PATH_MAX) == NULL) #endif { @@ -208,17 +208,6 @@ IcePatch2::Client::run(int argc, char* argv[]) sort(removeFiles.begin(), removeFiles.end(), FileInfoCompare()); sort(updateFiles.begin(), updateFiles.end(), FileInfoCompare()); - // - // We remove the summary file, so that if something goes wrong - // during patching, the next run has to be done with the - // thorough option. Otherwise there could be inconsistencies - // between the summary file and the real content. - // - if(!dry) - { - removeRecursive(dataDir + ".sum"); - } - FileInfoSeq::const_iterator p; p = removeFiles.begin(); @@ -232,7 +221,7 @@ IcePatch2::Client::run(int argc, char* argv[]) { removeRecursive(p->path); } - catch(...) + catch(const string&) { } } @@ -243,7 +232,7 @@ IcePatch2::Client::run(int argc, char* argv[]) { ++p; } - while(p->path.compare(0, dir.size(), dir) == 0); + while(p != removeFiles.end() && p->path.size() > dir.size() && p->path.compare(0, dir.size(), dir) == 0); } Long total = 0; @@ -270,13 +259,31 @@ IcePatch2::Client::run(int argc, char* argv[]) } else // Regular file. { + string pathBZ2 = p->path + ".bz2"; + ofstream os; + if(!dry) { - string dir = getDirname(p->path); + string dir = getDirname(pathBZ2); if(!dir.empty()) { createDirectoryRecursive(dir); } + + try + { + removeRecursive(pathBZ2); + } + catch(...) + { + } + + os.open(pathBZ2.c_str(), ios::binary); + if(!os) + { + cerr << argv[0] << ": cannot open `" + pathBZ2 + "' for writing: " + strerror(errno); + return EXIT_FAILURE; + } } Int pos = 0; @@ -302,6 +309,17 @@ IcePatch2::Client::run(int argc, char* argv[]) return EXIT_FAILURE; } + if(!dry) + { + os.write(reinterpret_cast<char*>(&bytes[0]), bytes.size()); + + if(!os.good()) + { + cerr << argv[0] << ": cannot write `" + pathBZ2 + "': " + strerror(errno); + return EXIT_FAILURE; + } + } + pos += bytes.size(); updated += bytes.size(); @@ -315,24 +333,18 @@ IcePatch2::Client::run(int argc, char* argv[]) cout << progress << flush; } -/* if(!dry) { + os.close(); + try { - removeRecursive(p->path); +// removeRecursive(p->path); } catch(...) { } - - ofstream os(p->path.c_str()); - if(!os) - { - throw "cannot open `" + p->path + "' for writing: " + strerror(errno); - } } -*/ } cout << endl; diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp index 2e4116f7a10..4220ce0bb0d 100644 --- a/cpp/src/IcePatch2/Util.cpp +++ b/cpp/src/IcePatch2/Util.cpp @@ -273,7 +273,7 @@ IcePatch2::removeRecursive(const string& pa) StringSeq paths = readDirectory(path); for(StringSeq::const_iterator p = paths.begin(); p != paths.end(); ++p) { - removeRecursive(*p); + removeRecursive(path + '/' + *p); } #ifdef _WIN32 @@ -388,16 +388,18 @@ IcePatch2::createDirectoryRecursive(const string& pa) } void -IcePatch2::compressToFile(const string& path, const ByteSeq& bytes, Int pos) +IcePatch2::compressToFile(const string& pa, const ByteSeq& bytes, Int pos) { - FILE* stdioFileBZ2 = fopen(path.c_str(), "wb"); - if(!stdioFileBZ2) + const string path = normalize(pa); + + FILE* stdioFile = fopen(path.c_str(), "wb"); + if(!stdioFile) { throw "cannot open `" + path + "' for writing: " + strerror(errno); } int bzError; - BZFILE* bzFile = BZ2_bzWriteOpen(&bzError, stdioFileBZ2, 5, 0, 0); + BZFILE* bzFile = BZ2_bzWriteOpen(&bzError, stdioFile, 5, 0, 0); if(bzError != BZ_OK) { string ex = "BZ2_bzWriteOpen failed"; @@ -405,7 +407,7 @@ IcePatch2::compressToFile(const string& path, const ByteSeq& bytes, Int pos) { ex += string(": ") + strerror(errno); } - fclose(stdioFileBZ2); + fclose(stdioFile); throw ex; } @@ -418,7 +420,7 @@ IcePatch2::compressToFile(const string& path, const ByteSeq& bytes, Int pos) ex += string(": ") + strerror(errno); } BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0); - fclose(stdioFileBZ2); + fclose(stdioFile); throw ex; } @@ -430,61 +432,17 @@ IcePatch2::compressToFile(const string& path, const ByteSeq& bytes, Int pos) { ex += string(": ") + strerror(errno); } - fclose(stdioFileBZ2); + fclose(stdioFile); throw ex; } - fclose(stdioFileBZ2); + fclose(stdioFile); } void -IcePatch2::uncompressToFile(const string& path, const ByteSeq& bytes, Int pos) +IcePatch2::uncompressToFile(const string& pa, const ByteSeq& bytes, Int pos) { - FILE* stdioFileBZ2 = fopen(path.c_str(), "wb"); - if(!stdioFileBZ2) - { - throw "cannot open `" + path + "' for writing: " + strerror(errno); - } - - int bzError; - BZFILE* bzFile = BZ2_bzWriteOpen(&bzError, stdioFileBZ2, 5, 0, 0); - if(bzError != BZ_OK) - { - string ex = "BZ2_bzWriteOpen failed"; - if(bzError == BZ_IO_ERROR) - { - ex += string(": ") + strerror(errno); - } - fclose(stdioFileBZ2); - throw ex; - } - - BZ2_bzWrite(&bzError, bzFile, const_cast<Byte*>(&bytes[pos]), bytes.size() - pos); - if(bzError != BZ_OK) - { - string ex = "BZ2_bzWrite failed"; - if(bzError == BZ_IO_ERROR) - { - ex += string(": ") + strerror(errno); - } - BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0); - fclose(stdioFileBZ2); - throw ex; - } - - BZ2_bzWriteClose(&bzError, bzFile, 0, 0, 0); - if(bzError != BZ_OK) - { - string ex = "BZ2_bzWriteClose failed"; - if(bzError == BZ_IO_ERROR) - { - ex += string(": ") + strerror(errno); - } - fclose(stdioFileBZ2); - throw ex; - } - - fclose(stdioFileBZ2); + const string path = normalize(pa); } void |