corinthia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmke...@apache.org
Subject [60/92] [abbrv] incubator-corinthia git commit: Replace DFPackageNewZip with Create/Open functions
Date Wed, 17 Dec 2014 13:29:10 GMT
Replace DFPackageNewZip with Create/Open functions

Distinguish between the act of creating a new zip file and opening an
existing one (for reading and/or modification).

The separation between these two functions takes the place of the
mustExist parameter that was accepted by DFPackageNewZip, and also makes
the creation case clearer as it returns an error if the file already
exists. The latter thus prevents accidentally bringing in one or more
files from an old zip file if the intention is to create an entirely new
one.


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

Branch: refs/heads/stable
Commit: 6fb91ae71127104ed982962f0710c3a00e5a13e3
Parents: bf6a061
Author: Peter Kelly <peter@uxproductivity.com>
Authored: Tue Dec 2 18:13:34 2014 +0700
Committer: Peter Kelly <peter@uxproductivity.com>
Committed: Tue Dec 2 18:13:34 2014 +0700

----------------------------------------------------------------------
 DocFormats/api/src/Operations.c          |  6 +++---
 DocFormats/core/src/lib/DFPackage.c      | 26 ++++++++++++++++++++++++--
 DocFormats/core/src/lib/DFPackage.h      |  3 ++-
 DocFormats/filters/ooxml/src/word/Word.c |  2 +-
 consumers/dfutil/src/Commands.c          |  2 +-
 consumers/dfutil/src/Plain.c             |  4 ++--
 6 files changed, 33 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/6fb91ae7/DocFormats/api/src/Operations.c
----------------------------------------------------------------------
diff --git a/DocFormats/api/src/Operations.c b/DocFormats/api/src/Operations.c
index 3c65375..f8e23e3 100644
--- a/DocFormats/api/src/Operations.c
+++ b/DocFormats/api/src/Operations.c
@@ -32,7 +32,7 @@ static int generateHTML(const char *packageFilename, const char *htmlFilename,
D
     DFBuffer *warnings = DFBufferNew();
     DFDocument *htmlDoc = NULL;
 
-    rawPackage = DFPackageNewZip(packageFilename,1,error);
+    rawPackage = DFPackageOpenZip(packageFilename,error);
     if (rawPackage == NULL) {
         DFErrorFormat(error,"%s: %s",packageFilename,DFErrorMessage(error));
         goto end;
@@ -90,7 +90,7 @@ static int updateFrom(const char *packageFilename, const char *htmlFilename,
DFE
 
     if (!DFFileExists(packageFilename)) {
 
-        rawPackage = DFPackageNewZip(packageFilename,0,error);
+        rawPackage = DFPackageCreateZip(packageFilename,error);
         if (rawPackage == NULL) {
             DFErrorFormat(error,"%s: %s",packageFilename,DFErrorMessage(error));
             goto end;
@@ -107,7 +107,7 @@ static int updateFrom(const char *packageFilename, const char *htmlFilename,
DFE
         HTMLBreakBDTRefs(htmlDoc->docNode,idPrefix);
     }
     else {
-        rawPackage = DFPackageNewZip(packageFilename,1,error);
+        rawPackage = DFPackageOpenZip(packageFilename,error);
         if (rawPackage == NULL) {
             DFErrorFormat(error,"%s: %s",packageFilename,DFErrorMessage(error));
             goto end;

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/6fb91ae7/DocFormats/core/src/lib/DFPackage.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFPackage.c b/DocFormats/core/src/lib/DFPackage.c
index a9a291e..eeb1a88 100644
--- a/DocFormats/core/src/lib/DFPackage.c
+++ b/DocFormats/core/src/lib/DFPackage.c
@@ -334,14 +334,36 @@ DFPackage *DFPackageNewMemory(void)
     return package;
 }
 
-DFPackage *DFPackageNewZip(const char *filename, int mustExist, DFError **error)
+DFPackage *DFPackageCreateZip(const char *filename, DFError **error)
 {
+    // Note that with the current implementation, the file doesn't actually get saved until
we do a DFPackageSave.
+    if (DFFileExists(filename)) {
+        DFErrorFormat(error,"File already exists");
+        return NULL;
+    }
+
+    DFPackage *package = (DFPackage *)calloc(1,sizeof(DFPackage));
+    package->retainCount = 1;
+    package->files = DFHashTableNew((DFCopyFunction)DFBufferRetain,(DFFreeFunction)DFBufferRelease);
+    package->ops = &zipOps;
+    package->zipFilename = strdup(filename);
+    return package;
+}
+
+DFPackage *DFPackageOpenZip(const char *filename, DFError **error)
+{
+    if (!DFFileExists(filename)) {
+        DFErrorFormat(error,"File does not exist");
+        return NULL;
+    }
+
     DFPackage *package = (DFPackage *)calloc(1,sizeof(DFPackage));
     package->retainCount = 1;
     package->files = DFHashTableNew((DFCopyFunction)DFBufferRetain,(DFFreeFunction)DFBufferRelease);
     package->ops = &zipOps;
     package->zipFilename = strdup(filename);
-    if (mustExist && !DFUnzip(filename,package,error)) {
+
+    if (!DFUnzip(filename,package,error)) {
         DFPackageRelease(package);
         return NULL;
     }

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/6fb91ae7/DocFormats/core/src/lib/DFPackage.h
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFPackage.h b/DocFormats/core/src/lib/DFPackage.h
index f15c17e..2a85bf6 100644
--- a/DocFormats/core/src/lib/DFPackage.h
+++ b/DocFormats/core/src/lib/DFPackage.h
@@ -22,7 +22,8 @@ typedef struct DFPackage DFPackage;
 
 DFPackage *DFPackageNewFilesystem(const char *rootPath);
 DFPackage *DFPackageNewMemory(void);
-DFPackage *DFPackageNewZip(const char *filename, int mustExist, DFError **error);
+DFPackage *DFPackageCreateZip(const char *filename, DFError **error);
+DFPackage *DFPackageOpenZip(const char *filename, DFError **error);
 DFPackage *DFPackageRetain(DFPackage *package);
 void DFPackageRelease(DFPackage *package);
 int DFPackageSave(DFPackage *package, DFError **error);

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/6fb91ae7/DocFormats/filters/ooxml/src/word/Word.c
----------------------------------------------------------------------
diff --git a/DocFormats/filters/ooxml/src/word/Word.c b/DocFormats/filters/ooxml/src/word/Word.c
index e00b214..505acb5 100644
--- a/DocFormats/filters/ooxml/src/word/Word.c
+++ b/DocFormats/filters/ooxml/src/word/Word.c
@@ -43,7 +43,7 @@ int DFHTMLToWord(const char *sourcePath, const char *destPath, DFError **error)
     if (DFFileExists(destPath) && !DFDeleteFile(destPath,error))
         goto end;
 
-    rawPackage = DFPackageNewZip(destPath,0,error);
+    rawPackage = DFPackageCreateZip(destPath,error);
     if (rawPackage == NULL)
         goto end;
 

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/6fb91ae7/consumers/dfutil/src/Commands.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/Commands.c b/consumers/dfutil/src/Commands.c
index eabcdd9..82f332d 100644
--- a/consumers/dfutil/src/Commands.c
+++ b/consumers/dfutil/src/Commands.c
@@ -116,7 +116,7 @@ static int prettyPrintWordFile(const char *filename, DFError **error)
     if (!DFEmptyDirectory(wordTempPath,error))
         goto end;
 
-    rawPackage = DFPackageNewZip(filename,1,error);
+    rawPackage = DFPackageOpenZip(filename,error);
     if (rawPackage == NULL) {
         DFErrorFormat(error,"%s: %s",filename,DFErrorMessage(error));
         goto end;

http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/6fb91ae7/consumers/dfutil/src/Plain.c
----------------------------------------------------------------------
diff --git a/consumers/dfutil/src/Plain.c b/consumers/dfutil/src/Plain.c
index 0b71e2c..5260255 100644
--- a/consumers/dfutil/src/Plain.c
+++ b/consumers/dfutil/src/Plain.c
@@ -600,7 +600,7 @@ int Word_fromPlain(const char *plain, const char *plainPath, const char
*zipTemp
         goto end;
     }
 
-    firstStore = DFPackageNewZip(docxPath,0,error);
+    firstStore = DFPackageCreateZip(docxPath,error);
     if (firstStore == NULL) {
         DFErrorFormat(error,"%s: %s",docxPath,DFErrorMessage(error));
         goto end;
@@ -619,7 +619,7 @@ int Word_fromPlain(const char *plain, const char *plainPath, const char
*zipTemp
 
     // Now we have a .docx file; access it using what will be the new way (this API will
change so we just say
     // "open a word document from here", without having to separately create the package
object first.
-    secondStore = DFPackageNewZip(docxPath,1,error);
+    secondStore = DFPackageOpenZip(docxPath,error);
     if (secondStore == NULL) {
         DFErrorFormat(error,"%s: %s\n",docxPath,DFErrorMessage(error));
         goto end;


Mime
View raw message