diff options
author | Michi Henning <michi@zeroc.com> | 2004-12-31 04:32:43 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2004-12-31 04:32:43 +0000 |
commit | 2e3f67c17223bf7af57100a3fc787b3cf6c72952 (patch) | |
tree | f8a96f33656f1f556ad3dde191134af69b23aeef /cpp/src/IcePatch2/Util.cpp | |
parent | Fixed incorrect return value from start() for bad options. (diff) | |
download | ice-2e3f67c17223bf7af57100a3fc787b3cf6c72952.tar.bz2 ice-2e3f67c17223bf7af57100a3fc787b3cf6c72952.tar.xz ice-2e3f67c17223bf7af57100a3fc787b3cf6c72952.zip |
Compress == 1 wasn't working as intended and ended up always compressing a
file. Fixed it so the compressed file is used only if the compressed
file is actually smaller than the uncompressed file.
Diffstat (limited to 'cpp/src/IcePatch2/Util.cpp')
-rw-r--r-- | cpp/src/IcePatch2/Util.cpp | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp index 0bf6c71106c..bf2c8c6ecaf 100644 --- a/cpp/src/IcePatch2/Util.cpp +++ b/cpp/src/IcePatch2/Util.cpp @@ -516,8 +516,8 @@ IcePatch2::createDirectoryRecursive(const string& pa) } } -void -IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos) +int +IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos, int compress) { const string path = normalize(pa); @@ -566,6 +566,21 @@ IcePatch2::compressBytesToFile(const string& pa, const ByteSeq& bytes, Int pos) } fclose(stdioFile); + + struct stat buf; + if(stat(path.c_str(), &buf) == -1) + { + throw "cannot stat `" + path + "':\n" + lastError(); + } + if(compress == 1) // Use compressed file only if it is smaller. + { + if(static_cast<ByteSeq::size_type>(buf.st_size) >= bytes.size() - pos) + { + remove(path); + return 0; + } + } + return buf.st_size; } void @@ -775,27 +790,20 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G // compress == 1: Compress if necessary. // compress >= 2: Always compress. // + cerr << "compress = " << compress << endl; if(compress > 0) { + if(compress >= 2 && cb && !cb->compress(relPath)) + { + return false; + } + string pathBZ2 = path + ".bz2"; struct stat bufBZ2; - if(compress >= 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 = compressBytesToFile(pathBZ2, bytes, relPath.size(), compress); } - - info.size = bufBZ2.st_size; } } |