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/08/02 11:15:30 UTC

incubator-corinthia git commit: unzip integrated, warning zip is broken right now

Repository: incubator-corinthia
Updated Branches:
  refs/heads/newZipExperiment2 1375ad9a0 -> b80df2922


unzip integrated, warning zip is broken right now


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

Branch: refs/heads/newZipExperiment2
Commit: b80df29228e5e5329ba9f224e1e227a1475baa20
Parents: 1375ad9
Author: jani <ja...@apache.org>
Authored: Sun Aug 2 11:15:13 2015 +0200
Committer: jani <ja...@apache.org>
Committed: Sun Aug 2 11:15:13 2015 +0200

----------------------------------------------------------------------
 DocFormats/core/src/lib/DFZipFile.c   | 48 +++++++----------
 DocFormats/headers/DFPlatform.h       |  7 ++-
 DocFormats/platform/src/Wrapper_zip.c | 86 +++---------------------------
 3 files changed, 28 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/b80df292/DocFormats/core/src/lib/DFZipFile.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFZipFile.c b/DocFormats/core/src/lib/DFZipFile.c
index ee5a648..b3dab37 100644
--- a/DocFormats/core/src/lib/DFZipFile.c
+++ b/DocFormats/core/src/lib/DFZipFile.c
@@ -38,40 +38,28 @@ static int zipError(DFError **error, const char *format, ...)
 
 int DFUnzip(const char *zipFilename, DFStorage *storage, DFError **error)
 {
-    char            entryName[4096];
-    DFextZipHandleP zipHandle;
+	unsigned char   *buf;
+    DFextZipHandleP  zipHandle;
+	int              i;
 
-    zipHandle = DFextZipOpen(zipFilename, 1);
+    zipHandle = DFextZipOpen(zipFilename);
     if (!zipHandle)
       return zipError(error,"Cannot open file");
 
-    int ret;
-    for (; (ret = DFextZipOpenNextFile(zipHandle, entryName, sizeof(entryName))) > 0;) {
-        DFBuffer *content = DFBufferNew();
-
-        unsigned char buf[4096];
-        int r;
-        while (0 < (r = DFextZipReadCurrentFile(zipHandle, buf, sizeof(buf))))
-            DFBufferAppendData(content,(void *)buf,r);
-        if (0 > r) {
-            DFBufferRelease(content);
-            return zipError(error,"%s: decompression failed",entryName);
-        }
-
-        if (DFextZipCloseFile(zipHandle) < 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);
-    }
+	for (i = 0; i < zipHandle->zipFileCount; i++) {
+		if ( (buf = DFextZipReadFile(zipHandle, &zipHandle->zipFileEntries[i])) == NULL)
+			return zipError(error, "Cannot read file in zip");
+
+		DFBuffer *content = DFBufferNew();
+		DFBufferAppendData(content, (void *)buf, zipHandle->zipFileEntries[i].uncompressedSize);
+		free(buf);
 
-    if (ret < 0)
-        return zipError(error,"Zip directory is corrupt");
+		if (!DFBufferWriteToStorage(content, storage, zipHandle->zipFileEntries[i].fileName, error)) {
+			DFBufferRelease(content);
+			return zipError(error, "%s: %s", zipHandle->zipFileEntries[i].fileName, DFErrorMessage(error));
+		}
+		DFBufferRelease(content);
+	}
 
     DFextZipClose(zipHandle);
 
@@ -101,7 +89,7 @@ int DFZip(const char *zipFilename, DFStorage *storage, DFError **error)
     DFextZipHandleP zipHandle = NULL;
 
     allPaths = DFStorageList(storage,error);
-    if (allPaths == NULL || !(zipHandle = DFextZipOpen(zipFilename, 0)))
+    if (allPaths == NULL || !(zipHandle = DFextZipCreate(zipFilename)))
     {
       DFErrorFormat(error,"Cannot create file");
     }

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/b80df292/DocFormats/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/headers/DFPlatform.h b/DocFormats/headers/DFPlatform.h
index 3eee304..e8ed0d7 100644
--- a/DocFormats/headers/DFPlatform.h
+++ b/DocFormats/headers/DFPlatform.h
@@ -74,8 +74,7 @@ typedef struct {
 	int   uncompressedSize;  // Real file size
 	int   compressionMethod; // Type of compression
 	long  offset;            // offset in file
-	int   fileNameLength;    // Length of filename
-	char *fileName;          // filename
+	char *fileName;          // filename zero terminated
 } DFextZipDirEntry;
 typedef DFextZipDirEntry * DFextZipDirEntryP;
 typedef struct {
@@ -99,12 +98,12 @@ int DFextZipClose(DFextZipHandleP zipHandle);
 int DFextZipAppendNewFile(DFextZipHandleP zipHandle,
                           const char *entryName);
 
-int DFextZipCloseFile(DFextZipHandleP zipHandle);
-
 int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle,
                              const void *buf,
                              const int len);
 
+
+
 void *xmalloc(size_t size);
 
 void *xcalloc(size_t nmemb, size_t size);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/b80df292/DocFormats/platform/src/Wrapper_zip.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper_zip.c b/DocFormats/platform/src/Wrapper_zip.c
index b0cd41f..272d3be 100644
--- a/DocFormats/platform/src/Wrapper_zip.c
+++ b/DocFormats/platform/src/Wrapper_zip.c
@@ -153,15 +153,14 @@ static int readDirectory(FILE *zipFile, DFextZipHandleP zipHandle)
 
 			// Save information
 			zipDirEntry->compressedSize    = recFile->compressedSize;
-			zipDirEntry->fileNameLength    = recFile->fileNameLength;
 			zipDirEntry->uncompressedSize  = recFile->uncompressedSize;
 			zipDirEntry->compressionMethod = recFile->compressionMethod;
 
 			// Add filename
-			zipDirEntry->fileName = xmalloc(zipDirEntry->fileNameLength + 1);
-			if (fread(zipDirEntry->fileName, 1, zipDirEntry->fileNameLength, zipFile) < (unsigned long)zipDirEntry->fileNameLength)
+			zipDirEntry->fileName = xmalloc(recFile->fileNameLength + 1);
+			if (fread(zipDirEntry->fileName, 1, recFile->fileNameLength, zipFile) < (unsigned long)recFile->fileNameLength)
 				return -1;
-			zipDirEntry->fileName[zipDirEntry->fileNameLength] = '\0';
+			zipDirEntry->fileName[recFile->fileNameLength] = '\0';
 
 			// skip extra field
 			if (fseek(zipFile, recFile->extraFieldLength, SEEK_CUR))
@@ -300,64 +299,15 @@ DFextZipHandleP DFextZipCreate(const char *zipFilename) {
 
 int DFextZipClose(DFextZipHandleP zipHandle)
 {
-    int rc = 0;
-
-#if 0
-    if (zipHandle->handle) {
-        if (zipHandle->zipFlag)
-            rc = (unzClose(zipHandle->handle) == UNZ_OK);
-        else
-            rc = (zipClose(zipHandle->handle, NULL) == ZIP_OK);
-        zipHandle->handle = NULL;
-    }
-
-    free(zipHandle);
-#endif
+	fclose(zipHandle->zipFile);
 	releaseMemory(zipHandle);
-	return rc ? 1 : -1;
+	return 0;
 }
 
 
 
-int DFextZipOpenNextFile(DFextZipHandleP zipHandle, char *entryName, const int maxName)
-{
-#if 0
-	int rc;
-
-    if (zipHandle->zipFlag) {
-        unz_file_info info;
-
-        // handling of first file and all others are different
-        if (zipHandle->zipFirst) {
-            rc = unzGoToFirstFile(zipHandle->handle);
-            zipHandle->zipFirst = 0;
-        }
-        else
-            rc = unzGoToNextFile(zipHandle->handle);
-
-        // Error or past last file
-        if (rc != UNZ_OK)
-            return (rc == UNZ_END_OF_LIST_OF_FILE) ? 0 : -1;
-
-        // get file name
-        if (unzGetCurrentFileInfo(zipHandle->handle, &info, entryName, maxName, NULL, 0, NULL, 0) != UNZ_OK)
-            return -1;
-
-        // check for prefix "/" and if present skip file
-        if (entryName[strlen(entryName) - 1] == '/')
-            return DFextZipOpenNextFile(zipHandle, entryName, maxName);
-
-        // open Regular file
-        if (unzOpenCurrentFile(zipHandle->handle) != UNZ_OK)
-            return -1;
-    }
-    else {
-        return -1; // Zip file is open in write-only mode
-    }
-
-    // ready to read
-#endif
-    return 1;
+int DFextZipCloseFile(DFextZipHandleP zipHandle) {
+	return 0;
 }
 
 int DFextZipAppendNewFile(DFextZipHandleP zipHandle, const char *entryName)
@@ -383,28 +333,6 @@ int DFextZipAppendNewFile(DFextZipHandleP zipHandle, const char *entryName)
     return 1;
 }
 
-int DFextZipCloseFile(DFextZipHandleP zipHandle)
-{
-#if 0
-    if (zipHandle->zipFlag)
-        return (unzCloseCurrentFile(zipHandle->handle) != UNZ_OK) ? -1 : 1;
-    else
-        return (zipCloseFileInZip(zipHandle->handle) != UNZ_OK) ? -1 : 1;
-#endif
-	return 0;
-}
-
-
- 
-
-int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, void *buf, const int maxLen)
-{
-#if 0
-    return unzReadCurrentFile(zipHandle->handle, buf, maxLen);
-#endif
-	return 0;
-}
-
 
 
 int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, const void *buf, const int len)