summaryrefslogtreecommitdiff
path: root/cpp/src/IcePatch2/Util.cpp
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2004-12-31 20:26:39 +0000
committerMarc Laukien <marc@zeroc.com>2004-12-31 20:26:39 +0000
commite66dc8e79da98544553d250089b071c25894823c (patch)
treed8e231e2934a39f4c60ed587ce3b7fd8c2a7de5a /cpp/src/IcePatch2/Util.cpp
parentBacked out previous change -- I didn't realize until just now that the file (diff)
downloadice-e66dc8e79da98544553d250089b071c25894823c.tar.bz2
ice-e66dc8e79da98544553d250089b071c25894823c.tar.xz
ice-e66dc8e79da98544553d250089b071c25894823c.zip
fix
Diffstat (limited to 'cpp/src/IcePatch2/Util.cpp')
-rw-r--r--cpp/src/IcePatch2/Util.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp
index 0bf6c71106c..e37a240537c 100644
--- a/cpp/src/IcePatch2/Util.cpp
+++ b/cpp/src/IcePatch2/Util.cpp
@@ -293,9 +293,10 @@ bool
IcePatch2::ignoreSuffix(const string& path)
{
string suffix = getSuffix(path);
- return suffix == "md5" // For legacy IcePatch
- || suffix == "tot" // For legacy IcePatch
- || suffix == "bz2";
+ return suffix == "md5" // For legacy IcePatch.
+ || suffix == "tot" // For legacy IcePatch.
+ || suffix == "bz2"
+ || suffix == "bz2temp";
}
string
@@ -331,6 +332,20 @@ IcePatch2::getDirname(const string& pa)
}
void
+IcePatch2::rename(const string& fromPa, const string& toPa)
+{
+ const string fromPath = normalize(fromPa);
+ const string toPath = normalize(toPa);
+
+ ::remove(toPath.c_str()); // We ignore errors, as the file we are renaming to might not exist.
+
+ if(::rename(fromPath.c_str(), toPath.c_str()) == -1)
+ {
+ throw "cannot rename `" + fromPath + "' to `" + toPath + "': " + lastError();
+ }
+}
+
+void
IcePatch2::remove(const string& pa)
{
const string path = normalize(pa);
@@ -660,7 +675,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
if(ignoreSuffix(path))
{
- string pathWithoutSuffix = getWithoutSuffix(path);
+ const string pathWithoutSuffix = getWithoutSuffix(path);
if(ignoreSuffix(pathWithoutSuffix))
{
@@ -777,8 +792,8 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
//
if(compress > 0)
{
- string pathBZ2 = path + ".bz2";
struct stat bufBZ2;
+ const string pathBZ2 = path + ".bz2";
if(compress >= 2 || stat(pathBZ2.c_str(), &bufBZ2) == -1 || buf.st_mtime >= bufBZ2.st_mtime)
{
@@ -787,8 +802,18 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G
return false;
}
- compressBytesToFile(pathBZ2, bytes, relPath.size());
+ //
+ // We compress into a .bz2temp file, and then
+ // move this file to the final .bz2 file. This
+ // way we can be sure that there are no
+ // incomplete .bz2 files in case of a crash.
+ //
+ const string pathBZ2Temp = path + ".bz2temp";
+
+ compressBytesToFile(pathBZ2Temp, bytes, relPath.size());
+ rename(pathBZ2Temp, pathBZ2);
+
if(stat(pathBZ2.c_str(), &bufBZ2) == -1)
{
throw "cannot stat `" + pathBZ2 + "':\n" + lastError();