You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by ja...@apache.org on 2015/01/01 11:10:29 UTC

[07/19] incubator-corinthia git commit: work

work


Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/4524f155
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/4524f155
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/4524f155

Branch: refs/heads/RTC_platform
Commit: 4524f155e19b34f080d5a40bf266bcf6aa55f351
Parents: 5fc315e
Author: jani <ja...@apache.org>
Authored: Sun Dec 28 19:02:52 2014 +0100
Committer: jani <ja...@apache.org>
Committed: Sun Dec 28 19:02:52 2014 +0100

----------------------------------------------------------------------
 DocFormats/core/src/lib/DFZipFile.c | 59 ++++++++++++++------------------
 1 file changed, 25 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/4524f155/DocFormats/core/src/lib/DFZipFile.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFZipFile.c b/DocFormats/core/src/lib/DFZipFile.c
index 87e4d54..63b6202 100644
--- a/DocFormats/core/src/lib/DFZipFile.c
+++ b/DocFormats/core/src/lib/DFZipFile.c
@@ -13,7 +13,7 @@
 // limitations under the License.
 
 #include "DFZipFile.h"
-#include "platform.h"
+#include "DFPlatform.h"
 #include "DFFilesystem.h"
 #include "DFString.h"
 #include "DFCommon.h"
@@ -34,46 +34,37 @@ static int zipError(DFError **error, const char *format, ...)
 
 int DFUnzip(const char *zipFilename, DFStorage *storage, DFError **error)
 {
-  if (DFextZipOpen(zipFilename, 1) <= 0)
+    char entryName[4096];
+
+    if (DFextZipOpen(zipFilename, 1) <= 0)
     return zipError(error,"Cannot open file");
 
     int ret;
-    for (ret = unzGoToFirstFile(zipFile); ret == UNZ_OK; ret = unzGoToNextFile(zipFile)) {
-        unz_file_info info;
-        char entryName[4096];
-        if (UNZ_OK != unzGetCurrentFileInfo(zipFile,&info,entryName,4096,NULL,0,NULL,0))
-            return zipError(error,"Zip directory is corrupt");
-
-        if (!DFStringHasSuffix(entryName,"/")) {
-            // Regular file
-            if (UNZ_OK != unzOpenCurrentFile(zipFile))
-                return zipError(error,"%s: Cannot open zip entry",entryName);;
-
-            DFBuffer *content = DFBufferNew();
-
-            unsigned char buf[4096];
-            int r;
-            while (0 < (r = unzReadCurrentFile(zipFile,buf,4096)))
-                DFBufferAppendData(content,(void *)buf,r);
-            if (0 > r) {
-                DFBufferRelease(content);
-                return zipError(error,"%s: decompression failed",entryName);
-            }
-
-            if (UNZ_OK != unzCloseCurrentFile(zipFile)) {
-                DFBufferRelease(content);
-                return zipError(error,"%s: decompression failed",entryName);
-            }
-
-            if (!DFBufferWriteToStorage(content,storage,entryName,error)) {
-                DFBufferRelease(content);
-                return zipError(error,"%s: %s",entryName,DFErrorMessage(error));
-            }
+    for (;  (ret = DFextZipOpenNextFile(entryName, sizeof(entryName))) > 0;) {
+        DFBuffer *content = DFBufferNew();
+
+        unsigned char buf[4096];
+        int r;
+        while (0 < (r = DFextZipReadCurrentFile(buf, sizeof(buf))))
+            DFBufferAppendData(content,(void *)buf,r);
+        if (0 > r) {
+            DFBufferRelease(content);
+            return zipError(error,"%s: decompression failed",entryName);
+        }
+
+        if (DFextZipCloseFile() < 0) {
+            DFBufferRelease(content);
+            return zipError(error,"%s: decompression failed",entryName);
+        }
+
+        if (!DFBufferWriteToStorage(content,storage,entryName,error)) {
             DFBufferRelease(content);
+            return zipError(error,"%s: %s",entryName,DFErrorMessage(error));
         }
+        DFBufferRelease(content);
     }
 
-    if (UNZ_END_OF_LIST_OF_FILE != ret)
+    if (ret < 0)
         return zipError(error,"Zip directory is corrupt");
 
     DFextZipClose();