diff data/fileio/BZipFileDevice.cpp @ 207:8ee6cf529c4e

* Further fix for restoring layer visibility from session file * Better handling of error state in bzip file device to avoid spurious errors * Fix #1495001 deleted layers prevail in saved session file
author Chris Cannam
date Fri, 05 Jan 2007 15:49:10 +0000
parents a75e678f5d37
children b4a8d8221eaf
line wrap: on
line diff
--- a/data/fileio/BZipFileDevice.cpp	Fri Jan 05 14:46:45 2007 +0000
+++ b/data/fileio/BZipFileDevice.cpp	Fri Jan 05 15:49:10 2007 +0000
@@ -23,7 +23,8 @@
     m_fileName(fileName),
     m_file(0),
     m_bzFile(0),
-    m_atEnd(true)
+    m_atEnd(true),
+    m_ok(true)
 {
 }
 
@@ -34,6 +35,12 @@
 }
 
 bool
+BZipFileDevice::isOK() const
+{
+    return m_ok;
+}
+
+bool
 BZipFileDevice::open(OpenMode mode)
 {
     setErrorString("");
@@ -45,16 +52,19 @@
 
     if (mode & Append) {
         setErrorString(tr("Append mode not supported"));
+        m_ok = false;
         return false;
     }
 
     if ((mode & (ReadOnly | WriteOnly)) == 0) {
         setErrorString(tr("File access mode not specified"));
+        m_ok = false;
         return false;
     }
 
     if ((mode & ReadOnly) && (mode & WriteOnly)) {
         setErrorString(tr("Read and write modes both specified"));
+        m_ok = false;
         return false;
     }
 
@@ -63,6 +73,7 @@
         m_file = fopen(m_fileName.toLocal8Bit().data(), "wb");
         if (!m_file) {
             setErrorString(tr("Failed to open file for writing"));
+            m_ok = false;
             return false;
         }
 
@@ -73,6 +84,7 @@
             fclose(m_file);
             m_file = 0;
             setErrorString(tr("Failed to open bzip2 stream for writing"));
+            m_ok = false;
             return false;
         }
 
@@ -88,6 +100,7 @@
         m_file = fopen(m_fileName.toLocal8Bit().data(), "rb");
         if (!m_file) {
             setErrorString(tr("Failed to open file for reading"));
+            m_ok = false;
             return false;
         }
 
@@ -98,6 +111,7 @@
             fclose(m_file);
             m_file = 0;
             setErrorString(tr("Failed to open bzip2 stream for reading"));
+            m_ok = false;
             return false;
         }
 
@@ -111,6 +125,7 @@
     }
 
     setErrorString(tr("Internal error (open for neither read nor write)"));
+    m_ok = false;
     return false;
 }
 
@@ -119,6 +134,7 @@
 {
     if (!m_bzFile) {
         setErrorString(tr("File not open"));
+        m_ok = false;
         return;
     }
 
@@ -134,6 +150,7 @@
         fclose(m_file);
         m_bzFile = 0;
         m_file = 0;
+        m_ok = false;
         return;
     }
 
@@ -145,6 +162,7 @@
         fclose(m_file);
         m_bzFile = 0;
         m_file = 0;
+        m_ok = false;
         return;
     }
 
@@ -166,6 +184,7 @@
         if (bzError != BZ_STREAM_END) {
             std::cerr << "BZipFileDevice::readData: error condition" << std::endl;
             setErrorString(tr("bzip2 stream read error"));
+            m_ok = false;
             return -1;
         } else {
 //            std::cerr << "BZipFileDevice::readData: reached end of file" << std::endl;
@@ -173,7 +192,6 @@
         }            
     }
 
-    setErrorString("");
     return read;
 }
 
@@ -188,12 +206,12 @@
     if (bzError != BZ_OK) {
         std::cerr << "BZipFileDevice::writeData: error condition" << std::endl;
         setErrorString("bzip2 stream write error");
+        m_ok = false;
         return -1;
     }
 
 //    std::cerr << "BZipFileDevice::writeData: wrote " << maxSize << std::endl;
 
-    setErrorString("");
     return maxSize;
 }