You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by pm...@apache.org on 2015/01/02 14:47:19 UTC

[1/3] incubator-corinthia git commit: Add DFextZipAppendNewFile

Repository: incubator-corinthia
Updated Branches:
  refs/heads/master c1c87be91 -> f27803f4c


Add DFextZipAppendNewFile

A handle to a zip file is either in read-only mode, or write-only mode
(as determined by the zipFlag field of the object). In the former case,
DFextZipOpenNextFile opens an existing file for reading at the next
position in the file. In the latter case, it created a new file at the
end of the zip file for writing.

When reading the next entry, the entryName parameter must be writable -
that's how the name is passed back to the caller. As such, the caller
provides a writable string, consisting of a char * and a maximum length.
In this case, the parameter types are ok.

When writing the next entry, the entryName parameter plays the opposite
role - it is the caller telling the function what name to give to the
new file. In what is currently the only place where this is called,
zipAddFile in DFZipFile.c, the filename is a read-only string (const
char *). Although the DFextZipOpenNextFile didn't actually overwrite the
string in the case of a write-only zip stream, the compiler would warn
that a value of const char * was being supplied to a function expecting
a char * value (that is, a read-only string being supplied where a
writable string parameter was expected).

This commit splits DFextZipOpenNextFile into two functions -
DFextZipOpenNextFile for reading and DFextZipAppendNewFile for writing.
The latter accepts a read-only string, and thus doesn't generate a
compiler warning.


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

Branch: refs/heads/master
Commit: f93d1a5a691d62e3f3e0374328d50b66147b5ac0
Parents: c1c87be
Author: Peter Kelly <pe...@uxproductivity.com>
Authored: Fri Jan 2 20:31:39 2015 +0700
Committer: Peter Kelly <pe...@uxproductivity.com>
Committed: Fri Jan 2 20:31:39 2015 +0700

----------------------------------------------------------------------
 DocFormats/core/src/lib/DFZipFile.c      |  2 +-
 DocFormats/platform/headers/DFPlatform.h |  1 +
 DocFormats/platform/src/Wrapper.c        | 33 +++++++++++++++++----------
 3 files changed, 23 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f93d1a5a/DocFormats/core/src/lib/DFZipFile.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFZipFile.c b/DocFormats/core/src/lib/DFZipFile.c
index 451934e..1057ad0 100644
--- a/DocFormats/core/src/lib/DFZipFile.c
+++ b/DocFormats/core/src/lib/DFZipFile.c
@@ -76,7 +76,7 @@ int DFUnzip(const char *zipFilename, DFStorage *storage, DFError **error)
 
 static int zipAddFile(DFextZipHandleP zipHandle, const char *dest, DFBuffer *content, DFError **error)
 {
-    if (DFextZipOpenNextFile(zipHandle, dest, 0) < 0)
+    if (DFextZipAppendNewFile(zipHandle, dest) < 0)
         return zipError(error,"%s: Cannot create entry in zip file",dest);
 
     if (DFextZipWriteCurrentFile(zipHandle, content->data, (unsigned int)content->len) < 0)

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f93d1a5a/DocFormats/platform/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/platform/headers/DFPlatform.h b/DocFormats/platform/headers/DFPlatform.h
index 3d379d4..1e83b2c 100755
--- a/DocFormats/platform/headers/DFPlatform.h
+++ b/DocFormats/platform/headers/DFPlatform.h
@@ -46,6 +46,7 @@ DFextZipHandleP DFextZipOpen(const char *zipFilename, int doUnzip);
 int             DFextZipClose(DFextZipHandleP zipHandle);
 
 int             DFextZipOpenNextFile(DFextZipHandleP zipHandle, char *entryName, const int maxName);
+int             DFextZipAppendNewFile(DFextZipHandleP zipHandle, const char *entryName);
 int             DFextZipCloseFile(DFextZipHandleP zipHandle);
 
 int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, char *buf, const int maxLen);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f93d1a5a/DocFormats/platform/src/Wrapper.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper.c b/DocFormats/platform/src/Wrapper.c
index 1701d9d..26dc413 100644
--- a/DocFormats/platform/src/Wrapper.c
+++ b/DocFormats/platform/src/Wrapper.c
@@ -93,25 +93,34 @@ int DFextZipOpenNextFile(DFextZipHandleP zipHandle, char *entryName, const int m
             return -1;
     }
     else {
-        zip_fileinfo fileinfo;
-        memset(&fileinfo, 0, sizeof(fileinfo));
-
-        if (zipOpenNewFileInZip(zipHandle->handle,
-            entryName,
-            &fileinfo,
-            NULL, 0,
-            NULL, 0,
-            NULL,
-            Z_DEFLATED,
-            Z_DEFAULT_COMPRESSION) != ZIP_OK)
-            return -1;
+        return -1; // Zip file is open in write-only mode
     }
 
     // ready to read
     return 1;
 }
 
+int DFextZipAppendNewFile(DFextZipHandleP zipHandle, const char *entryName)
+{
+    zip_fileinfo fileinfo;
+    memset(&fileinfo, 0, sizeof(fileinfo));
 
+    if (zipHandle->zipFlag)
+        return -1; // Zip file is open in read-only mode
+
+    if (zipOpenNewFileInZip(zipHandle->handle,
+                            entryName,
+                            &fileinfo,
+                            NULL, 0,
+                            NULL, 0,
+                            NULL,
+                            Z_DEFLATED,
+                            Z_DEFAULT_COMPRESSION) != ZIP_OK) {
+        return -1;
+    }
+
+    return 1;
+}
 
 int DFextZipCloseFile(DFextZipHandleP zipHandle)
 {


[3/3] incubator-corinthia git commit: DFUnzip: Fix warning about unsigned char * cast

Posted by pm...@apache.org.
DFUnzip: Fix warning about unsigned char * cast

The DFextZipReadCurrentFile function expected a char * parameter, but we
were passing in an unsigned char *, resulting in a compiler warning.

This commit changes DFextZipReadCurrentFile to instead take a void *
parameter, and similarly DFextZipWriteCurrentFile to take a const void *
parameter. This allows any pointer types to be used with the functions.


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

Branch: refs/heads/master
Commit: f27803f4c0f0336c5f5df5fb7bd5d396bc74de65
Parents: 69a8028
Author: Peter Kelly <pe...@uxproductivity.com>
Authored: Fri Jan 2 20:39:12 2015 +0700
Committer: Peter Kelly <pe...@uxproductivity.com>
Committed: Fri Jan 2 20:39:12 2015 +0700

----------------------------------------------------------------------
 DocFormats/platform/headers/DFPlatform.h | 4 ++--
 DocFormats/platform/src/Wrapper.c        | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f27803f4/DocFormats/platform/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/platform/headers/DFPlatform.h b/DocFormats/platform/headers/DFPlatform.h
index 1e83b2c..6f16983 100755
--- a/DocFormats/platform/headers/DFPlatform.h
+++ b/DocFormats/platform/headers/DFPlatform.h
@@ -49,6 +49,6 @@ int             DFextZipOpenNextFile(DFextZipHandleP zipHandle, char *entryName,
 int             DFextZipAppendNewFile(DFextZipHandleP zipHandle, const char *entryName);
 int             DFextZipCloseFile(DFextZipHandleP zipHandle);
 
-int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, char *buf, const int maxLen);
-int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, char *buf, const int len);
+int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, void *buf, const int maxLen);
+int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, const void *buf, const int len);
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/f27803f4/DocFormats/platform/src/Wrapper.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper.c b/DocFormats/platform/src/Wrapper.c
index 26dc413..14ed093 100644
--- a/DocFormats/platform/src/Wrapper.c
+++ b/DocFormats/platform/src/Wrapper.c
@@ -133,14 +133,14 @@ int DFextZipCloseFile(DFextZipHandleP zipHandle)
 
  
 
-int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, char *buf, const int maxLen)
+int DFextZipReadCurrentFile(DFextZipHandleP zipHandle, void *buf, const int maxLen)
 {
     return unzReadCurrentFile(zipHandle->handle, buf, maxLen);
 }
 
 
 
-int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, char *buf, const int len)
+int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, const void *buf, const int len)
 {
     return (zipWriteInFileInZip(zipHandle->handle, buf, len) == ZIP_OK) ? 1 : -1;
 }


[2/3] incubator-corinthia git commit: DFZip: Fix uninitialised variable warning

Posted by pm...@apache.org.
DFZip: Fix uninitialised variable warning


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

Branch: refs/heads/master
Commit: 69a802864f077258bc733426e95e9a9b2814876f
Parents: f93d1a5
Author: Peter Kelly <pe...@uxproductivity.com>
Authored: Fri Jan 2 20:37:26 2015 +0700
Committer: Peter Kelly <pe...@uxproductivity.com>
Committed: Fri Jan 2 20:37:26 2015 +0700

----------------------------------------------------------------------
 DocFormats/core/src/lib/DFZipFile.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/69a80286/DocFormats/core/src/lib/DFZipFile.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFZipFile.c b/DocFormats/core/src/lib/DFZipFile.c
index 1057ad0..8bc0bcb 100644
--- a/DocFormats/core/src/lib/DFZipFile.c
+++ b/DocFormats/core/src/lib/DFZipFile.c
@@ -94,7 +94,7 @@ int DFZip(const char *zipFilename, DFStorage *storage, DFError **error)
     const char **allPaths = NULL;
     DFBuffer *content = NULL;
     int ok = 0;
-    DFextZipHandleP zipHandle;
+    DFextZipHandleP zipHandle = NULL;
 
     allPaths = DFStorageList(storage,error);
     if (allPaths == NULL || !(zipHandle = DFextZipOpen(zipFilename, 0)))
@@ -123,6 +123,7 @@ int DFZip(const char *zipFilename, DFStorage *storage, DFError **error)
 end:
     DFBufferRelease(content);
     free(allPaths);
-    DFextZipClose(zipHandle);
+    if (zipHandle != NULL)
+        DFextZipClose(zipHandle);
     return ok;
 }