From 177380015f8d5d192ca1112a9d959734c031314c Mon Sep 17 00:00:00 2001
From: Andreas Naumann <andreas.naumann@tu-dresden.de>
Date: Sun, 24 Oct 2010 19:14:46 +0000
Subject: [PATCH] boost::iostreams truncate bug

---
 AMDiS/src/VtkWriter.cc | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/AMDiS/src/VtkWriter.cc b/AMDiS/src/VtkWriter.cc
index 2153ae00..7b997d58 100644
--- a/AMDiS/src/VtkWriter.cc
+++ b/AMDiS/src/VtkWriter.cc
@@ -29,16 +29,21 @@ namespace AMDiS {
     switch (compress) {
     case GZIP:
       file.push(boost::iostreams::gzip_compressor());
-      file.push(boost::iostreams::file_descriptor_sink(name.append(".gz")));    
+      name.append(".gz");
       break;
     case BZIP2:
       file.push(boost::iostreams::bzip2_compressor());
-      file.push(boost::iostreams::file_descriptor_sink(name.append(".bz2")));
+      name.append(".bz2");
       break;
     default:
-      file.push(boost::iostreams::file_descriptor_sink(name));
       break;
-    } 
+    }
+    {
+      //boost::iostreams seems not to truncate the file
+      std::ofstream swapfile(name.c_str(), std::ios::out | std::ios::trunc);
+      swapfile.close();
+    }
+    file.push(boost::iostreams::file_descriptor_sink(name, std::ios::trunc)); 
     writeFileToStream(file);
 
 #else
-- 
GitLab