]> git.saurik.com Git - wxWidgets.git/commitdiff
Always write end record unless one has already been written.
authorMichael Wetherell <mike.wetherell@ntlworld.com>
Thu, 3 Jan 2008 17:09:10 +0000 (17:09 +0000)
committerMichael Wetherell <mike.wetherell@ntlworld.com>
Thu, 3 Jan 2008 17:09:10 +0000 (17:09 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51008 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/tarstrm.h
include/wx/zipstrm.h
src/common/tarstrm.cpp
src/common/zipstrm.cpp

index b92119904f85f6eb98696797652e3a5255d611d7..e405375925a7005212db242741b526835fa1cdd4 100644 (file)
@@ -280,6 +280,7 @@ private:
     char *m_extendedHdr;
     size_t m_extendedSize;
     wxString m_badfit;
+    bool m_endrecWritten;
 
     DECLARE_NO_COPY_CLASS(wxTarOutputStream)
 };
index 6486492a5addc60e26a4717e06ad85f99fbd35b4..5d3d67530dcb055af875835b041de16d152e86bd 100644 (file)
@@ -346,6 +346,7 @@ private:
     int m_level;
     wxFileOffset m_offsetAdjustment;
     wxString m_Comment;
+    bool m_endrecWritten;
 
     DECLARE_NO_COPY_CLASS(wxZipOutputStream)
 };
index 38020b7d25f132f7b7c85c8213a9bfa87eeedbad..7b053df2ab38d5f17a83553e7c2527e54cea252b 100644 (file)
@@ -1083,12 +1083,12 @@ void wxTarOutputStream::Init(wxTarFormat format)
     m_extendedHdr = NULL;
     m_extendedSize = 0;
     m_lasterror = m_parent_o_stream->GetLastError();
+    m_endrecWritten = false;
 }
 
 wxTarOutputStream::~wxTarOutputStream()
 {
-    if (m_tarsize)
-        Close();
+    Close();
     delete m_hdr;
     delete m_hdr2;
     delete [] m_extendedHdr;
@@ -1207,9 +1207,9 @@ bool wxTarOutputStream::CloseEntry()
 
 bool wxTarOutputStream::Close()
 {
-    if (!CloseEntry())
+    if (!CloseEntry() || (m_tarsize == 0 && m_endrecWritten))
         return false;
-
     memset(m_hdr, 0, sizeof(*m_hdr));
     int count = (RoundUpSize(m_tarsize + 2 * TAR_BLOCKSIZE, m_BlockingFactor)
                     - m_tarsize) / TAR_BLOCKSIZE;
@@ -1219,6 +1219,7 @@ bool wxTarOutputStream::Close()
     m_tarsize = 0;
     m_tarstart = wxInvalidOffset;
     m_lasterror = m_parent_o_stream->GetLastError();
+    m_endrecWritten = true;
     return IsOk();
 }
 
index 79c1c449e4ceb9f9de5f0f883586686c724ca61a..70d5651070fc3e83084bc8283d456e0d4bc95969 100644 (file)
@@ -1463,11 +1463,13 @@ bool wxZipInputStream::LoadEndRecord()
     m_TotalEntries = endrec.GetTotalEntries();
     m_Comment = endrec.GetComment();
 
+    wxUint32 magic = m_TotalEntries ? CENTRAL_MAGIC : END_MAGIC;
+
     // Now find the central-directory. we have the file offset of
     // the CD, so look there first.
     if (m_parent_i_stream->SeekI(endrec.GetOffset()) != wxInvalidOffset &&
-            ReadSignature() == CENTRAL_MAGIC) {
-        m_signature = CENTRAL_MAGIC;
+            ReadSignature() == magic) {
+        m_signature = magic;
         m_position = endrec.GetOffset();
         m_offsetAdjustment = 0;
         return true;
@@ -1477,8 +1479,8 @@ bool wxZipInputStream::LoadEndRecord()
     // to a self extractor, so take the CD size (also in endrec), subtract
     // it from the file offset of the end-central-directory and look there.
     if (m_parent_i_stream->SeekI(endPos - endrec.GetSize())
-            != wxInvalidOffset && ReadSignature() == CENTRAL_MAGIC) {
-        m_signature = CENTRAL_MAGIC;
+            != wxInvalidOffset && ReadSignature() == magic) {
+        m_signature = magic;
         m_position = endPos - endrec.GetSize();
         m_offsetAdjustment = m_position - endrec.GetOffset();
         return true;
@@ -1988,6 +1990,7 @@ void wxZipOutputStream::Init(int level)
     m_comp = NULL;
     m_level = level;
     m_offsetAdjustment = wxInvalidOffset;
+    m_endrecWritten = false;
 }
 
 wxZipOutputStream::~wxZipOutputStream()
@@ -2287,7 +2290,9 @@ bool wxZipOutputStream::Close()
 {
     CloseEntry();
 
-    if (m_lasterror == wxSTREAM_WRITE_ERROR) {
+    if (m_lasterror == wxSTREAM_WRITE_ERROR
+        || (m_entries.size() == 0 && m_endrecWritten))
+    {
         wxFilterOutputStream::Close();
         return false;
     }
@@ -2312,6 +2317,7 @@ bool wxZipOutputStream::Close()
     endrec.Write(*m_parent_o_stream, GetConv());
 
     m_lasterror = m_parent_o_stream->GetLastError();
+    m_endrecWritten = true;
     
     if (!wxFilterOutputStream::Close() || !IsOk())
         return false;